필터 지우기
필터 지우기

For loop help, initilizing seed value

조회 수: 2 (최근 30일)
Chase
Chase 2013년 3월 4일
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!

답변 (2개)

Azzi Abdelmalek
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}

Rick Rosson
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);

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by