Is it possible to have an ode solver solve in chronological order?

4 visualizaciones (últimos 30 días)
Isabella
Isabella el 27 de Jul. de 2022
Comentada: Isabella el 29 de Jul. de 2022
I'm trying to solve a piecewise differential equation of Temperature as a function of time using ode45. Some of the conditions of the piecewise are dependent on timestamps of certain events in the differential function. For now, I am using global variables to store those times. The plot did not behave the way I expected, so I displayed time in the ode function, and saw that time was not monotonically increasing. This caused the timestamps to be changed after calculations dependent on them were performed. I looked into event location functions, but if ode45 does not solve in order, I don't think that'll work either. Is it possible to use an ode solver for this problem?
Here's an example of the script:
f = @(t,T)funcOfT(t,T)
[t,T] = ode45(f, [0 6000], 0);
plot (t,T)
function dTdt = funcOfT(t,T)
global t1 t2;
T_max = 5;
x = 1;
a = 1;
b = 1;
% Displaying time for troubleshooting
disp(t);
if(t<500)
% First case ends at timestamp t1
if (T < T_max)
dT = T/2;
t1 = t;
% Third case begins at t2
elseif (t-t1 > x)
dT = T/3;
% Second case starts at t1, ends at t2
else
dT = 0;
t2 = t;
end
else
% Fourth case ends at t3
if (T > T_max)
dT = T/2;
t3 = t;
% Sixth case begins with this timestamp-based condition
elseif ((t-t3)*a + (t2-t1)*b < 0)
dT = T/4;
% Fifth case begins at t3
else
dT = 0;
end
end
end
  7 comentarios
Sam Chak
Sam Chak el 29 de Jul. de 2022
Can you have some realistic values for the parameters? I asked because your example where and initial value which is also the equilibrium point, does not help the simulation.
Request for and the initial temperature , as well as the melting point .
Need to perform analysis on the thermal system.
Since the Temperature (T) is a physical quantity and T > 0 is always true, if and is bounded, then the thermal system is stable.
Isabella
Isabella el 29 de Jul. de 2022
Sure, here are some more realistic conditions then:
Initially,

Iniciar sesión para comentar.

Respuestas (1)

Bruno Luong
Bruno Luong el 29 de Jul. de 2022
@Isabella "Also looking at the ode45 documentation, I do see that it solves using the previous timestep, so I'm now looking into why the displayed times aren't monotonically increasing."
If you read Runge Kutta scheme used by ode45 you'll see it evaluate intermediate times in between the so called "time step" then go back the previous time step evalute with the solution of the next time step. So in between two time steps there a few call of the model that are NOT monotonic.
Also ode45 possibly reduces the time step when it estimates the system become stiffer. I don't know the exact detail but this could also means that there is some non monototic calls of your model that jump back the the previus time step.
In your case I would use the event (click on the link) to estimate t1, t2, t3, t4, and NOT detect them inside your model with the assumtion that the model is called with increasing t. That assumption cannot be true.

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by