(How) can I get a numerical solution for an ODE (e.g. using ode15s) that respects monotonicity?
1 view (last 30 days)
Show older comments
I am solving an ODE (IVP) yp=f(t,y) with guaranteed nonnegative yp. Mathematically, the solution y(t) is guaranteed to be monotonically non-decreasing; however, numerically it is not always.
Simple example:
>> yp=@(t,y) sin(y.^4).^2; % yp guaranteed nonnegative
>> [t,y] = ode15s(yp,[0,500],1); % solve OVP …
>> any(diff(y)<0) % … but numerical solution is not monotonically increasing ans = 1
This violation of monotonicity is a spurious effect only, and it can be reduced somewhat by changing the tolerances for the ode-solver. However, I find no way to reliably remove it alltogether.
Note that the "NonNegative"-option of the ODE solvers does not help here.
Post-processing the solution from ode15s (by re-evaluating yp for each timestep output by the ODE-solver and updating the solution accordingly) is possible, but I find this a bit dowdy and clumsy.
Use of an implicit solver (like ode15s) is mandatory for the actual ODE I am solving (a very stiff problem).
0 Comments
Answers (2)
Sean de Wolski
on 19 Aug 2016
Edited: Sean de Wolski
on 19 Aug 2016
Have you tried defining every point in tspan?
tspan = linspace(0,500,100000);
You could perhaps sample it more often near where there is a non-increasing point, or do a simple smoothing after.
0 Comments
Robert Schiessl
on 19 Aug 2016
1 Comment
Sean de Wolski
on 19 Aug 2016
What about dense sampling and then smoothing it to a coarser density after?
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!