ODE 45 integration control
21 views (last 30 days)
Show older comments
I've been having some issues with running ODE45 on a model that is very flat unless forced with a very short duration square wave, in which case it forms a spike and returns to the baseline. The adaptive time step of ODE45 is causing the time step to be larger than the interval the model is forced for, and skipping the spikes (unless by chance, one of the t values lies in the forcing interval).
Is there any way to control the internal time steps used by the solver? I would like to be able to supply a list of time values and ensure that ode45 evaluates my function at those points. Elsewhere it can do what it likes I just need to make sure the function is evaluated within the forcing interval to trigger the shorter step size.
Many thanks,
Harry
0 Comments
Accepted Answer
Jan
on 2 May 2014
Edited: Jan
on 2 May 2014
Matlab's ODE solves cannot handle discontinuities. So controlling the time steps will not help reliably. See: http://www.mathworks.com/matlabcentral/answers/59582#answer_72047
The only way to treat discontinuities correctly is to stop the integration and restart it.
5 Comments
Jan
on 4 May 2014
I do not agree that the integrators "can" handle discontinuities. It is true, that you get sometimes a final value. But from the view point of a scientist working in the field of numerical computations I do not call this final value a "result". The numerical integration is a kind of measurement process based on a large number of steps, which cause round off errors and local discretization errors. As in all measurements, the final value is a "result" only, if the measurement error can be estimated and given e.g. by a standard deviation. For an integration this means, that a sensitivity analysis is required. Unfortunately Matlab's ODE integrators do not provide the accumulated Wronski-matrix, but you at least vary the initial conditions to find out, how sensitive the final value reacts to this.
Imagine the integration of the equations of motion for a pen staying perpendicular on its tip. Would you think, that the calculated trajectory reflects the reality in any kind? An analysis of the sensitivity would reveal the instability of the system directly.
Now take into accound, that a discontinuos right hand side let the matrix of sensitivity explode and the integration even stops or fails, when such a discontinuity occurres exactly during the function evaluations during a step. Therefore I insist, that you can get a final value with some luck, but you'd run the integrator outside its specifications and therefore there is no scientific evidence, that the results are meaningful.
The handling of discontinuities in the right hand side for integrations has been one of the topic of my diploma thesis. Unfortuantely it was written in German, so it is not of general use. But as long as you found out, that stopping and restarting works fine, this is a nearly perfect solution already. For the equations of motion of e.g. a multibody system an additional step is required: The change of the RHS causes a jump in the velocities, e.g. when a foot of a running robot touches the floor. This concerns even the other bodies, which are connected by joints. Letting the integrator running stupidly over such discontinuities works sometimes, but it is numerically instable and the results are junk.
So my conclusion: I cannot really help to solve your question. You can modify the code of ODE45 to solve your needs, but I would recommend not to do it due to the mentioned problems.
More Answers (1)
Mischa Kim
on 2 May 2014
Harry, in
...
tspan = linspace(0,1,11);
options = odeset('AbsTol',1e-8);
[t,X] = ode45(@ODE,tspan,IC,options);
for which the solver returns the solution at specific data points defined by tspan. You can further use the options vector with odeset to control other solver options such as tolerances, step size, etc.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!