【发布时间】:2015-11-29 21:27:49
【问题描述】:
我想根据草的不同死亡率 (=D) 和生长情况创建地球上覆盖的草的最终比例(= 20 亿年后) (=A) 的 3D 图草率 (=G)。
A 的最终值(距现在 20 亿年)可以使用带有以下离散方程的循环来计算:
A(t+dt) = A(t)*((1-A(t))*G-D)*dt + A(t)
%Define variables and arrays
D=0.1; %constant value
G=0.4; %constant value
A=0.001; %initial value of A at t=0
t=0;
dt=10E6;
startloop=1; %define number of iterations
endloop=200;
timevector=zeros(1,endloop); %create vector with 0
grassvector=zeros(1,endloop);
%Define the loop
for t=startloop:endloop
A=A.*((((1-A).*G)-D)) + A;
grassvector(t)=A;
timevector(t)=t*dt;
end
现在我被困在如何创建 A 的最终值作为不同 G 和 D 的函数的 3D 图。我得到了这个,但经过几次试验后,它不断给出错误:
%(1) Create array of values for G and D varying between 0 and 1
A=0.001;
G=[0.005:0.005:1]; %Vary from 0.005 to 1 in steps of 0.005
D=[0.005:0.005:1]; %Vary from 0.005 to 1 in steps of 0.005
%(2) Meshgrid both variables = all possible combinations in a matrix
[Ggrid,Dgrid]=meshgrid(G,D);
%(3) Calculate the final grass fraction with varying G and D
D=0.1;
G=0.4;
A=0.001;
t=0;
dt=10E6;
startloop=1; %define number of iterations
endloop=200;
timevector=zeros(1,endloop); %create vector with 0
grassvector=zeros(1,endloop);
%Define the loop
for t=startloop:endloop
A=A.*((((1-A).*Ggrid)-Dgrid)) + A;
grassvector(t)=A;
timevector(t)=t*dt;
end
%(4) mesh together with D and G
...??
有人可以帮忙吗?谢谢!
【问题讨论】:
-
你的代码出错了,因为grassvector和A的大小不一样。首先,整理你的代码,然后询问绘图!