Solution (source code)

= Solution

<Lagrangian mechanics> expresses dynamics through <generalized coordinates> $q_i$ that respect the constraints. For a system with conservative, velocity-independent <forces> and standard <kinetic energy>, the <Lagrangian> is $L=T-V$. Its equations follow from the <principle of stationary action>:
$$
\mathcal S[q]=\int_{t_1}^{t_2}L(q,\dot q,t)\,dt,\qquad \delta\mathcal S=0
$$
for variations that vanish at the endpoints. Varying the <integral> and integrating the $\delta\dot q_i$ term by parts gives
$$
\delta\mathcal S=\int_{t_1}^{t_2}\sum_i\left[\frac{\partial L}{\partial q_i}-\frac d{dt}\frac{\partial L}{\partial\dot q_i}\right]\delta q_i\,dt.
$$
Independent variations therefore yield the <Euler-Lagrange equations>:
$$
\boxed{\frac d{dt}\frac{\partial L}{\partial\dot q_i}-\frac{\partial L}{\partial q_i}=0.}
$$
Additional nonconservative <generalized forces> appear on the right-hand side as $Q_i$. The <action> is stationary, not necessarily a minimum. For ideal <holonomic constraints>, using suitable <generalized coordinates> removes the need to solve explicitly for constraint <forces>.

The <conjugate momentum> is $p_i=\partial L/\partial\dot q_i$. If a coordinate is cyclic, $\partial L/\partial q_i=0$ and its <conjugate momentum> is conserved. If $L$ has no explicit time dependence, the <energy> function
$$
E=\sum_i\dot q_ip_i-L
$$
is conserved. It equals $T+V$ for the usual quadratic <kinetic energy> with time-independent geometry, but that identification is not universal for every <Lagrangian> or constraint.

For example, a <simple pendulum> with angle $\theta$, length $\ell$ and bob mass $m$ has
$$
L=\frac12m\ell^2\dot\theta^2+mg\ell\cos\theta,
\qquad \ddot\theta+\frac g\ell\sin\theta=0.
$$
The <tension> does no <virtual work> in the allowed angular displacement and never needs to be calculated to obtain the angular equation. The method scales naturally to coupled systems and coordinates with complicated geometry.