Applying Lagrangian Mechanics

From Rigid Body Dynamics we learned that a mechanical system is described by generalized coordinates , velocities , and Lagrangian . Real motion is one that satisfies the Least Action Principle/Euler-Lagrange Equations. For rigid bodies, is not just a vector in but inside configuration space .

The theme was that mechanics is geometry (linear algebra) plus variational principles (calculus). This document takes that idea and applies it numerically to simulate physics.

Simple Numerical Methods

Standard numerical methods for solving ODEs (e.g. Forward Euler Method, or RK4) look at at a specific point in time and try to blindly guess the next geometric slope. A variational integrator is a numerical method that tries to preserve the underlying geometric structure of the system. It defines the total physical energy of the system across a span of time (“discrete action”) and uses calculus to find the trajectory that minimizes this energy over time (least action paths).

In particular, we see that in this example, when is larger (i.e. ), the system is stable in “asteroid belts”. Although the system is a good approximation, as it never explodes, it is still only an approximation. We can improve the accuracy of the system by replacing the RHS of the example with

where calculates the angle of a complex number in the complex plane. The result is that the system is stable for all , and removes the “asteroid belts” that we see in the previous example.

This image represents the exact trajectories on the position-momentum plane, where is the axis and is the axis.

Störmer-Verlet Method

What if instead of discretizing an ODE, what if we discretize the action and take the variational derivative to get the equations of motion?

Main Idea

Standard numerical methods look at the slope of the next discretized point. A variational integrator says “among all discrete paths, which one makes the discrete action stationary?”

Let denote the discrete timestep. A discrete Lagrangian is a function

approximating the total action between two positions. The continuous Lagrangian is Kinetic Energy minus Potential Energy:

Since we simulate this, time is broken up into steps of size . The discrete Lagrangian via the trapezoidal rule (from Calculus 1!) is:

So, the discrete total action of a path is

or the sum of all the discrte Lagrangian segments. Remember, we want to find the minimum of these segments.

Functional

Recall that this is the total action functional seen in here but discretized (approximating a curve with small segments)!

By the discrete least action principle, for all . We can derive this similar to how we showed the LAP. Let

Then to apply LAP, we need to find a stationary point where small pertubations to the path do not change the total action. We need to find the first variation (the derivative via multivariable chain rule) denoted as and setting it to .

The second term can be rewritten as

such that

But for this to equal , the inside terms must equal exactly.

We can now compute the first derivative of with respect to gives us

implying that

Let

This is different from RK41

This gives us an explicitly timestep march, where and so

Why is this better than RK4?

The idea is that variational integrators preserve the geometric structure of the shape of motion in configuration space better than generic ODE solvers.

Stability

See prior image. The Störmer-Verlet method is the variational integrator on the right. We see a cleaner phase portrait.

Discrete Euler-Lagrange Equation

The discrete Euler-Lagrange equation is the stationarity condition for the discrete action

For each interior index , varying while keeping the endpoints fixed gives

This is the discrete analogue of the continuous Euler-Lagrange equation. In particular, it is the general variational principle from which methods such as Störmer-Verlet Method are derived.

Interpretation

The two terms represent the two discrete action contributions meeting at the node : one contribution comes from the interval , and the other comes from the interval . Their sum vanishes because the discrete path is stationary with respect to variations of the interior point .

This is the discrete counterpart of the continuous idea that momentum is obtained from the velocity derivative of the Lagrangian:

Accordingly, the discrete Lagrangian defines two discrete Legendre transforms

by replacing the velocity description with a pair of nearby configurations. Define (the contangent bundle) by

The quantity

is the left discrete momentum at (contribution from previous state), and

is the right discrete momentum at (contribution to next state). The discrete Euler-Lagrange equation is exactly the matching condition

In terms of the maps and , this says

Therefore, if is locally invertible2, we can solve for the next pair from the previous pair by applying and then . This gives the marching rule

Thus the discrete EL equation gives an update map on , and through the maps it also induces the corresponding update on phase space . We can visualize this as

"\\begin{document}\n\\begin{tikzpicture}[>=stealth, scale=1.0]\n\n% Define colors matching the reference image\n\\definecolor{topblue}{RGB}{65, 110, 185}\n\\definecolor{botteal}{RGB}{90, 170, 155}\n\n% --- Nodes Top Row ---\n\\node (T1) at (2.5, 2.5) {\\Large $(\\mathbf{q}_{k-1}, \\mathbf{q}_k)$};\n\\node (T2) at (7.5, 2.5) {\\Large $(\\mathbf{q}_k, \\mathbf{q}_{k+1})$};\n\\node (T3) at (12.5, 2.5) {\\Large $(\\mathbf{q}_{k+1}, \\mathbf{q}_{k+2})$};\n\n% --- Nodes Bottom Row ---\n\\node (B1) at (0, 0) {\\Large $(\\mathbf{q}_{k-1}, \\mathbf{p}_{k-1})$};\n\\node (B2) at (5, 0) {\\Large $(\\mathbf{q}_k, \\mathbf{p}_k)$};\n\\node (B3) at (10, 0) {\\Large $(\\mathbf{q}_{k+1}, \\mathbf{p}_{k+1})$};\n\n% --- Top Horizontal Arrows (marching on QxQ) ---\n\\draw[|->, densely dotted, line width=1.5pt, topblue, shorten >=8pt, shorten <=8pt] \n (T1) -- (T2);\n\\draw[|->, densely dotted, line width=1.5pt, topblue, shorten >=8pt, shorten <=8pt] \n (T2) -- (T3);\n\n% --- Bottom Horizontal Arrows (marching on qp) ---\n\\draw[|->, densely dotted, line width=1.5pt, botteal, shorten >=8pt, shorten <=8pt] \n (B1) -- (B2);\n\\draw[|->, densely dotted, line width=1.5pt, botteal, shorten >=8pt, shorten <=8pt] \n (B2) -- (B3);\n\n% --- Diagonal Mapping Arrows ---\n\\draw[|->, line width=1.5pt, shorten >=6pt, shorten <=6pt] \n (T1) -- (B1) node[midway, left, xshift=-2pt, yshift=4pt] {\\Large $f_1$};\n \n\\draw[|->, line width=1.5pt, shorten >=6pt, shorten <=6pt] \n (T1) -- (B2) node[midway, right, xshift=2pt, yshift=4pt] {\\Large $f_2$};\n \n\\draw[|->, line width=1.5pt, shorten >=6pt, shorten <=6pt] \n (T2) -- (B2) node[midway, left, xshift=-2pt, yshift=4pt] {\\Large $f_1$};\n \n\\draw[|->, line width=1.5pt, shorten >=6pt, shorten <=6pt] \n (T2) -- (B3) node[midway, right, xshift=2pt, yshift=4pt] {\\Large $f_2$};\n \n\\draw[|->, line width=1.5pt, shorten >=6pt, shorten <=6pt] \n (T3) -- (B3) node[midway, left, xshift=-2pt, yshift=4pt] {\\Large $f_1$};\n\n% --- Explanatory Text Labels ---\n\\node[topblue, font=\\Large] at (6.5, 3.4) {marching on the $Q \\times Q$ space};\n\\node[botteal, font=\\Large] at (4.0, -0.9) {marching on the $q \\times p$ space};\n\n\\end{tikzpicture}\n\\end{document}"(qk¡1;qk)(qk;qk+1)(qk+1;qk+2)(qk¡1;pk¡1)(qk;pk)(qk+1;pk+1)f1f2f1f2f1marchingontheQ£Qspacemarchingontheq£pspace
source code

The space corresponds to the axes in the image.

Variational Integrators via Midpoint Rule

The midpoint rule is a variational integrator where the discrete Lagrangian is

The Euler-Lagrange equation is

and equivalently,

which is the implicit midpoint method. It is implicit because appears on both sides, so we cannot write a simple rule for it like in Störmer-Verlet Method.

Discrete Liouville Theorem

Marching on space preserves the enclosed area of the marched loop. In particular, the area is a section on the graphs we see above. This means that all possible positions and momentum are conserved as the system evolves over time.

The path the system takes between all the points may change, but the area of the path is preserved (even if the shape is complex). This geometric property is called symplecticity and is a consequence of the variational principle. This is precisely why variational integrators are better than generic ODE solvers: they preserve the underlying geometric structure of the system, which leads to better long-term stability and accuracy in simulations.

Discrete Noether’s Theorem

If the discrete Lagrangian has a continuous symmetry,

then is conserved (constant independent of ).

For example, if we let a particle move along a wire in empty space and then translate the entire system, the Lagrangian is invariant to this translation. Mathematically, let be a constant vector representing the direction of symmetry, and let be the start and be the end of a discrete segment. The translation is by some amount along is .

"\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsfonts}\n\n\\begin{document}\n\\begin{tikzpicture}[>=stealth, scale=1.3]\n\n% Define original points\n\\coordinate (qk) at (0.2, 0.7);\n\\coordinate (qk1) at (3.2, 1.4);\n\n% Define translated points (shifted by dx = +2.5, dy = -1.5)\n\\coordinate (tqk) at (2.7, -0.8);\n\\coordinate (tqk1) at (5.7, -0.1);\n\n% Draw original wire (gray)\n\\draw[thick, gray] (-0.5, -0.5) to[out=70, in=180] (2, 2) to[out=0, in=135] (4, 0.5);\n\\node[gray, above] at (2, 2) {Original Wire};\n\n% Draw translated wire (gray, dashed)\n\\draw[thick, gray, dashed] (2.0, -2.0) to[out=70, in=180] (4.5, 0.5) to[out=0, in=135] (6.5, -1.0);\n\\node[gray, below] at (4.5, 0) {Translated Wire};\n\n% Motion segment on original wire (blue)\n\\draw[->, ultra thick, blue] (qk) to[out=75, in=180] (2, 2) to[out=0, in=145] (qk1);\n\\filldraw[blue] (qk) circle (2.5pt) node[left, xshift=-4pt] {$\\mathbf{q}_k$};\n\\filldraw[blue] (qk1) circle (2.5pt) node[above right, yshift=2pt] {$\\mathbf{q}_{k+1}$};\n\n% Motion segment on translated wire (purple)\n\\draw[->, ultra thick, purple] (tqk) to[out=75, in=180] (4.5, 0.5) to[out=0, in=145] (tqk1);\n\\filldraw[purple] (tqk) circle (2.5pt) node[left, xshift=-4pt] {$\\mathbf{q}_k + \\varepsilon\\mathbf{v}$};\n\\filldraw[purple] (tqk1) circle (2.5pt) node[right, xshift=4pt] {$\\mathbf{q}_{k+1} + \\varepsilon\\mathbf{v}$};\n\n% Translation vectors (orange)\n\\draw[->, thick, dashed, orange] (qk) -- (tqk) node[midway, left] {$\\varepsilon\\mathbf{v}$};\n\\draw[->, thick, dashed, orange] (qk1) -- (tqk1) node[midway, right] {$\\varepsilon\\mathbf{v}$};\n\n\\end{tikzpicture}\n\\end{document}"OriginalWireTranslatedWireqkqk+1qk+"vqk+1+"v"v"v
source code

Because the Lagrangian is invariant to this translation, we have its derivative with respect to must be .

By the chain rule, this is equivalent to

Indeed, this is true for all and because of the symmetry.

We can show this is true for momentum. Recall from earlier that the discrete momentum entering the current step and leaving the current step 3 are

Substituting into the symmetry condition gives us

Indeed, momentum along the direction of symmetry is conserved across all steps .

Idea

This article gives a nice intuitive explanation of Noether’s theorem and how the ideas from Lagrangian Mechanics are used to show symmetry.

Definition (Time Reversal Symmetry)

In classical physics, the equations of motion are invariant under time reversal. If our discrete integrator satisfies the property that

then we say it is time-reversal symmetric. Indeed, the Störmer-Verlet Method is time-reversal symmetric.

Footnotes

  1. Why?

  2. Here, “locally invertible” means that near a regular point, the phase-space data uniquely determines a nearby next configuration . For the mechanical discrete Lagrangians used in this note, this holds whenever the discrete Lagrangian is regular, which is typically true for sufficiently small timestep .

  3. The negative sign is from the original Discrete Euler-Lagrange equation as described previously.