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일

0 개 추천

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

Ömer Fatih Özdemir
Ömer Fatih Özdemir 2022년 5월 8일
Thank you! it works. And i should make a plot of the velocity that is first derivative of displacement equation(y1)(A*sin(w0*t1(i))) again 10 times how can i do?
Torsten
Torsten 2022년 5월 8일
t1 = 1:10
for i = 1:10
y1(i) = A*sin(w0*t1(i));
dy1dt(i) = A*w0*cos(w0*t1(i));
end
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개)

카테고리

도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by