Lagrangian Mechanics

The primary abstraction of MechanicsDSL is the Lagrangian \(\mathcal{L}\), defined as the difference between kinetic and potential energy.

\[\mathcal{L}(q, \dot{q}, t) = T(q, \dot{q}) - V(q)\]

Equations of Motion

The compiler automatically derives the equations of motion using the Euler-Lagrange equation:

\[\frac{d}{dt} \left( \frac{\partial \mathcal{L}}{\partial \dot{q}_i} \right) - \frac{\partial \mathcal{L}}{\partial q_i} = Q_i\]

Where \(Q_i\) represents generalized non-conservative forces (like drag or friction).

Symbolic Derivation Pipeline

  1. Velocity Jacobian: The compiler identifies the dependence of \(T\) on \(\dot{q}\).

  2. Hessian Matrix: It computes the mass matrix \(M_{ij} = \frac{\partial^2 \mathcal{L}}{\partial \dot{q}_i \partial \dot{q}_j}\).

  3. Linear Solve: It symbolically solves the linear system \(M \ddot{q} = \mathbf{F}\) to isolate accelerations.

Code Example

\system{double_pendulum}
\lagrangian{ 0.5*(m1+m2)*l1^2*\dot{t1}^2 + ... }