[Screen shot comparing Euler's method (red) with the analytic (gray) SHO solution.]

Week 3 Notes: Introduction to Ordinary Differential Equations

In order to begin our study of the numerical solution of ordinary differential equations, we model a mass on a spring using a Hooke's Law approximation to the spring force.  Although the analytic solution to this simple harmonic oscillator is well known, it pays to begin with a model with a known analytic result so that we can compare this result with various numerical approximations.

Second model: Euler's Simple Harmonic Oscillator Solution

The SHO Euler Model displays the time evolution of a simple harmonic oscillator using Euler's method and compares this numerical solution to the analytic solution.

 

Dynamical variables, such as position and velocity, are variables that evolve according to a differential equation and Euler's method assumes that the rate of change of any dynamical variable u is constant throughout the time interval.  In other words, if we know the value of u at time t0, we estimate its value at t0+Δt using:

 

This algorithm is applied to the position x, velocity vx, and time t variables in the model's evolution workpanel as follows.

double force=-k*x;  // compute force
x +=  vx*dt ;       // advance position
vx += force*dt/m;   // advance velocity
t += dt;            // advance time

At the position vs. time data generated by this algorithm is displayed in the x-trail in the main frame's plotting panel.  The fixed relations workpanel computes the analytic solution and this solution is plotted in x-analytic trail for comparison with the numerical algorithm.

 

Questions:

Why are the two solutions not the same?  What advantage, if any, does Euler's method have?

Related Models

The following simple harmonic oscillator (SHO) models compare different solution techniques.  These models are listed in order of complexity.

Credits:

The SHO Euler Model was created by Wolfgang Christian using the Easy Java Simulations (EJS) version 4.1 authoring and modeling tool.  You can examine and modify a compiled EJS model if you run the model (double click on the model's jar file), right-click within a plot, and select "Open Ejs Model" from the pop-up menu.  You must, of course, have EJS installed on your computer.

 

Information about Ejs is available at: <http://www.um.es/fem/Ejs/> and in the OSP comPADRE collection <http://www.compadre.org/OSP/>.