Time stepping: Smart, Dumb and Midpoint Euler

We now consider three different versions of time stepping for Newtonian mechanics in its basic form of the harmonic oscillator:

  • dx = v*dt,
  • dv=a*dt
  • a = -x.

Dumb Euler (position first updated) with x_n=x(n*dt), v_n=v(n*dt):

  • x_{n+1}=x_n + v_n*dt
  • v_{n+1}=v_n - x_{n+1}*dt

Smart Euler (velocity first updated):

  • v_{n+1}=v_n - x_n*dt
  • x_{n+1}=x_n + v_{n+1}*dt

Midpoint Euler:

  • v_{n+1}=v_n - x_{n+\frac{1}{2}}*dt
  • x_{n+1}=x_n + v_{n+\frac{1}{2}}*dt

where

  • x_{n+\frac{1}{2}}=\frac{1}{2}*(x_n+x_{n+1})
  • v_{n+\frac{1}{2}}=\frac{1}{2}*(v_n+v_{n+1})

as averages represent midpoint values between time n*dt and (n+1)*dt. Midpoint Euler is an implicit method with the new value at (n+1)*dt appearing also on the right hand side. This requires iteration with repetition of the update with successively new values introduced on the right.

Watch this code to see that Midpoint Euler is most accurate followed by Smart Euler, which lives up to its name as the right way to do explicit updating of first velocity and then position, while Dumb Euler is much less accurate.

Test with different number of iterations in Midpoint Euler (m<4 as default).