Changing array variables whilst they are being solved within ODE45 routine at each timestep
1 view (last 30 days)
Show older comments
Hello,
I have a problem which takes the following form:
[t T] = ode45(@dTdt,tspan,ICs)
end
Rates = dTdt(t,T,X,Y,Z)
dTdt = (X+Y-Z)*T -2*t;
end
So I am numerically solving for an array of temperatures, T over time t.
The problem is, I need to modify the temperatures after they have been solved over each time step. For example, after each timestep I might have to do the following:
for k = 2:NumberTemps;
if T(k-1)>T(k);
T(k) = 0;
end
end
The problem is that I don't know how to access the array of variables, T whilst the ODE45 solver is running.
How should I go about doing this?
Do I need to modify the ODE45 routine that is called and include the numerical step inside it?
Or is there a way to come out of ODE45 after each time step and execute an arbitrary procedure on the array that it is solving?
Best Regards
Pete
6 Comments
Star Strider
on 20 Sep 2012
If you want to stop the integration when the temperature T(t) begins to decrease (as in your example), I suggest you explore the options of the ODE Events Property ‘Events’ in odeset. Experiment with it until you get the result you want.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!