其他分享
首页 > 其他分享> > 求解微分方程组

求解微分方程组

作者:互联网

定义函数 sir.m

function y = sir(t,x)
    %UNTITLED 此处显示有关此函数的摘要
    %   此处显示详细说明
    a=0.8;  %感染率0.8
    b=0.2;  %治愈率0.2
    y=[-a*x(1)*x(2),a*x(1)*x(2)-b*x(2)]';
end

运行函数 rum.m

[t,x]=ode45('sir',[0,50],[0.98 0.02]);
% ode45是用来求解常微分函数的方法
[t,x]
% 健康者与病人的图
figure(1);
plot(t,x(:,1),'.',t,x(:,2),'^');
title('SIR模型');
xlabel('时间');
ylabel('比例');
legend('健康者','病人','2');

% 健康者与病人的相轨线
figure(2);
plot(x(:,1),x(:,2));
title('i-s 相轨线');
xlabel('s');
ylabel('i');

运行结果

 

 

标签:sir,0.2,函数,figure,0.8,求解,plot,微分方程
来源: https://www.cnblogs.com/mrfanqie/p/matlab001.html