Last active
February 14, 2023 21:32
-
-
Save n7275/fdb46bb22eee1d8c3f8100108e9ff798 to your computer and use it in GitHub Desktop.
Heater Ramp Simulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%Tank Heater | |
clear; | |
clc; | |
nominal_heat = 200; %Watts | |
ramp_rate = 10.0; | |
Dt = .1; | |
heat = 0; | |
t = 0; | |
ii = 1; | |
T = []; | |
H = []; %heat output | |
P = []; %power input | |
on = 0; | |
start_time = 2; | |
stop_time = 90; | |
tmax = 200; | |
while t < tmax | |
dt = Dt*rand(); %simulate random variation in timesteps | |
%NASSP code is from here... | |
ramp = 1-exp(-dt/ramp_rate); | |
if(heat < nominal_heat && on) | |
heat += (nominal_heat-heat)*ramp; | |
else | |
heat -= heat*ramp; | |
endif | |
%thermic(heat); | |
%...to here | |
if(on) | |
P(ii) = nominal_heat; | |
else | |
P(ii) = 0; | |
endif | |
H(ii) = heat; | |
%for testing | |
if ((t > start_time) && (t<stop_time)) | |
on = 1; | |
elseif t >= stop_time | |
on = 0; | |
endif | |
t += dt; | |
T(ii) = t; | |
ii++; | |
end | |
plot(T,H,T,P) | |
grid on; | |
grid minor | |
axis ([0 tmax, 0 nominal_heat*1.1]); | |
xlabel("Time [s]"); | |
ylabel("Power [W]"); | |
legend("Heat Output", "Power Input") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment