Flag for ODE15s solver
7 views (last 30 days)
Show older comments
I am using ode15s (or any of the ode solvers), and having issues with it returning errors such as:
Warning: Failure at t=5.128513e-01. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (1.776357e-15) at time t
I understand that my ODE system is stiff, that this depends on the parameter set, and that that this is exactly what this message is telling me.
However, I am iteratively trying different parameter sets (in an MCMC scheme) and would like to set the solver so that if this error message occurs, it returns some kind of flag and stops, or, even better, if the integrator takes longer than a certain period of time to integrate also for it to stop and return a flag.
I have been combing through the odeset documentation, and cannot figure out how to do this.
Thank you.
0 Comments
Answers (1)
Teja Muppirala
on 3 May 2011
There are probably a number of ways to do this, but here is one of them. You can see I am calling ode15s, but I am putting limits on the maximum time and the minimum time step. If either of these are violated, it cancels the ODE solver and returns to the main function.
function myode
clear all %<-- Reset persistent variables
try
ode15s(@dydt,[0 5],1);
catch
disp(lasterr)
% Do something else ...
end
function dydt = dydt(t,y)
dydt = y.^2;
% Below is where we check for stopping conditions
MAXTIME = 1; %Max time in seconds
MINSTEP = 1e-10; %Minimum step
persistent tprev elapsedtime
if isempty(tprev)
tprev = -inf;
end
if isempty(elapsedtime)
elapsedtime = tic;
end
timestep = t - tprev;
tprev = t;
if (timestep > 0) && (timestep < MINSTEP)
error(['Stopped. Time step is too small: ' num2str(timestep)])
elseif toc(elapsedtime) > MAXTIME
error('Stopped. Taking too long.')
end
2 Comments
Teja Muppirala
on 3 May 2011
The initial time step tends to be very small though, so you might want to take that into account too to avoid canceling on that first step:
if (t > 0.01) && (timestep > 0) && (timestep < MINSTEP)
Mahmudul Hasan
on 5 Sep 2013
Hi, I am using ode15s. But it gives the same warning as mentioned above. How can I use the internal ode15s time to detect as an event. This answer is quite vague to me. I have 3 files: main program, dydt function, and event function. I want to reset my initial conditions ( i.e. last computed value = new initial values) at each time the tolerance warning occur...
Could anyone help me, please....
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!