作业帮 > 综合 > 作业

matlab建模利用MATLAB求解传染病模型中的SIR模型的数值解:程序中a=λ=1,b=μ=0.3,i(0)=0.0

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/13 01:57:52
matlab建模
利用MATLAB求解传染病模型中的SIR模型的数值解:
程序中a=λ=1,b=μ=0.3,i(0)=0.02,s(0)=0.98
M文件中:
function y=ill(t,x)
a=1;b=0.3;
y=[a*x(1)*x(2)-b*x(1),-a*x(1)*x(2)]';
命令窗口中:
>> [t,x]=ode45('ill',[0:50],[0.02,0.98]);[t,x]
为什么老是报错呢
方程式这样的
matlab建模利用MATLAB求解传染病模型中的SIR模型的数值解:程序中a=λ=1,b=μ=0.3,i(0)=0.0
你定义的函数里面就没有t啊
再问: 你能加我吗,492920927,请帮个忙吧
再答: 用ode45这个命令无法求解 我用龙格库塔4阶求解。程序如下 (1)方程组中式1 function F=F(t,x,y) F=0*t+1*x*y-0.3*x; (2)方程组中式2 function G=G(t,x,y) G=0*t-1*x*y; (3)龙格库塔程序(输入:F,G,[a,b]求解区间,[Za1,Za2]初始值,M需要结果数) function [T,Z]=rks4(F,G,a,b,Za1,Za2,M) h=(b-a)/M; T=zeros(1,M+1); Z1=zeros(1,M+1); Z2=zeros(1,M+1); Z1(1)=Za1; Z2(1)=Za2; Z=zeros(M+1,2); Z(1,1)=Za1; Z(1,2)=Za2; for j=1:M fk1=feval(F,T(j),Z1(j),Z2(j)) gk1=feval(G,T(j),Z1(j),Z2(j)) fk2=feval(F,T(j)+h/2,Z1(j)+h*fk1/2,Z2(j)+h*gk1/2) gk2=feval(G,T(j)+h/2,Z1(j)+h*fk1/2,Z2(j)+h*gk1/2) fk3=feval(F,T(j)+h/2,Z1(j)+h*fk2/2,Z2(j)+h*gk2/2) gk3=feval(G,T(j)+h/2,Z1(j)+h*fk2/2,Z2(j)+h*gk2/2) fk4=feval(F,T(j)+h,Z1(j)+h*fk3,Z2(j)+h*gk3) gk4=feval(G,T(j)+h,Z1(j)+h*fk3,Z2(j)+h*gk3) Z(j+1,1)=Z(j,1)+h*(fk1+2*fk2+2*fk3+fk4)/6 Z(j+1,2)=Z(j,2)+h*(gk1+2*gk2+2*gk3+gk4)/6 end (4)在命令窗口输入 [T,Z]=rks4(@F,@G,0,0.02,0.02,0.98,2) 结果如下: fk1 = 0.0136 gk1 = -0.0196 fk2 = 0.0136 gk2 = -0.0197 fk3 = 0.0136 gk3 = -0.0197 fk4 = 0.0137 gk4 = -0.0197 Z = 0.0200 0.9800 0.0201 0 0 0 Z = 0.0200 0.9800 0.0201 0.9798 0 0 fk1 = 0 gk1 = 0 fk2 = 0 gk2 = 0 fk3 = 0 gk3 = 0 fk4 = 0 gk4 = 0 Z = 0.0200 0.9800 0.0201 0.9798 0.0201 0 Z = 0.0200 0.9800 0.0201 0.9798 0.0201 0.9798 T = 0 0 0 Z = 0.0200 0.9800 0.0201 0.9798 0.0201 0.9798 >>