For loop help, initilizing seed value
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Azzi Abdelmalek
am 4 Mär. 2013
Bearbeitet: Azzi Abdelmalek
am 4 Mär. 2013
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 Kommentare
Rick Rosson
am 4 Mär. 2013
Bearbeitet: Rick Rosson
am 4 Mär. 2013
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 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!