# Deriving the Leapfrog Integrator

Assume we have a second-order ordinary differential equation

with initial conditions and .

Assume there is no analytical equation for that satisfied the differential equation. We can use a numerical integration algorithm to compute values of on discrete time steps . We’ll focus on explicit integrators which extrapolate from the previous value .

The Leapfrog method is commonly-used in molecular dynamics. Here, we’ll walk through the steps of deriving the Leapfrog method.

We begin by finding the Taylor series of , , and around :

We need to re-arrange and make substitutions of the terms in the Taylor series for and so that they only contain the values , , , and . We begin by truncating the Taylor series of after the first-order term and re-arrange:

We then note the following relationships:

By truncating the Taylor series for and at the second-order terms and applying the above substitutions, we get a variation of the Leapfrog integrator:

Since we truncated the equations for and at the second-order terms, the Leapfrog integrator is third-order accurate for a single update of the velocities and positions. This means that if we half the time step, the per-step error is divided by eight. The global error for the method is , making it a secord-order method.

In a future blog post, we’ll compare the analytical model for the harmonic oscillator to approximations made with the Leapfrog integrator. This comparison will allow us to verify the order of the error of the Leapfrog integrator.