Variational integrator

Variational integrators are numerical integrators for Hamiltonian systems derived from the Euler–Lagrange equations of a discretized Hamilton's principle. Variational integrators are momentum-preserving and symplectic.

Derivation of a simple variational integrator
Consider a mechanical system with a single particle degree of freedom described by the Lagrangian


 * $$L(t,q,v) = \frac 1 2 m v^2 - V(q),$$

where $$m$$ is the mass of the particle, and $$V$$ is a potential. To construct a variational integrator for this system, we begin by forming the discrete Lagrangian. The discrete Lagrangian approximates the action for the system over a short time interval:



\begin{align} L_d(t_0, t_1, q_0, q_1) & = \frac{t_1 - t_0}{2} \left[ L\left(t_0, q_0, \frac{q_1-q_0}{t_1-t_0}\right) + L\left(t_1, q_1, \frac{q_1-q_0}{t_1-t_0}\right) \right] \\ & \approx \int_{t_0}^{t_1} \, dt\, L(t, q(t), v(t)). \end{align} $$

Here we have chosen to approximate the time integral using the trapezoid method, and we use a linear approximation to the trajectory,


 * $$q(t) \approx \frac{q_1 - q_0}{t_1-t_0}(t - t_0) + q_0$$

between $$t_0$$ and $$t_1$$, resulting in a constant velocity $$v \approx \left(q_1 - q_0 \right)/\left(t_1 - t_0 \right)$$. Different choices for the approximation to the trajectory and the time integral give different variational integrators. The order of accuracy of the integrator is controlled by the accuracy of our approximation to the action; since


 * $$L_d(t_0, t_1, q_0, q_1) = \int_{t_0}^{t_1} \, dt\, L(t,q(t),v(t)) + \mathcal{O}(t_1 - t_0)^2,$$

our integrator will be second-order accurate.

Evolution equations for the discrete system can be derived from a stationary-action principle. The discrete action over an extended time interval is a sum of discrete Lagrangians over many sub-intervals:


 * $$S_d = L_d(t_0, t_1, q_0, q_1) + L_d( t_1, t_2, q_1, q_2) + \cdots.$$

The principle of stationary action states that the action is stationary with respect to variations of coordinates that leave the endpoints of the trajectory fixed. So, varying the coordinate $$q_1$$, we have


 * $$\frac{\partial S_d}{\partial q_1} = 0 = \frac{\partial}{\partial q_1} L_d\left(t_0, t_1, q_0, q_1 \right) + \frac{\partial}{\partial q_1} L_d\left( t_1, t_2, q_1, q_2 \right).$$

Given an initial condition $$(q_0, q_1)$$, and a sequence of times $$(t_0,t_1,t_2)$$ this provides a relation that can be solved for $$q_2$$. The solution is


 * $$q_2 = q_1 + \frac{t_2 - t_1}{t_1 - t_0}(q_1 - q_0) - \frac{(t_2 - t_0) (t_2 - t_1)}{2m} \frac{d}{dq_1} V(q_1).$$

We can write this in a simpler form if we define the discrete momenta,


 * $$p_0 \equiv -\frac{\partial}{\partial q_0} L_d(t_0, t_1, q_0, q_1)$$

and


 * $$p_1 \equiv \frac{\partial}{\partial q_1} L_d(t_0, t_1, q_0, q_1).$$

Given an initial condition $$(q_0,p_0)$$, the stationary action condition is equivalent to solving the first of these equations for $$q_1$$, and then determining $$p_1$$ using the second equation. This evolution scheme gives


 * $$q_1 = q_0 + \frac{t_1 - t_0}{m} p_0 - \frac{(t_1 - t_0)^2}{2m} \frac{d}{dq_0} V(q_0)$$

and


 * $$p_1 = m \frac{q_1 - q_0}{t_1 - t_0} - \frac{t_1 - t_0} 2 \frac{d}{dq_1} V(q_1).$$

This is a leapfrog integration scheme for the system; two steps of this evolution are equivalent to the formula above for $$q_2$$