Reiteration of Beverton-Holt model
1 view (last 30 days)
Show older comments
%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.
0 Comments
Answers (1)
Torsten
on 7 Oct 2015
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.
See Also
Categories
Find more on Sources in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!