获得3个竞争物种的情节

时间:2016-03-17 20:40:36

标签: matlab matlab-figure

我想为竞争三种物种的模型制作代码以获得绘图(polt 3d z对x,y和2d绘制x,y,z对时间) 我的模特是

x'=(r1-a1x-b1y-c1z)x
y'=(r2-a2x-b2y-c2z)y
z'=(r3-a3x-b3y-c3z)z

其中

r1=1.5; r2=2.65; r3=3.45;
a1=0.1; b1=0.3; c1=0.01; b2=0.2;
a2=0.3; c2=0.2; c3=0.2; a3=0.01; b3=0.1.

任何帮助做这个代码将不胜感激。

1 个答案:

答案 0 :(得分:0)

解决问题:

% Define diff. equations, time span and initial conditions, e.g.
tspan = [0 20];
y0 = [0.2 0.2 0.2];

r1=1.5;     r2=2.65;    r3=3.45;
a1=0.1;     a2=0.3;     a3=0.01; 
b1=0.3;     b2=0.2;     b3=0.1;
c1=0.01;    c2=0.2;     c3=0.2; 

dy = @(t,y) [
(r1-a1*y(1)-b1*y(2)-c1*y(3))*y(1);
(r2-a2*y(1)-b2*y(2)-c2*y(3))*y(2);
(r3-a3*y(1)-b3*y(2)-c3*y(3))*y(3)];

% Solve differential equations
[t,y] = ode45(dy, tspan, y0);

现在只绘制结果:

% Plot all species against time
figure(1)
plot(t,y)

% 3D plot of z against xy
figure(2)
plot3(y(:,1), y(:,2), y(:,3))
grid on
xlabel('x')
ylabel('y')
zlabel('z')