For loop help, initilizing seed value
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
Azzi Abdelmalek
le 4 Mar 2013
Modifié(e) : Azzi Abdelmalek
le 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 commentaires
Rick Rosson
le 4 Mar 2013
Modifié(e) : Rick Rosson
le 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 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!