Euler method for modeling simple harmonic oscillation

Click For Summary

Discussion Overview

The discussion revolves around the application of the Standard Euler method for modeling a simple harmonic oscillator, specifically a mass-spring system. Participants are exploring the numerical implementation of the method, its stability, and energy conservation over time.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant outlines the equations governing the motion of a simple harmonic oscillator and presents their numerical implementation using the Standard Euler method.
  • Another participant suggests that the energy of the system should be plotted as a function of time to better illustrate the non-conservative nature of the method.
  • Concerns are raised about the implementation of the equations, with a participant indicating that the time-dependence of the variables may not be correctly represented in the provided code.
  • Further comments emphasize that the errors in the Euler method become noticeable even after a few cycles of oscillation.
  • A later reply includes a modification to the implementation, suggesting a different approach to calculating acceleration and updating the position and velocity.

Areas of Agreement / Disagreement

Participants express differing views on the effectiveness of the Standard Euler method for this application, with some agreeing on the need for careful attention to time-dependence, while others question the stability and energy conservation aspects of the method. The discussion remains unresolved regarding the best approach to accurately model the system.

Contextual Notes

There are unresolved issues regarding the implementation details and the assumptions made about the numerical method's stability and energy conservation. The discussion highlights potential limitations in the initial approach and the need for further exploration of the energy error over time.

acadian
Messages
3
Reaction score
0
Hello!

An assignment for my computational modeling course is to demonstrate the use of the Standard Euler method for modeling a simple harmonic oscillator; in this case, a mass attached to the end of a spring.

I have the two coupled first-order differential equations satisfying hookes law: dx/dt = v, and dv/dt = -(k/m)*x

The numerical solutions of which are v(t + dt) = v(t) - k*x(t)*dt / m, and x(t + dt) = x(t) + v(t)*dt to model the velocity and position, respectively.

In a computer program, I've represented this as:

x = x + v*dt;
v = v - k*x*dt / m;
t = t + dt;

with dt = 0.04, m = 1, k = 1, and initial values v = 0, t = 0, and x = 5.

The Purpose of the exercise is to demonstrate how the standard Euler Method is non-stable and results in non-conserved energy.

When iterating the above Euler method for sufficiently large periods of time, I've expected x to grow larger after each period but my numerical method above is acting like a conserved-energy Improved Euler method (Euler-cromer)? Please see attached plot.
 

Attachments

  • Screen Shot 2015-02-09 at 10.59.10 PM.png
    Screen Shot 2015-02-09 at 10.59.10 PM.png
    15.8 KB · Views: 1,403
Last edited:
Physics news on Phys.org
acadian said:
Hello!

An assignment for my computational modeling course is to demonstrate the use of the Standard Euler method for modeling a simple harmonic oscillator; in this case, a mass attached to the end of a spring.

I have the two coupled first-order differential equations satisfying hookes law: dx/dt = v, and dv/dt = -(k/m)*x

The numerical solutions of which are v(t + dt) = v(t) - k*x(t)*dt / m, and x(t + dt) = x(t) + v(t)*dt to model the velocity and position, respectively.

In a computer program, I've represented this as:

x = x + v*dt;
v = v - k*x*dt / m;
t = t + dt;

with dt = 0.04, m = 1, k = 1, and initial values v = 0, t = 0, and x = 5.

The Purpose of the exercise is to demonstrate how the standard Euler Method is non-stable and results in non-conserved energy.

When iterating the above Euler method for sufficiently large periods of time, I've expected x to grow larger after each period but my numerical method above is acting like a conserved-energy Improved Euler method (Euler-cromer)? Please see attached plot.

Your plot shows only a few cycles, where the method should probably be "good enough." What is the energy as a function of time? Why not plot the energy error as a function of time? Error = PE_0 - (KE + PE) -- When you plot the difference, it will be much more obvious that the system is non-conservative.
 
acadian said:
In a computer program, I've represented this as:

x = x + v*dt;
v = v - k*x*dt / m;
t = t + dt;
This does not implement the system of equations you have. Pay close attention to the time-dependence of the variables.
 
Quantum Defect said:
Your plot shows only a few cycles, where the method should probably be "good enough."
Euler's method is bad enough that the error is clearly noticeable even after two cycles!
 
DrClaude said:
This does not implement the system of equations you have. Pay close attention to the time-dependence of the variables.
... I missed that!
 
Thank you!

Modification:

e = (v*v/2) + (x*x/2);
a = -k*x / m;
x = x + v*dt;
v = v + a*dt;
t = t + dt;

Plotting e, t and x produces the following:
 

Attachments

  • Screen Shot 2015-02-10 at 6.01.05 PM.png
    Screen Shot 2015-02-10 at 6.01.05 PM.png
    15.3 KB · Views: 1,402

Similar threads

  • · Replies 7 ·
Replies
7
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 38 ·
2
Replies
38
Views
11K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K