ODE event location but integration does not stop

28 Ansichten (letzte 30 Tage)
kyllen87
kyllen87 am 20 Apr. 2020
Kommentiert: Torsten am 5 Dez. 2023
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 Kommentare
Chinmay
Chinmay am 5 Dez. 2023
did you find a solution?
Torsten
Torsten am 5 Dez. 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

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Produkte


Version

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by