Euler method for modeling simple harmonic oscillation

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,361
Last edited:
Mathematics 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,372
Insights auto threads is broken atm, so I'm manually creating these for new Insight articles. In Dirac’s Principles of Quantum Mechanics published in 1930 he introduced a “convenient notation” he referred to as a “delta function” which he treated as a continuum analog to the discrete Kronecker delta. The Kronecker delta is simply the indexed components of the identity operator in matrix algebra Source: https://www.physicsforums.com/insights/what-exactly-is-diracs-delta-function/ by...
Fermat's Last Theorem has long been one of the most famous mathematical problems, and is now one of the most famous theorems. It simply states that the equation $$ a^n+b^n=c^n $$ has no solutions with positive integers if ##n>2.## It was named after Pierre de Fermat (1607-1665). The problem itself stems from the book Arithmetica by Diophantus of Alexandria. It gained popularity because Fermat noted in his copy "Cubum autem in duos cubos, aut quadratoquadratum in duos quadratoquadratos, et...
Thread 'Imaginary Pythagorus'
I posted this in the Lame Math thread, but it's got me thinking. Is there any validity to this? Or is it really just a mathematical trick? Naively, I see that i2 + plus 12 does equal zero2. But does this have a meaning? I know one can treat the imaginary number line as just another axis like the reals, but does that mean this does represent a triangle in the complex plane with a hypotenuse of length zero? Ibix offered a rendering of the diagram using what I assume is matrix* notation...
Back
Top