フィルターのクリア

Why is my code not working?

1 回表示 (過去 30 日間)
Derek Gabaldon
Derek Gabaldon 2019 年 9 月 22 日
コメント済み: Ankit 2019 年 9 月 23 日
I'm working on a project dealing with a function for a damped harmonic oscillator. I've found the derivate of this function to plot the velocities. I'm being asked to "Superimpose the respective velocities estimating them using a numerical approach." I'm not sure why the code I'm using won't run. I get no errors; the graph just never appears. I've linked the original m file. Any help is much appreciated!
  2 件のコメント
David Hill
David Hill 2019 年 9 月 23 日
編集済み: Walter Roberson 2019 年 9 月 23 日
Everything is working except question #5. What are you trying to do with question #5 (it does not make sense to me)? n(i) would be a scalar not a vector and most of your equations can be moved outside the loop. I'm not sure if this is what you wanted or not.
A=1;
g= c/(2*m); %Damping coefficient
wn=sqrt(k/m); %Natural frequency
wd=sqrt(((wn).^2)-(g).^2); %Damped natural frequency
t=linspace(0,20,1000); %Time value
x=A*exp(-g*t).*cos(wd*t); %x(t)
for i = 1:(length(t) -1)
n(i)= (x(i+1)-x(i))/(t(i+1)-t(i));
end
plot (t(1:end-1),n);
hold on
grid on
pause(0.1);
Ankit
Ankit 2019 年 9 月 23 日
Question 4 and Question 5 should have same output:
as in question 4
v = dx/dt, differentiation of displacement using differential calculus
and in question 5
v is approximated as change in x/change in t.
David code is giving also same results

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

回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by