我有下一个代码:BD_MACRO,但是当朗姆酒时,我在matlab的命令窗口中得到了这个答案
BD_MACROPA 下标索引必须是实数正整数或 逻辑。
BD_MACROPA中的错误(第27行) dH = betaH((aH-bH)* H(i-1)+ phi * h(i-1))- alphaH * Z(i-1);
[![% MODELO BASICO
dt=0.01; % pasos en el tiempo
tiempo=2000; % anos de evolucion
%CONDICIONES INICIALES
H(1)=100; h(1)=250; Z(1)=200; t(1)=0;
%PARAMETROS
%ADULTOS Y PREADULTOS
aH = 147.9;
ah = 34.25;
bh = 0.20;
bH = 0.20;
phi= 0.25;
ro = 34.24;
muZ = 0.15;
H0 = 10.0;
alphaH = 0.000001;
alphah = 0.000001;
lambda = 6.0;
betaH = 0.095;
betah = 0.095;
rand('state',sum(100*clock)); % semilla de generador de numeros aleatorios,
%
numreps=5000; % numero de realizaciones
for j=1:numreps
for i=2:tiempo
dH = betaH((aH - bH) * H(i-1) + phi * h(i-1)) - alphaH * Z(i-1);
dh = betah((ah - bh) * h(i-1) + ro * H(i-1)) - alphah * Z(i-1);
dZ = Z(i-1) * (lambda * H(i-1)./(H0 + H(i-1)) + (r - mu + (bH + bh)) - alpha * (H(i-1) + Z(i-1))./H(i-1));
H(i) = H(i-1) + dt * dH;
h(i) = h(i-1) + dt * dh;
Z(i) = Z(i-1) + dt * dZ;
t(i) = t(i-1) + dt;
end
end
% Create figure
figure1 = figure;
% Create axes
axes1 = axes('Parent',figure1);
hold(axes1,'on');
% Create multiple lines using matrix input to plot
plot1 = plot(t,H,t,P,t,Z,'LineWidth',2);
set(plot1(1),'DisplayName','H');
set(plot1(2),'DisplayName','P','LineStyle','--');
set(plot1(3),'DisplayName','Z','LineStyle','.-');
%plot(t,H,t,P)
% Create xlabel
xlabel('Tiempo');
% Create ylabel
ylabel('Tamaño de la Población');
box(axes1,'on');
grid(axes1,'on');
% Set the remaining axes properties
set(axes1,'FontSize',12);
% Create legend
legend1 = legend(axes1,'show');
set(legend1,'FontSize',20);
legend('Hospederos Adultos', 'Hospederos Preadultos','Zoosporas');][1]][1]
答案 0 :(得分:0)
您可能在语句中缺少*符号
dH = betaH((aH - bH) * H(i-1) + phi * h(i-1)) - alphaH * Z(i-1);
现在,这正在尝试访问dH的第14833个元素,而您将dH定义为标量。我想你想要的是
dH = betaH*((aH - bH) * H(i-1) + phi * h(i-1)) - alphaH * Z(i-1);
与dH相同的问题。您在语句中也有未声明的变量alpha,mu和r
dZ = Z(i-1) * (lambda * H(i-1)./(H0 + H(i-1)) + (r - mu + (bH + bh)) - alpha * (H(i-1) + Z(i-1))./H(i-1));