How do I get this graph?

12 ビュー (過去 30 日間)
Joo Seo Lee
Joo Seo Lee 2020 年 4 月 25 日
コメント済み: Ameer Hamza 2020 年 4 月 25 日
I want to get the graph of n and x(n) on x(n+1)=2.5*x(n)*(1-x(n)), where x(1)=0.9
I wrote
x(1)=0.9;
for n = 1:100,
x(n+1)=x(n)*(1-x(n))*2.5
plot (x(n),n)
end
and my plot is empty

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 25 日
編集済み: Ameer Hamza 2020 年 4 月 25 日
Try this
x(1)=0.9;
for n = 1:100
x(n+1)=x(n)*(1-x(n))*2.5;
end
plot(x)
In your code, you are just plotting one point at a time and then overwriting it with a new plot statement.
  2 件のコメント
Joo Seo Lee
Joo Seo Lee 2020 年 4 月 25 日
thanks!
Ameer Hamza
Ameer Hamza 2020 年 4 月 25 日
Glad to be of help.

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

その他の回答 (1 件)

Sriram Tadavarty
Sriram Tadavarty 2020 年 4 月 25 日
Hi Joo,
The code is calculating as you expected, but not plotting the same because, the plot is getting overwritten with the latest value of x(n).
You can try the following code modifications:
Option 1:
Use hold on to update the figure for each iteration
x(1)=0.9;
for n = 1:100
x(n+1)=x(n)*(1-x(n))*2.5;
plot(n,x(n),'*') % Plotting at each point, line doesn't help, so try symbols
hold on
end
Option 2:
Plot x after the computation
x(1)=0.9;
for n = 1:100
x(n+1)=x(n)*(1-x(n))*2.5;
end
plot(x)
Hope this helps.
Regards,
Sriram

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by