No damping but the solution to simple harmonic oscillator damps?

In summary, the conversation discusses an issue with a code that simulates a damped simple harmonic oscillator. The exact solution for the undamped case is known, but when the same code is used, it appears to be introducing damping. Suggestions are made to try a different ODE solver and to choose one that respects the important symmetries of the system. The conversation also mentions finding an algorithm that alternates between adding and subtracting error to produce an accurate simulation. One person shares their experience with implementing the Duffing oscillator in C and getting the correct solution for the undamped case. The conversation ends with a discussion about the initial conditions used in the simulation.
  • #1
member 428835
I posted yesterday but figured it out; however, a different issue I just detected with the same code arose: namely, why does the solution damp here for an undamped simple harmonic oscillator? I know the exact solution is ##\cos (5\sqrt 2 t)##.

Code:
global delta alpha beta gamma OMEG
delta      = 0;     % DAMPING
alpha     = 50;   % STIFFNESS
beta       = 0;     % RESTORATION NONLINEARITY
OMEG    = 1.2;  % DRIVING FORCE ANGULAR FREQ
gamma  = 0;     % FORCING

Fs = 100;       % Sampling frequency                  
T  = 1/Fs;      % Sampling period     
L  = 10000;     % Length of signal

[t, x]  = ode45(@duffing,(0:L-1)*T,[0 1]);

plot(t,x(:,2))

and the function ode45 calls is

Code:
function xdot = duffing(t,x)
global delta alpha beta gamma OMEG
xdot(1) = -delta*x(1) - alpha*x(2) - beta*x(2)^3 + gamma*cos(OMEG*t);
xdot(2) = x(1);
xdot    = xdot';
end
 
Physics news on Phys.org
  • #2
Damping can occur when error is introduced somehow. The error in this case would be subtracting from the system energy causing it to appear as damping.

You could try another ODE solver beside ODE45 to see if that fixes the problem.

When simulating stuff, error can introduce more energy or take away energy depending on the algorithm chosen. As an example, Euler methods are good for systems that are non-periodic such as tracking a particle trajectory and ODE45 is good for periodic systems. In general, though ODE45 always seemed to be the best even though it could be slower in some cases.

You could also try a finer step.

Here's how to choose an ode solver:

https://www.mathworks.com/help/matlab/math/choose-an-ode-solver.html
Here's the MATLAB description of the ode45 solver:

https://www.mathworks.com/help/matlab/ref/ode45.html
which mentions it might not be good for very stiff systems.

As an aside, I found some Matlab notes on using ode45 that might be of interest:

https://www.12000.org/my_notes/matlab_ODE/
 
Last edited:
  • Like
Likes member 428835
  • #3
When we ran simulations of planetary orbits in java code using one of the Euler variants, we would get either a planet crashing into the Sun or zipping off on a journey of adventure and off our screen due to the algorithm introducing small error that manifested as energy loss or energy gain in a closed system.

The trick was to find an algorithm that alternated adding some error and then taking it away and between those two limits produced an effective and accurate simulation over longer periods of time.
 
  • #4
jedishrfu said:
The trick was to find an algorithm that alternated adding some error and then taking it away and between those two limits produced an effective and accurate simulation over longer periods of time.
Another way would be to find an algorithm that respects the important symmetries of the system, ie, one that is explicitly designed such that energy is conserved.
 
  • Like
Likes jedishrfu
  • #5
jedishrfu said:
Damping can occur when error is introduced somehow. The error in this case would be subtracting from the system energy causing it to appear as damping.
Can you elaborate on this please?
 
  • #6
Orodruin said:
Another way would be to find an algorithm that respects the important symmetries of the system, ie, one that is explicitly designed such that energy is conserved.
Any ideas for such an algorithm? See, I'm using my developed code to solve the Duffing oscillator, so there are nonlinear components. I just thought I'd benchmark the code with an equation that admits an analytic solution first.
 
  • #7
What are the initial conditions?

For "fun," I implemented the Duffing oscillator in C using RKF45 from GSL, which should be the same integrator as the one used by Matlab, and I get the correct solution for the undamped case.
 
  • Like
Likes jedishrfu
  • #8
DrClaude said:
What are the initial conditions?

For "fun," I implemented the Duffing oscillator in C using RKF45 from GSL, which should be the same integrator as the one used by Matlab, and I get the correct solution for the undamped case.
Hmmmm this is odd. I use ##x(0) = 1## and ##\dot x (0) = 0##.
 

1. What is a simple harmonic oscillator?

A simple harmonic oscillator is a system that follows a sinusoidal motion in response to an applied force. It is characterized by a restoring force that is proportional to the displacement of the object from its equilibrium position.

2. What does "no damping" mean in relation to a simple harmonic oscillator?

"No damping" means that there is no external force acting on the system to dissipate its energy. This results in the oscillations continuing indefinitely without losing amplitude.

3. How does the solution to a simple harmonic oscillator change when there is no damping?

Without damping, the solution to a simple harmonic oscillator will still exhibit a sinusoidal motion, but the amplitude of the oscillation will remain constant rather than decreasing over time.

4. Can a simple harmonic oscillator exhibit damping even if there is no external force acting on it?

Yes, a simple harmonic oscillator can exhibit damping due to internal friction or drag forces within the system. In this case, the amplitude of the oscillation will decrease over time.

5. How does the damping ratio affect the solution to a simple harmonic oscillator?

The damping ratio, which is a measure of the amount of damping in a system, affects the solution to a simple harmonic oscillator by determining the rate at which the amplitude of the oscillation decreases. A higher damping ratio results in a faster decrease in amplitude, while a lower damping ratio allows the oscillation to continue for a longer period of time before dissipating.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
Replies
7
Views
649
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • Classical Physics
Replies
5
Views
978
Replies
6
Views
2K
Replies
4
Views
1K
  • Introductory Physics Homework Help
Replies
7
Views
3K
  • Introductory Physics Homework Help
Replies
6
Views
779
  • Classical Physics
Replies
17
Views
1K
Back
Top