Harmonic Oscilation. When I plot f towards time amplitude is increasing I don't know why. It should be constant. what's wrong?

1 view (last 30 days)
When I plot f towards time amplitude is increasing I don't know why. It should be constant. what's wrong?
for i= 1:N
t(i+1)=t(i)+dt;
E(i)=-f(i); % Equation for the z axial motion
w(i+1)=w(i)+E(i)*dt;
f(i+1)=f(i)+w(i)*dt;
end
plot(t,f);
  2 Comments
Nikoloz Nikuradze
Nikoloz Nikuradze on 10 Sep 2020
f(1)=3; %% Ratation angle (Rad)
w(1)=0; %% Angular velocity (Rad/sec)
E(1)=0; %% Angular acceleration
t(1)=0; %% Time vector (sec)
dt=0.001;
N=1000000;
%% The main code
for i= 1:N
t(i+1)=t(i)+dt;
E(i)=-f(i); % Equation for the z axial motion
w(i+1)=w(i)+E(i)*dt;
f(i+1)=f(i)+w(i)*dt;
end
plot(t,f);

Sign in to comment.

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 10 Sep 2020
Well if you have an equation of motion you should write it as an ordinary differential equation and solve it with a more ambitious method than the "explicit-Euler"-looking method you've chosen. Have a look at ode45 and its siblings. It seems pretty likely that at least one example of ODE-integration in the help, documentation and demos for the ode45, ode23 etc functions explicitly deals with harmonic oscillations. You likely can find some analysis of the expected long-term behaviour of explicit Euler-methods for this case if you search the internet.
HTH

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!