How to plot x(n) for many values of n?

26 ビュー (過去 30 日間)
SAS
SAS 2020 年 6 月 6 日
コメント済み: SAS 2020 年 6 月 7 日
How to plot 𝑥(𝑛) = 𝛼𝑛 𝑥(0) for n=1-30 and x(0)=100?? I have tried this code, but it is repeating it's value again and again... What I am missing?
alpha = 2
x0 = 100; % Initial conditions
for n = 1:30
x(n) = (alpha^n)*(x0)
end
disp(x(n))

採用された回答

madhan ravi
madhan ravi 2020 年 6 月 6 日
編集済み: madhan ravi 2020 年 6 月 6 日
Shorter code eliminating loop:
Alpha = 2
x0 = 100; % Initial conditions
n = 1:30;
x = Alpha.^n*x0;
plot(n,x)
Note: You were doing it correctly all you had to use was disp(x)
  9 件のコメント
madhan ravi
madhan ravi 2020 年 6 月 6 日
編集済み: madhan ravi 2020 年 6 月 6 日
SAS
SAS 2020 年 6 月 7 日
Issues resolved.

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

その他の回答 (1 件)

David Hill
David Hill 2020 年 6 月 6 日
alpha = 2
x0 = 100; % Initial conditions
for n = 1:30
x(n) = (alpha^n)*(x0)
end
disp(x);
plot(1:30,x);
  3 件のコメント
David Hill
David Hill 2020 年 6 月 6 日
x has only 30 values...use ; to suppress
alpha = 2;
x0 = 100; % Initial conditions
for n = 1:30
x(n) = (alpha^n)*(x0);
end
disp(x);
plot(1:30,x);
SAS
SAS 2020 年 6 月 6 日
Thanks dear...

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

カテゴリ

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

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by