Foundations to Frontier
Tests
A. Mathematical Foundations › A13 Physics for Robotics and AI

Lagrangian Mechanics

Newton's laws need every force, including the constraint forces you don't care about. Lagrange's approach needs only two scalar functions, kinetic and potential energy, written in whatever coordinates suit the problem. This topic covers generalized coordinates and degrees of freedom, the Lagrangian L = T − V, the principle of stationary action, the Euler–Lagrange equations, generalized forces, and conservation laws from cyclic coordinates (Noether's idea). In the research exercise you build an 'automatic' Euler–Lagrange solver that derives equations of motion from L alone, then compute a two-link robot arm's joint torques for a smooth pick motion, verifying gravity compensation, the 1/T² torque law and the energy balance.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Physics from energy alone

Lagrange found a different way into mechanics. Instead of adding up forces and their directions, you write down just two numbers for any arrangement of the system: its energy of motion (kinetic, T) and its stored energy (potential, V). One recipe turns T − V into the equations of motion. It works for pendulums, robot arms and planets alike, in whatever coordinates are most convenient (angles, lengths, anything).

The double pendulum: deterministic, yet unpredictable
1e-121e-91e-61e-31e0time (s) →gap between the two (rad, log scale)
gap now 6.0e-2 rad (started at 1e-6) · energy drift over 20 s: 3.1e-5 J
Both pendulums follow the same equations, which come straight from the Lagrangian L = T − V with two generalized coordinates (the two angles). At small release angles the motion is nearly linear and the gap stays tiny. At large angles the gap grows exponentially (a straight rising line on the log plot) until the pendulums do completely different things: sensitive dependence on initial conditions (a9-5). The tiny energy drift shows the divergence isn't numerical error.
Why engineers care

Robot-arm dynamics, legged-robot models, spacecraft with flexible appendages and multibody simulators are almost always derived with Lagrangian methods. Model-based controllers (computed torque, MPC) and physics-informed networks (Lagrangian neural networks) are built directly on L = T − V.

📝 Quick check (Level 0)
0/3 answered
  1. 1. The Lagrangian is…
  2. 2. How many coordinates describe a double pendulum's configuration?
  3. 3. The double pendulum at large angles is…

Level 1: Beginner

★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.

Generalized coordinates

The degrees of freedom are the minimum number of independent numbers needed to describe a configuration: 1 for a pendulum (θ), 2 for a double pendulum or a 2-link arm, 6 for a free rigid body in space. Generalized coordinates qiq_i are any such set. Constraints (rigid rods, rolling) are built into the choice of coordinates, so their forces never appear.

The Lagrangian and the Euler–Lagrange equation

L(q,q˙)=T−V,ddt∂L∂q˙i−∂L∂qi=Qi,L(q, \dot q) = T - V,\qquad\frac{d}{dt}\frac{\partial L}{\partial\dot q_i} - \frac{\partial L}{\partial q_i} = Q_i,

where QiQ_i are generalized forces that aren’t in V (motor torques, friction). For a pendulum, L=12ml2θ˙2+mglcos⁡θL = \tfrac12ml^2\dot\theta^2 + mgl\cos\theta gives ml2θ¨=−mglsin⁡θml^2\ddot\theta = -mgl\sin\theta. The generalized momentum is pi=∂L/∂q˙ip_i = \partial L/\partial\dot q_i; for the pendulum it’s ml2θ˙ml^2\dot\theta, an angular momentum.

📝 Quick check (Level 1)
0/3 answered
  1. 1. Degrees of freedom of a free rigid body in space:
  2. 2. For a pendulum, ∂L/∂θ̇ equals…
  3. 3. Constraint forces (like rod tension) in the Lagrangian method…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Stationary action

Among all paths q(t) with fixed endpoints, the physical one makes the action S=∫t0t1L dtS = \int_{t_0}^{t_1}L\,dt stationary. Setting the first variation to zero gives exactly the Euler–Lagrange equation (the calculus of variations, a3-5-9). This is Hamilton’s principle.

Robot manipulators

For an n-joint arm, T=12q˙⊤M(q)q˙T = \tfrac12\dot q^\top M(q)\dot q and V = V(q). The Euler–Lagrange equations become the manipulator equation

M(q)q¨+C(q,q˙)q˙+G(q)=τ.M(q)\ddot q + C(q, \dot q)\dot q + G(q) = \tau.

M is the configuration-dependent mass matrix, C holds the Coriolis and centrifugal terms, G(q) = ∂V/∂q is gravity, and τ the joint torques. Given a desired trajectory, inverse dynamics computes τ. Forward dynamics solves for q̈ from τ.

Symmetries and conservation

If L doesn’t depend on a coordinate qkq_k (it’s cyclic), then pk=∂L/∂q˙kp_k = \partial L/\partial\dot q_k is conserved. For a central force, φ is cyclic, so mr2φ˙mr^2\dot\varphi is conserved (Kepler’s second law). If L has no explicit time dependence, energy is conserved. Noether’s theorem makes the general link: every continuous symmetry gives a conservation law.

🐍 Exercise 1: automatic Euler–Lagrange
Compute generalized accelerations from any Lagrangian L(q, q̇) using numerical derivatives (H q̈ = ∂L/∂q − J q̇). Check the pendulum, spring and projectile, match the textbook double-pendulum equations, and simulate with RK4 while monitoring energy.
📝 Quick check (Level 2)
0/3 answered
  1. 1. In the manipulator equation, G(q) represents…
  2. 2. A coordinate absent from L gives…
  3. 3. Hamilton's principle says the true path makes the action…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Euler–Lagrange reproduces Newton

For a particle with L=12m∣x˙∣2−V(x)L = \tfrac12m|\dot{\mathbf x}|^2 - V(\mathbf x), we get ∂L/∂x˙=mx˙\partial L/\partial\dot{\mathbf x} = m\dot{\mathbf x} and ∂L/∂x=−∇V\partial L/\partial\mathbf x = -\nabla V. So mx¨=−∇Vm\ddot{\mathbf x} = -\nabla V. ∎

Cyclic coordinates

If ∂L/∂qk=0\partial L/\partial q_k = 0, the Euler–Lagrange equation reads ddt∂L/∂q˙k=0\frac{d}{dt}\partial L/\partial\dot q_k = 0. ∎ If the radius halves under a central force, the angular rate quadruples.

Expanding the derivative

ddt∂L∂q˙=∂2L∂q˙2q¨+∂2L∂q˙ ∂qq˙\frac{d}{dt}\frac{\partial L}{\partial\dot q} = \frac{\partial^2L}{\partial\dot q^2}\ddot q + \frac{\partial^2L}{\partial\dot q\,\partial q}\dot q (for L without explicit t). This is the H q̈ + J q̇ form used in the code. For mechanical systems, H=M(q)H = M(q) is positive definite, so q̈ is always solvable.

Atwood machine, the Lagrangian way

With one coordinate x (rope length is fixed): L=12(m1+m2)x˙2+(m2−m1)gxL = \tfrac12(m_1 + m_2)\dot x^2 + (m_2 - m_1)gx, so x¨=(m2−m1)g/(m1+m2)\ddot x = (m_2 - m_1)g/(m_1 + m_2). No tension appears. ∎

📝 Quick check (Level 3)
0/3 answered
  1. 1. For mechanical systems, ∂²L/∂q̇² is…
  2. 2. Atwood with 1 kg and 3 kg via Lagrange: acceleration…
  3. 3. Euler–Lagrange for L = ½m ẋ² − V(x) gives…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

A planar arm moves in a vertical plane: link 1 is 2 kg × 0.5 m, link 2 is 1.5 kg × 0.4 m, both uniform. A minimum-jerk motion (zero velocity and acceleration at both ends) takes it from (−0.5, 0.3) rad to (0.8, 1.2) rad. Joint torques come from the Euler–Lagrange equations applied to L alone, via numerical derivatives.

  • Holding still: the torques are (13.646, 2.884) N·m, exactly the gravity torques. Gravity compensation is just G(q).
  • Move time: a 1 s move needs peak torques (21.99, 5.08) N·m. Doing it in 0.5 s needs (45.39, 11.48) N·m. The dynamic (non-gravity) part grows exactly ×4.00, the 1/T² law. That’s why fast robots need big motors and light arms.
  • Energy balance: integrated motor work, 17.94 J, equals the change in total energy, confirming the computed torques.

Computed-torque control feeds exactly this τ forward and corrects errors with feedback (Lynch and Park, 2017).

🐍 Exercise 2 (research): robot-arm inverse dynamics
Write the Lagrangian of a two-link arm, compute joint torques by automatic Euler–Lagrange for a minimum-jerk motion, verify gravity compensation, show the 1/T² scaling of dynamic torque, and check that motor work equals the change in total energy.

Lagrangian mechanics in AI, robotics and aerospace

  • Robot dynamics and control: the manipulator equation, computed-torque control, and passivity-based control exploiting the energy structure.
  • Learning: Lagrangian neural networks (Cranmer et al., 2020) and DeLaN (Lutter, Ritter and Peters, 2019) learn L from data, so the learned models conserve energy and generalize better.
  • Spacecraft: flexible-appendage and fuel-slosh models; multibody dynamics of deployables.
  • Simulation: variational integrators that discretize the action itself and inherit its conservation laws.

References

  1. H. Goldstein, C. Poole, J. Safko (2002). Classical Mechanics, 3rd ed. Addison-Wesley.
  2. K. Lynch, F. Park (2017). Modern Robotics. Cambridge.
  3. M. Cranmer, S. Greydanus, S. Hoyer, P. Battaglia, D. Spergel, S. Ho (2020). “Lagrangian neural networks.” ICLR Workshop on Integration of Deep Neural Models and Differential Equations.
  4. M. Lutter, C. Ritter, J. Peters (2019). “Deep Lagrangian networks: using physics as model prior for deep learning.” ICLR.
  5. J. Marsden, M. West (2001). “Discrete mechanics and variational integrators.” Acta Numerica, 10.