How to solve SIR model with ode45?

4 ビュー (過去 30 日間)
Christos Ioannou
Christos Ioannou 2021 年 2 月 14 日
回答済み: Pavan Guntha 2021 年 3 月 26 日
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/τ

回答 (1 件)

Pavan Guntha
Pavan Guntha 2021 年 3 月 26 日
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.

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by