Azzera filtri
Azzera filtri

How to solve SIR model with ode45?

2 visualizzazioni (ultimi 30 giorni)
Christos Ioannou
Christos Ioannou il 14 Feb 2021
Risposto: Pavan Guntha il 26 Mar 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
λ(t)=cx/N(t)*I(t)
γ(t)=1/τ

Risposte (1)

Pavan Guntha
Pavan Guntha il 26 Mar 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];
end
end
You can refer to the documentation of interp1 for more details about its usage.

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by