Plot with while loop

4 ビュー (過去 30 日間)
Ömer Fatih Özdemir
Ömer Fatih Özdemir 2022 年 5 月 8 日
What is the problem with my codes? I could not see the plot.
m=0.5;
k=5;
A=0.5;
w0=sqrt(k/m);
t1=1;
while (t1<10)
y1=A*sin(w0*t1);
t1=t1+1;
end
plot(t1,y1)

採用された回答

Alan Stevens
Alan Stevens 2022 年 5 月 8 日
By the time you get to the plot command you only have a single value of t1 and a single value of y1 as you overwrite each of them each time through the while loop. You would be better to use a for loop here, something like:
t1 = 1:10
for i = 1:10
y1(i) = A*sin(w0*t1(i));
end
  4 件のコメント
Alan Stevens
Alan Stevens 2022 年 5 月 8 日
Just add
v(i) = A*w0*cos(w0*t1(i));
Ömer Fatih Özdemir
Ömer Fatih Özdemir 2022 年 5 月 8 日
Thank you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by