For loop help, initilizing seed value
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
Azzi Abdelmalek
il 4 Mar 2013
Modificato: Azzi Abdelmalek
il 4 Mar 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 Commenti
Rick Rosson
il 4 Mar 2013
Modificato: Rick Rosson
il 4 Mar 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 Commenti
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!