Borrar filtros
Borrar filtros

How to solve SIR model with ode45?

1 visualización (últimos 30 días)
Christos Ioannou
Christos Ioannou el 14 de Feb. de 2021
Respondida: Pavan Guntha el 26 de Mzo. de 2021
S'(t)=-λ(t)S(t) S(0)=So
Ι'(t)=λ(t)S(t)-γ(t) I(0)=Io
R'(t)=γ(t)I(t) R(0)=Ro

Respuestas (1)

Pavan Guntha
Pavan Guntha el 26 de Mzo. de 2021
You can refer to the following code:
[t,dYdt] = odeOut;
function [t,dYdt] = odeOut
% time dependent window
tRange = linspace(0, 10, 100); % Change the limits as per your requirement
Y0 = [S0; I0; R0]; % initial conditions
yT = 1/T; % Considering T to be a constant.
lambdaT = cx./(N(tRange).*I(tRange)); % N, I are to be defined
[t,dYdt] = ode45(@odefunc, tRange, Y0);
function dYdt = odefunc(t,y)
lambdaT_t = interp1(tRange,lambdaT,t);
dSdt = -lambdaT_t*y(1);
dIdt = lambdaT_t*y(2) - yT;
dRdt = yT*y(3);
dYdt = [dSdt; dIdt; dRdt];
You can refer to the documentation of interp1 for more details about its usage.


Más información sobre Startup and Shutdown en Help Center y File Exchange.


Community Treasure Hunt

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

Start Hunting!

Translated by