For loop help, initilizing seed value
2 次查看(过去 30 天)
显示 更早的评论
heres what my problem boils down to, i want to loop over initial values for P,and output the value of P(250) but i dont know how to do it. For the following code, i get an error for "Unbalanced or unexpected parenthesis" in line 2, for P(1)
r = 3;
for P(1) = linspace(0.1,0.9,100);
for n = 1:250
P(n+1) = P(n)*r*(1-P(n));
end
end
P(250)
any help would be appreciated!
0 个评论
回答(2 个)
Azzi Abdelmalek
2013-3-4
编辑:Azzi Abdelmalek
2013-3-4
Do you mean?
clear
r = 3;
P(1)=0.1
for n = 1:249
P(n+1) = P(n)*r*(1-P(n));
end
P(250)
%or maybe
clear
r = 3;
P{1}=linspace(0.1,0.9,100);
for n = 1:249
P{n+1} = P{n}*r.*(1-P{n});
end
P{250}
0 个评论
Rick Rosson
2013-3-4
编辑:Rick Rosson
2013-3-4
r = 3;
N = 250;
initValues = linspace(0.1,0.9,100);
M = length(initValues);
finalValues = zeros(M,1);
P = zeros(N,1);
for k = 1:M
P(1) = initValues(k);
for n = 1:N-1
P(n+1) = P(n)*r*(1-P(n));
end
finalValues(k) = P(N);
end
plot(initValues,finalValues);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!