On this page
Simulate a mass on a spring with Euler's method and it slowly gains energy until the motion blows up. Velocity Verlet costs the same per step and does not. Here are the formulas, three steps to check by calculator, and the reason.
What are the Verlet and leapfrog update formulas?
Verlet integration is a numerical method for solving Newton's equations of motion, widely used for particle trajectories in molecular dynamics and computer graphics (Verlet integration, Wikipedia). The same article records earlier uses by Delambre in 1791 and Carl Størmer in 1907, before Loup Verlet rediscovered it for molecular dynamics.
With time step h and acceleration a = A(x), depending only on position, one velocity Verlet step is:
x(n+1) = x(n) + h·v(n) + ½h²·a(n)
a(n+1) = A(x(n+1)), the one new force calculation
v(n+1) = v(n) + ½h·[a(n) + a(n+1)]
Leapfrog is the same method written with velocities at half steps: v(n+½) = v(n−½) + h·a(n), then x(n+1) = x(n) + h·v(n+½), so positions and velocities leap over each other (Leapfrog integration, Wikipedia). Leapfrog is second order and Euler first order, yet each needs one force evaluation per step.
For comparison, Euler's method is x(n+1) = x(n) + h·v(n) and v(n+1) = v(n) + h·a(n).
Worked example: three steps with h = 0.1
Take a spring with m = k = 1, so a = −x, ω = 1 and the exact motion is x = cos t. Start at x = 1, v = 0, with energy E = (x² + v²)/2 = 0.5.
Euler's method:
Step 1: x = 1, v = −0.1, E = 0.505
Step 2: x = 0.99, v = −0.2, E = 0.51005
Step 3: x = 0.97, v = −0.299, E = 0.51515
Velocity Verlet:
Step 1: x = 1 − 0.005 = 0.995, v = 0.05 × (−1 − 0.995) = −0.09975, E = 0.49999
Step 2: x = 0.98005, v = −0.19850, E = 0.49995
Step 3: x = 0.95530, v = −0.29527, E = 0.49989
The exact answer at t = 0.3 is x = 0.95534, v = −0.29552. Verlet is out by about 0.00004 in position, Euler by about 0.015, and Euler's energy is already climbing.
Why does Euler's method spiral out while Verlet stays bounded?
Hairer, Lubich and Wanner (Acta Numerica, 2003) explain the general case. For the spring, two lines of algebra show it.
With a = −x, one Euler step gives x(n+1)² + v(n+1)² = (1 + h²)·[x(n)² + v(n)²]. With h = 0.1 the energy is multiplied by exactly 1.01 every step, so it is 2.7 times too big after 100 steps and about 21,000 times too big after 1,000. In the phase plane of x against v, the true circle becomes an outward spiral.
For velocity Verlet, the quantity (1 − h²/4)·x² + v² comes out exactly the same at every step. Check it: at step 0 it is 0.9975 × 1 + 0 = 0.9975, and at step 1 it is 0.9975 × 0.990025 + 0.00995 = 0.9975. The points stay on a fixed ellipse, so the energy only wobbles between 0.49875 and 0.5, forever, provided h is less than 2/ω (Leapfrog integration, Wikipedia). Our guide to drawing phase portraits for linear systems shows why the exact motion is a closed loop.
What makes an integrator symplectic?
Hairer, Lubich and Wanner explain that the Störmer–Verlet method is symplectic and follows almost exactly the flow of a slightly modified differential equation, which accounts for its long-time energy conservation and linear error growth (Acta Numerica, 2003).
In plain terms, a symplectic method preserves area in phase space; Euler enlarges every patch by a factor of 1 + h² each step, which is the spiral above. Leapfrog is also time-reversible: run n steps forward, then n back, and you land where you started (Leapfrog integration, Wikipedia). The same article notes that the fourth-order Runge–Kutta method does not conserve energy, which matters for long orbit runs.
Where are Verlet and leapfrog used?
Molecular dynamics. Loup Verlet's 1967 paper in Physical Review ran computer experiments on the thermodynamic properties of Lennard-Jones molecules (Verlet, 1967). The velocity form is credited to Swope and colleagues (1982).
Orbits. Cowell and Crommelin used the same scheme in 1909 to compute the orbit of Halley's Comet (Verlet integration, Wikipedia); our post on how many trips round the Sun Halley's Comet can survive follows that comet further.
A checklist before you simulate motion
Does the force depend only on position? Springs and gravity do; drag does not.
Keep h fixed; a changing step can destabilise the method (Leapfrog integration, Wikipedia).
Keep h well below 2/ω. h = 0.1 gives about 63 steps per period of the unit spring.
Print the energy now and then: it should wobble, not climb.
If a symbol here is unfamiliar, the Fermi Concept Library covers every concept in physics, chemistry, biology, mathematics and computing. For ideas that are easier to see than to read, try the Fermi Simulation Lab and its interactive simulations.



