Euler-Lagrange Dynamics

March 22, 2026 · View on GitHub

Overview & Motivation

The Euler-Lagrange equations provide a systematic way to derive the equations of motion for mechanical systems from energy principles. Instead of tracking forces on each body (as in Newton's method), they express dynamics in terms of generalized coordinates qq and the system's kinetic and potential energy.

For a robotic manipulator or any articulated mechanism with nn degrees of freedom, the Euler-Lagrange formulation yields a compact matrix equation:

M(q)q¨+C(q,q˙)q˙+g(q)=τM(q)\ddot{q} + C(q, \dot{q})\dot{q} + g(q) = \tau

Where:

  • qRnq \in \mathbb{R}^n — generalized coordinates (joint angles/positions)
  • q˙,q¨\dot{q}, \ddot{q} — generalized velocities and accelerations
  • M(q)Rn×nM(q) \in \mathbb{R}^{n \times n} — mass (inertia) matrix, symmetric positive definite
  • C(q,q˙)q˙RnC(q, \dot{q})\dot{q} \in \mathbb{R}^n — Coriolis and centrifugal terms
  • g(q)Rng(q) \in \mathbb{R}^n — gravitational terms
  • τRn\tau \in \mathbb{R}^n — generalized forces/torques (inputs)

This formulation supports two fundamental computations:

  • Forward dynamics: given torques τ\tau, compute accelerations q¨=M1(τCq˙g)\ddot{q} = M^{-1}(\tau - C\dot{q} - g)
  • Inverse dynamics: given desired accelerations q¨\ddot{q}, compute required torques τ=Mq¨+Cq˙+g\tau = M\ddot{q} + C\dot{q} + g

Mathematical Theory

Prerequisites

The Lagrangian of a system is defined as:

L(q,q˙)=T(q,q˙)V(q)\mathcal{L}(q, \dot{q}) = T(q, \dot{q}) - V(q)

where TT is kinetic energy and VV is potential energy.

Core Definitions

The Euler-Lagrange equation for coordinate qiq_i is:

ddtLq˙iLqi=τifor i=1,,n\frac{d}{dt}\frac{\partial \mathcal{L}}{\partial \dot{q}_i} - \frac{\partial \mathcal{L}}{\partial q_i} = \tau_i \quad \text{for } i = 1, \ldots, n

For a rigid-body system, kinetic energy takes the form:

T=12q˙TM(q)q˙T = \frac{1}{2}\dot{q}^T M(q) \dot{q}

Applying the Euler-Lagrange equation to this quadratic form yields the standard manipulator equation:

M(q)q¨+C(q,q˙)q˙+g(q)=τM(q)\ddot{q} + C(q, \dot{q})\dot{q} + g(q) = \tau

Mass Matrix M(q)M(q)

The mass matrix is always symmetric (M=MTM = M^T) and positive definite (q˙TMq˙>0\dot{q}^T M \dot{q} > 0 for q˙0\dot{q} \neq 0). These properties guarantee:

  • The forward dynamics linear system Mq¨=fM\ddot{q} = f always has a unique solution
  • Physical kinetic energy is always non-negative

Coriolis Matrix C(q,q˙)C(q, \dot{q})

The Coriolis matrix captures velocity-dependent forces using Christoffel symbols of the first kind:

cij=k=1n12(mijqk+mikqjmjkqi)q˙kc_{ij} = \sum_{k=1}^{n} \frac{1}{2}\left(\frac{\partial m_{ij}}{\partial q_k} + \frac{\partial m_{ik}}{\partial q_j} - \frac{\partial m_{jk}}{\partial q_i}\right)\dot{q}_k

A key property: M˙2C\dot{M} - 2C is skew-symmetric, which is important for passivity-based control.

Gravity Vector g(q)g(q)

gi(q)=Vqig_i(q) = \frac{\partial V}{\partial q_i}

where V(q)V(q) is the total potential energy of the system.

Complexity Analysis

OperationTimeSpaceNotes
Forward dynamicsO(n3)O(n^3)O(n2)O(n^2)Dominated by M1M^{-1} solve via Gaussian elimination
Inverse dynamicsO(n2)O(n^2)O(n2)O(n^2)Matrix-vector multiplication Mq¨M \ddot{q}
Model evaluationModel-dependentO(n2)O(n^2)Computing M(q)M(q), C(q,q˙)C(q,\dot{q}), g(q)g(q)

For systems with n6n \leq 6 DOF (typical robotic manipulators), the O(n3)O(n^3) cost of Gaussian elimination is negligible. For larger systems, consider the Recursive Newton-Euler Algorithm (RNEA) which achieves O(n)O(n) inverse dynamics.

Step-by-Step Walkthrough

Example: Simple Pendulum (1-DOF)

A point mass mm on a rigid rod of length ll:

System parameters: m=1kgm = 1\,\text{kg}, l=1ml = 1\,\text{m}, g0=9.81m/s2g_0 = 9.81\,\text{m/s}^2

Model matrices:

  • M(q)=ml2=1.0M(q) = ml^2 = 1.0
  • C(q,q˙)q˙=0C(q, \dot{q})\dot{q} = 0 (single DOF → no Coriolis)
  • g(q)=mglsin(q)=9.81sin(q)g(q) = mgl\sin(q) = 9.81\sin(q)

Forward dynamics at q=0.5radq = 0.5\,\text{rad}, q˙=0\dot{q} = 0, τ=0\tau = 0:

q¨=M1(τCq˙g)=009.81sin(0.5)1.0=4.703rad/s2\ddot{q} = M^{-1}(\tau - C\dot{q} - g) = \frac{0 - 0 - 9.81\sin(0.5)}{1.0} = -4.703\,\text{rad/s}^2

Inverse dynamics for holding position (q¨=0\ddot{q} = 0):

τ=Mq¨+Cq˙+g=0+0+9.81sin(0.5)=4.703N⋅m\tau = M\ddot{q} + C\dot{q} + g = 0 + 0 + 9.81\sin(0.5) = 4.703\,\text{N·m}

For a 2-DOF arm with equal links (m1=m2=1kgm_1 = m_2 = 1\,\text{kg}, l1=l2=1ml_1 = l_2 = 1\,\text{m}):

At rest (q=[0,0]Tq = [0, 0]^T, q˙=[0,0]T\dot{q} = [0, 0]^T):

  • sin(q1)=0\sin(q_1) = 0, sin(q1+q2)=0\sin(q_1 + q_2) = 0
  • g=[0,0]Tg = [0, 0]^T → gravity terms vanish when links hang vertically
  • Forward dynamics with τ=0\tau = 0 produces q¨=[0,0]T\ddot{q} = [0, 0]^T (equilibrium)

Pitfalls & Edge Cases

  • Singular mass matrix: Should not happen for physically valid systems, but numerical conditioning degrades near kinematic singularities (e.g., fully extended arm). The Gaussian elimination solver uses partial pivoting to help.
  • Fixed-point arithmetic: Dynamics values (torques, accelerations) typically exceed the [1,1)[-1, 1) range of Q15/Q31 formats. Use float unless inputs are carefully scaled.
  • Coriolis computation: The choice of Coriolis parameterization (Christoffel vs. factored form) affects the skew-symmetry property of M˙2C\dot{M} - 2C. The interface returns the product C(q,q˙)q˙C(q,\dot{q})\dot{q} directly, leaving the parameterization choice to the user.
  • Energy consistency: For simulation, ensure the model matrices satisfy the skew-symmetry property; otherwise, energy may not be conserved in numerical integration.
  • Units: Be explicit about whether angles are in radians (standard) and torques in N·m.

Variants & Generalizations

VariantTrade-offUse Case
Euler-Lagrange (this)O(n3)O(n^3) forward, closed-form, intuitiveSmall systems (n6n \leq 6), control design, analysis
Newton-EulerBody-by-body force balanceSingle rigid bodies, intuitive for simple systems
Recursive Newton-Euler (RNEA)O(n)O(n) inverse dynamicsLarge kinematic chains, real-time control
Articulated Body Algorithm (ABA)O(n)O(n) forward dynamicsLarge chains, simulation
Hamiltonian formulationPhase-space, symplectic integrationLong-horizon simulation, energy preservation

Applications

  • Robot control: Computed torque control, gravity compensation, impedance control
  • Simulation: Forward dynamics integration for physics simulation
  • System identification: Estimate dynamic parameters from measured motion
  • Trajectory optimization: Inverse dynamics as constraints in optimization
  • Vibration analysis: Linearized dynamics around equilibrium points

Connections to Other Algorithms

  • Gaussian Elimination (GaussianElimination.md): Used internally to solve Mq¨=fM\ddot{q} = f in forward dynamics
  • LQR Controller (Lqr.md): Euler-Lagrange dynamics can be linearized to produce the (A,B)(A, B) state-space matrices needed for LQR design
  • Kalman Filter (../filters/active/): State estimation for partially observed dynamical systems derived from Euler-Lagrange models
  • DARE (DiscreteAlgebraicRiccatiEquation.md): Discretized Euler-Lagrange systems feed into DARE for optimal control gain computation

References & Further Reading

  • Siciliano, B., Sciavicco, L., Villani, L., & Oriolo, G. (2009). Robotics: Modelling, Planning and Control. Springer. Chapters 7–8.
  • Spong, M. W., Hutchinson, S., & Vidyasagar, M. (2020). Robot Modeling and Control (2nd ed.). Wiley. Chapter 6.
  • Murray, R. M., Li, Z., & Sastry, S. S. (1994). A Mathematical Introduction to Robotic Manipulation. CRC Press.
  • Featherstone, R. (2008). Rigid Body Dynamics Algorithms. Springer. (For RNEA and ABA extensions.)