Is there any way to use multiple tolerances in ODE solvers?
Show older comments
I'm frequently using systems of ODEs to simulate the dynamics of ecological communities. The number of equations is large: from hundreds to thousands, and running times are sometimes desperately long. The diversity of species’ characteristics implies that some of them have dynamics which are orders of magnitude faster than others: like the difference between a bacteria and a tree. The ‘faster’ species require tighter tolerances which, in turn, result in smaller time steps, but that is usually unnecessarily small for the ‘slower’ species, which are essentially constants (or very slowly varying) at that time scale (e.g. hours vs. months or years) and could use much larger tolerances and longer time-steps. I guess this, if possible, would save computing time, which is the goal here. So, my question is: is there any way to set at least two different tolerances for different groups of equations in a system of ODEs? Or any other way to get around this problem? I use MATLAB R2017b.
Accepted Answer
More Answers (3)
CARLOS RIASCOS
on 5 Apr 2018
Hello friend, you could try, generate for example two systems of equations one with slow dynamics and another with fast dynamics, for the slow dynamics use a value of big h and for fast dynamics a value of small h, also consider in changing the limits of tspan, because if you are analyzing a dynamic that evolves in micro-seconds should not have limits like the code here example but rather tspan = 0: h_small: 0.01.
If you must make a model as a whole, you can see if the fast dynamics stabilize and if so you could even consider them as constants, but everything depends on the type of problem you have. I hope I've helped.
h=1;
tspan = 0:h:5;
y0 = 0;
[t,y] = ode45(@(t,y) 2*t, tspan, y0);
plot(t,y)
1 Comment
Francisco de Castro
on 18 May 2018
Francisco de Castro
on 18 May 2018
0 votes
Torsten
on 22 May 2018
0 votes
AbsTol can be a vector of the same size as the solution vector. Thus you can prescribe absolute tolerances for each solution component separately.
Best wishes
Torsten.
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!