Reiteration of Beverton-Holt model

%Program Beverton-Holt
initial = 15;
c = 0.002;
n = 100;
b = [0.5 0.9 1.0 1.1 1.5];
for i = 1:1:n+1;
x(i) = (i-1);
end
for i = 1:1:length(b);
y(1,i) = initial;
for j = 2:1:n+1;
y(j,i) = (b*y(j-1,i))/(1+(c*y(j-1,i)))
end
end
plot(x,y)
However, I haven't been able to get it run properly. It comes up with this error:
Subscripted assignment dimension mismatch.
Error in bevertonholt (line 14)
y(j,i) = (b*y(j-1,i))/(1+(c*y(j-1,i)))
I'm not sure why this is happening. Any help would be greatly appreciated.

Réponses (1)

Torsten
Torsten le 7 Oct 2015

0 votes

b is a vector of length 5, so in
y(j,i) = (b*y(j-1,i))/(1+(c*y(j-1,i)))
you try to assign a vector ((b*y(j-1,i))/(1+(c*y(j-1,i)))) to a scalar (y(j,i)), which is not possible.
Probably you mean
y(j,i) = (b(i)*y(j-1,i))/(1+(c*y(j-1,i)))
Best wishes
Torsten.

1 commentaire

Viktoria Kolpacoff
Viktoria Kolpacoff le 7 Oct 2015
Easy mistake to make. Thank you so much for your help.
VK

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by