Timestep tracking in ode45

6 views (last 30 days)
Rebecca Ward
Rebecca Ward on 3 Nov 2011
Hi, Can anyone tell me how I would go about tracking the size of the timestep being used in the adaptive solver ode45?
What I need to do is to use a value for the absolue time in the equations being solved, and I was thinking I could do this by summing the timesteps, but I can't find a way to do this.
Any advice would be great - I'm a fairly new user of MATLAB.
Thanks a lot,
Rebecca

Accepted Answer

Jan
Jan on 3 Nov 2011
Of course ODE45 itself sums up the accepted time-steps. The simulation time is used as input of the ODE function.
Do you want to consider rejected steps? Perhaps it is getting clear, if you explain, what you want to achieve.

More Answers (2)

Rebecca Ward
Rebecca Ward on 3 Nov 2011
Thanks Jan,
I have a parameter within the ode function which is set according to how far through the simulation we are.
Specifically the simulation models heat flow through a building over a time period of 30 days. It is necessary to check for each day whether the step in question is between 8am and 8pm in which case the parameter (a set-point temperature) is changed. I understand that ODE45 itself sums the accepted timesteps, and I can generate the temperature outputs at the times I require, I just can't work out how to access the sum of accepted timesteps so I can modify the set-point temperature.
Thanks for your interest,
Rebecca

Walter Roberson
Walter Roberson on 3 Nov 2011
The t passed to the fun function handle is the time since the beginning of the simulation. You know (ie. can control) the simulated clock time of the start of the simulation, so add the start clock time to the time offset, and convert the result to time of day. For example, seconds since 00:00, mod 24*60*60, between (8*60*60) and (20*60*60 minus epsilon) would be at one set point, otherwise the other set point.
You do not want to work with the sum of the timesteps, just with the current t (time since start) parameter. That and you might want to specify an explicit tspan list to ode45 so that ode45 calculates at your known boundaries rather than unknowingly stepping over a boundary.
  2 Comments
Rebecca Ward
Rebecca Ward on 4 Nov 2011
Hi Walter,
Thanks for taking the time to answer - I originally assumed that t was the time since the beginning of the simulation but it doesn't monotonically increase, so that made me think it must be a timestep size. I'm OK with the set-point calculation once I have the time, I just can't work out how to extract the time value. Any more advice you could give would be great.
Thanks,
Rebecca
Rebecca Ward
Rebecca Ward on 4 Nov 2011
Hi again,
Seems to be working OK now - I was picking up t mid adaptive iteration, but the routine seems to assign t correctly to the parameters I'm specifying, so I think it's OK.
Thanks for your help,
Rebecca

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!