ODE event location but integration does not stop
3 views (last 30 days)
Show older comments
I am trying to use the “Events” option of the odeset function to stop the solver integration of the ODE system at “steady state” (where vector dydt = 0), but the solver never stops (only when it reaches Inf [t = ~10^300]).
%% event function (saved as function file)
function [x,isterm,dir] = eventfun(t, y, parameters, rates)
dydt = cellmodel_odes(t, y, rates, parameters)
dy = norm(dydt, Inf)
x = dy
isterm = 1;
dir = 0;
end
%% script calling event function
% call solver routine
...
t0= 0;
xoverFcn = @(T, Y) eventfun(T, Y, parameters, rates);
opts = odeset('Events',xoverFcn);
[t,y]= ode15s(@(t,y) cellmodel_odes(t, y, rates, parameters), [t0 Inf], init, opts);
...
2 Comments
Torsten
on 5 Dec 2023
An exact steady state (thus norm(dydt) = 0 exactly) is impossible to reach.
Say you have the differential equation
dy/dt = -y, y(0) = 1
with solution
y(t) = exp(-t).
Steady state is y = 0, but it is never reached.
Thus you will have to set a small value at which the solver should stop, e.g.
%% event function (saved as function file)
function [x,isterm,dir] = eventfun(t, y, parameters, rates)
dydt = cellmodel_odes(t, y, rates, parameters)
small = 1e-8;
dy = norm(dydt, Inf)
x = dy - small;
isterm = 1;
dir = 0;
end
Answers (0)
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!