How can I create a min step for ode45?
27 views (last 30 days)
Show older comments
I have a problem with ode45. I have measured data and I don't want ode45 to create steps smaller than the sample time of the experiment, so that every time step of ode45 belongs to a measured value.
3 Comments
Jan
on 17 Jul 2017
Sorry, Pablo, I hate Dropbox. My browser is secured by a script block. I've allowed some levels on dropbox, but still get either error messages or a blank page. Why do I have to offer Dropbox my IP address to solve your problem? The Answers forum has nice tools for attaching code.
Walter Roberson
on 20 Jul 2017
Edited: Walter Roberson
on 20 Jul 2017
The original author removed most of their responses, leaving most of the discussion without any context :(
They also appear to have removed an Answer they had posted, along with all the responses to that Answer, thereby removing record of the contributions from the volunteers :(
Answers (3)
Jan
on 17 Jul 2017
Edited: Jan
on 18 Jul 2017
The ode5.m integrator should be faster than the smart ODE45 with stepsize control - if and only if the number of steps is smaller. Note that ODE45 controls the step size such, that the minimum number of steps is taken to fullfill the wanted limit of accuracy. The fixed step solver ode5.m can be slower if you select the step size too small and less accurate if the step size is too small or too large. It would be possible to find the wanted level of accuracy and speed, if you explain "a lot faster" in absolute terms.
If you function to be integrated contains discontinuities (Star Strider mentioned abs()), the stepsize control of the intergrator will fail. See http://www.mathworks.com/matlabcentral/answers/59582#answer_72047. In ode5.m there is no stepsize control and the integration will not stop or drive crazy, but the result is not accurate, as you can imagine, if the discontinuity is not exactly at a step. Better integrate in two steps, before and after the discontinuity.
0 Comments
Walter Roberson
on 17 Jul 2017
You interpolate t to the values in the matrix, and you then do not use the original t anywhere. That process is inherently discontinuous, and none of the variable step ode* routines will be able to handle that function.
You do not want the ode function to be evaluated anywhere other than at the measured values. The approach you should be taking there is to call your ode function "by hand" once for each location without calling any of the ode*() routines, and then to do numeric integration such as calling trapz or cumtrapz.
Specifying the measurement times as your tspan will not achieve your goals. The ode* routines call the ode function with whatever times they feel are appropriate in order to achieve the integration tolerances: specifying a vector of length 3 or more for tspan just tells it which positions to report the output for.
1 Comment
Walter Roberson
on 18 Jul 2017
Dormand-Price is used by ode45() to adaptively select step size. This fits in with what I said about the ode being called with whatever times are needed to achieve the integration tolerance.
Star Strider
on 17 Jul 2017
@Pablo —
I believe you have only one independent variable, ‘t’. I would use it as your ‘tspan’ vector.
Also, you can include the initial conditions as parameters to be optimized, as I did in the Monod kinetics and curve fitting (link) code.
I would avoid the dicontinuities altogether by eliminating the abs calls entirely and let the genetic algorithm sort out the results. If a negative solution to your ODE results in a lower fitness score, the genetic algorithm will eventually correct the parameters that cause it.
It is always best not to second-guess the optimization routines.
0 Comments
See Also
Categories
Find more on Ordinary Differential Equations 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!