# softmatter:Verlet Algorithm

Verlet algorithm is probably the most widely used integration scheme in molecular simulations for integrating equations of motion to determine trajectories and velocities of particles. It is important to note that the Verlet algorithm does not directly use velocity to advance particles through time. To derive the algorithm, we proceed as follows:

## General Algorithm

Taylor expansion for position of a particle at time t + Δt is:

$\mathbf{r}(t + \Delta t) = \frac{\mathbf{r}(t)}{0!} + \frac{\mathbf{r}'(t) \Delta t}{1!} + \frac{\mathbf{r}''(t) \Delta t^2}{2!} + \frac{\mathbf{r}'''(t) \Delta t^3}{3!} + O(\Delta t^4) \qquad \qquad [1]$

where $\mathbf{r}(t)$ is the position of the particle at time t and Δt is the time step of integration.

Since the first derivative $\mathbf{r}'(t)$ is the velocity $\mathbf{v}(t)$ of the particle at time t and the second derivative $\mathbf{r}''(t)$ is the acceleration $\mathbf{a}(t)$ of the particle at time t, the above equation becomes

$\mathbf{r}(t + \Delta t) = \mathbf{r}(t) + \mathbf{v}(t) \Delta t + \frac{\mathbf{a}(t) \Delta t^2}{2} + \frac{\mathbf{r}'''(t) \Delta t^3}{6} + O(\Delta t^4) \qquad \qquad [2]$

Similarly taylor expansion for particle position at time t − Δt is:

$\mathbf{r}(t - \Delta t) = \mathbf{r}(t) - \mathbf{v}(t) \Delta t + \frac{\mathbf{a}(t)}{2} \Delta t^2 - \frac{\mathbf{r}'''(t) \Delta t^3}{6} + O(\Delta t^4) \qquad \qquad [3]$

Adding equations [2] and [3] and rearranging terms we get the following expression for position of the particle at time t + Δt:

$\mathbf{r}(t + \Delta t) = 2 \mathbf{r}(t) - \mathbf{r}(t - \Delta t) + \mathbf{a}(t) \Delta t^2 + O(\Delta t^4)$

Note that here acceleration $\mathbf{a}(t) = \frac{\mathbf{f}(t)}{m}$ where $\mathbf{f}(t)$ is the net force on the particle at time t and m is the mass of the particle. Also, the new position contains an error of the order Δt4 and has been determined without using velocity values.

Further, subtracting equation [3] from [2] we get:

$\mathbf{r}(t + \Delta t) - \mathbf{r}(t - \Delta t) = 2 \mathbf{v}(t) \Delta t + O( \Delta t^3)$

## Calculating Velocity

Dividing the entire equation by Δt and rearranging terms we get the expression for velocity of the particle at time t:

$\mathbf{v}(t) = \frac{\mathbf{r}(t + \Delta t) - \mathbf{r}(t - \Delta t)}{2 \Delta t} + O(\Delta t^2)$

Thus in verlet algorithm, velocities of particles at time t are only evaluated after determining particle positions at time t + Δt. Also, the velocity estimate is less accurate than the position estimate as it contains an error of order Δt2. These disadvantages of the verlet algorithm have been overcome in its variants Leapfrog Algorithm, Velocity Verlet Algorithm and Velocity-corrected Verlet Algorithm.