
if temperature 17 increase until 23, swich on,Q=15*10^6 and if temperature 23 decrease untill17 switch off, Q = 0 how can I plot the temperature with time when T(0)=20degree
9 views (last 30 days)
Show older comments
dT/dt =(Q/15172.5)+29.66+2.966T
4 Comments
Sam Chak
on 23 Mar 2022
There is nothing wrong with your English. I can understand what you wrote. It was just I don't truly get what you want at the beginning, because plotting the results requires solving the temperature control differential equation, and modeling the hysteresis behavior in the thermostat (Q). Yet, you did not mention about any issue with the ODE. That's why I requested clarification from you.
Luckily you cleared things up. However, I have discovered two things:
- Since the thermostat exhibit nonlinearity behavior (from the hysteresis), the Laplace and Inverse Laplace Transforms cannot be used in the nonlinear system.
- Your modeling of the thermostat (Q) appears to be incorrect, and no action is defined between
. Please confirm if this is intended.

Answers (1)
Davide Masiello
on 23 Mar 2022
Edited: Davide Masiello
on 23 Mar 2022
You could try this
clear,clc
tf = 3; % Final time of integration
T0 = 20; % Initial temperature
tend = 0; % Initial time of integration
idx = 0; % Iteration index
while tend < tf
if T0 < 23 % Sets positive heat input when T < 23
Tx = 23;
Q = 1.5e+6;
else % Sets negative heat input when T >= 23
Tx = 17;
Q = -1.5e+6;
end
idx = idx+1;
tspan = [tend,tf];
opts = odeset('Event',@(t,T)heatSwitch(t,T,Tx));
sol(idx) = ode15s(@(t,T) tempControl (t,T,Q), tspan, T0, opts);
tend = sol(idx).x(end);
T0 = sol(idx).y(end);
end
plot( [sol(:).x],[sol(:).y],'k',...
[sol(:).x],ones(1,length([sol(:).x]))*23,'r--',...
[sol(:).x],ones(1,length([sol(:).x]))*17,'r--')
xlabel('Time, s')
ylabel('Temperature, C')
axis([-inf +inf 16 24])
function dTdt = tempControl(t,T,Q)
dTdt =(Q/15172.5)+29.66+2.966*T;
end
function [position,isterminal,direction] = heatSwitch(t,T,Tx)
position = T-Tx; % The value that we want to be zero
isterminal = 1; % Halt integration
direction = 0; % The zero can be approached from either direction
end
However, please notice that when T = 23, I switch Q to -Q otherwise the temperature wouldn't go down back to 17. In fact, if Q = 0, dT/dt in your espression would still be positive.
8 Comments
Davide Masiello
on 24 Mar 2022
Sure. For a general overview of ODE Event Location functions, I recommend checking the following link
In summary, the ode event locator checks if a condition is met at each time step of integration of a ODE.
You can then choose whether to stop the integration or not. In any case, you can store the values of t and y when the event happens.
In the particular case above, heatSwitch checks if the temperature reaches a target temperature Tx, which I have to be either 17 or 23 depending on what stage the process is at (quenching or heating).
Sam Chak
on 24 Mar 2022
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
