No damping but the solution to simple harmonic oscillator damps?

Click For Summary

Discussion Overview

The discussion centers around the unexpected damping observed in the solution of an undamped simple harmonic oscillator, specifically in the context of simulating the Duffing oscillator using MATLAB's ode45 function. Participants explore potential reasons for this phenomenon, including numerical errors and algorithm choices.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant notes that the exact solution for the undamped simple harmonic oscillator is ##\cos (5\sqrt 2 t)## but observes damping in their simulation.
  • Another participant suggests that damping may arise from numerical errors that affect the system's energy, leading to an appearance of damping.
  • Some participants propose trying different ODE solvers or finer steps to mitigate the issue, mentioning that ODE45 may not be ideal for very stiff systems.
  • A participant shares an experience with simulating planetary orbits, highlighting how algorithmic errors can lead to energy loss or gain in closed systems.
  • There is a discussion about finding algorithms that alternate adding and removing errors to maintain energy conservation in simulations.
  • One participant inquires about the initial conditions used in the simulations, noting their implementation of the Duffing oscillator in C with a different integrator that yielded the correct undamped solution.

Areas of Agreement / Disagreement

Participants express differing views on the causes of the observed damping, with some attributing it to numerical errors while others suggest exploring algorithmic approaches. The discussion remains unresolved regarding the exact reason for the damping in the simulation.

Contextual Notes

Participants mention the importance of algorithm choice and initial conditions, but there are no settled assumptions or definitions regarding the nature of the damping observed in the simulations.

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
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   Reactions: member 428835
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.
 
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   Reactions: jedishrfu
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?
 
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.
 
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   Reactions: jedishrfu
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##.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
Replies
9
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
7
Views
1K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 7 ·
Replies
7
Views
5K