% testode45.m
%-----------------------------------------------------
% 清空所有变量
clear
% 清空屏幕
clc
global a b c d e f
% 时间跨度取0-20,可以空格分隔,也可以用逗号分隔
%n=[0,4167,41019,15340,16507,17347,19563,20353,20984,21344,21398];
%n=[0,562,2387,34426,66827,79114,86567,91501,94520,98696,112064,124062,183740,228299,276311,303046,310058,312964,314826];
tspan = [0,20];
% 初始值
y0 = [20000,0,1,0];
% 调用语句
[T,Y] = ode45( @odefun1,tspan,y0);
% 绘图
plot(T,Y(1),'-',T,Y(2),'-.',T,Y(3),'.',T,Y(4),'--')
legend('S(t)','E(t)','I(t)','R(t)')
% odefun.m
function dy = odefun1(~,y)
global a b c d e f
S = y(1);
E = y(2);
I = y(3);
R = y(4);
a=0.2;
b=0.4;
c=0.4;
d=0.2;
dS = -a * S * I -b * S * I;
dE = -a * S * I - c * E - d * E + e * R;
dI= c * E - f * I;
dR = b * S * I + d * E + f * I - e * R;
dy=[dS;dE;dI;dR];
end