Timestep tracking in ode45
6 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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.
0 Comments
More Answers (2)
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.
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!