MATLAB解ODE方程/方程组的数值解
\[\dot{x}_1(t)=r_1 x_1(1-\alpha_{11}x_1-\alpha_{12}x_2-\alpha_{13}x_3)\\
\dot{x}_2(t)=r_2 x_2(1-\alpha_{21}x_1-\alpha_{22}x_2-\alpha_{23}x_3)\\
\dot{x}_3(t)=r_3 x_3(1-\alpha_{31}x_1-\alpha_{32}x_2-\alpha_{33}x_3)\\
x_1(0)=0.1,\ x_2(0)=0.1,\ x_3(0)=0.1
\]
main.m
clear all;
global r1 r2 r3 a11 a12 a13 a21 a22 a23 a31 a32 a33
r1=0.1;
r2=0.1;
r3=0.1;
a11=1;
a12=0.3;
a13=0.4;
a21=0.2;
a22=1;
a23=0.3;
a31=0.3;
a32=0.4;
a33=1;
[t,x]=ode45(@func,[0,50],[0.1,0.1,0.1]);
plot(t,x(:,1),'r',t,x(:,2),'g',t,x(:,3),'b');
legend();
func.m
% func.m
function f=func(t,x)
global r1 r2 r3 a11 a12 a13 a21 a22 a23 a31 a32 a33
f = zeros(3,1);
f(1)=r1*x(1)*(1-a11*x(1)-a12*x(2)-a13*x(3))
f(2)=r2*x(2)*(1-a21*x(1)-a22*x(2)-a23*x(3))
f(3)=r3*x(3)*(1-a31*x(1)-a32*x(2)-a33*x(3))
% 确保f为行向量
f=f(:);
参考
https://www.cnblogs.com/gtts/archive/2011/05/17/2048595.html