How to solve SIR model with ode45?
1 view (last 30 days)
Show older comments
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/τ
0 Comments
Answers (1)
Pavan Guntha
on 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
0 Comments
See Also
Categories
Find more on Stress and Strain in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!