Changing array variables whilst they are being solved within ODE45 routine at each timestep
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
Jan
on 20 Sep 2012
What is X, Y and Z? You want to modify T after each timestep? But T is your solution. And do you mean each step, or each successful step only - be aware that ODE45 has a step size control and the setps are not performed in chronological order necessarily.
Peter
on 20 Sep 2012
Jan
on 20 Sep 2012
Of course you can do everything in Matlab, as long as it is recursively computational. But ODE needs a sufficiently smooth curve for an integration and modifying T sounds like it introduces discontinuities, such that the stepsize control can cause to random results.
But I'm still not convinced, that mdofying the solution inside the integration is mathematically correct.
Ryan G
on 20 Sep 2012
The big question is what are your goals here? I think Jan may be implying why are you using the ODE solver at all if you're simply changing the result when it's done?
I know this is easily doable in Simulink, which was a question on here not long ago, but I'm not sure how easy it is here.
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.
Peter
on 20 Sep 2012
Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!