用matlab画微分方程组图像
都是对t求导这个微分方程组在matlab里面怎么绘图?初值的话取(0.5,0,0.5)和(0,0,1)就行。求大神!!! 展开
图片:
程序:
tspan=[0 20];
y0=[0.5 0 0.5 ];
y1=[0 0 1];
[t0,Y0]=ode45('dif_dsdedi',tspan,y0)
[t1,Y1]=ode45('dif_dsdedi',tspan,y1)
figure
subplot(2,1,1)
plot(t0,Y0(:,1),'-b',t0,Y0(:,2),'-g',t0,Y0(:,3),'-k')
grid on
legend('s','e','i')
xlabel('t-time')
title('y0=[0.5 0 0.5 ]')
subplot(2,1,2)
plot(t1,Y1(:,1),'-b',t1,Y1(:,2),'-g',t1,Y1(:,3),'-k')
legend('s','e','i')
grid on
xlabel('t-time')
title('y0=[0 0 1]')
%=====子函数
function dy=dif_dsdedi(t,y)
%y(1)=s y(2)=e y(3)=i
dy(1)=-0.5*y(1)*y(3)+0.5*y(3)-0.1*y(1)+0.1;
dy(2)=1.5*y(1)*y(3)-0.1*y(2)+0.9*y(2)*y(3);
dy(3)=y(3)^2+0.1*y(2)*y(3)-1.6*y(3);
dy=dy(:)
2024-04-02 广告