plotting the graph changing by the range

1 回表示 (過去 30 日間)
Joo Seo Lee
Joo Seo Lee 2020 年 4 月 26 日
コメント済み: Walter Roberson 2020 年 4 月 26 日
the given equation is
n=~20
x(n+1)=1.4x(n) for 0<x<0.5
x(n+1)=1.4(1-x(n)) for 0.5<x<1
I tried to use 'if' and 'elseif', but I can't make it repeat.

採用された回答

Walter Roberson
Walter Roberson 2020 年 4 月 26 日
x(1) = something
for n = 2 : number of iterations
if x(n) has some property
x(n+1) = some formula
elseif it has some other property
x(n+1) = some other formula
else
give an error because the situation is not defined
end
end
  2 件のコメント
Joo Seo Lee
Joo Seo Lee 2020 年 4 月 26 日
thanks for the answer, but
x(1) = 0.2
for n = 2 : 20
if 0<x(n)<0.5
x(n+1) = 1.4*x(n)
elseif 0.5<x(n)<1
x(n+1) = 1.4*(1-x(n))
else
give an error because the situation is not defined
end
end
only is done once and gives an error message that index exceeds the number of array elements.
Walter Roberson
Walter Roberson 2020 年 4 月 26 日
In MATLAB,
if 0<x(n)<0.5
means the same as
if ((0<x(n))<0.5)
The first test, 0<x(n) gives a logical result that is 0 (false) or 1 (true). Then the second test compares that 0 or 1 to 0.5. That code does not test to see if a variable is in a particular range. To test for a particular range, use seperate tests:
if 0 < x(n) & x(n) < 0.5
I should have written for
for n = 1 : 20-1

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTesting Frameworks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by