ODE event location but integration does not stop
26 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Torsten
le 5 Déc 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
Réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!