Early exit instead of a warning in ODE113?
9 views (last 30 days)
Show older comments
While running a code that uses ODE113, the program will run, possibly indefinitely, until manually paused. Once paused, the error "Unable to meet integration tolerances without reducing the
step size below the smallest value allowed" appears.
Is there a way to tell ODE113 to generate an error instead of a warning (or something else that would stop the code), so the program won't be stuck in futile calculation?
0 Comments
Accepted Answer
Bjorn Gustavsson
on 6 Sep 2021
The brute-forciest way to do this might be to give ode113 an event that interrupts after some suitably long time, i.e. long enough to let a successful integration complete and short enough to not get on your nerves (if this is possible...). Perhaps something like:
function [position,isterminal,direction] = your_patienceEvent(t,y,t0,dt)
position = etime(datevec(t),datevec(t0))<dt; % The elapsed time that we can manage to wait?
isterminal = 1; % Halt integration
direction = 0; % The zero can be approached from either direction
Then set the eventfunction-field of the ode-options struct to something like:
ops113 = odeset;
t0 = now;
ops113.event = @(t,y) your_patienceEvent(t,y,t0,600);
That will limit the running-time of ode113 to 10 minutes after you assign t0. Perhaps you have some more appropriate diagnostic for when the integration runs into problems (some problematic values of y(t) would be more sensible to use for aborting integration).
HTH
0 Comments
More Answers (1)
Jan
on 6 Sep 2021
In the current version of Matlab ODE113 does stop, when the integration tolerance is not met. The warning is shown an the integration is stopped. This means, that the code does already, what you want.
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!