Setup first lets setup up some imports import numpy as np import sympy as smp import matplotlib.pyplot as plt plt.rcParams['figure.figsize'] = (16.0, 6.0) smp.init_printing() from sympy.physics import mechanics as mcx #mcx.init_vprinting() mcx.mechanics_printing() #smp.init_printing() Goldstein 1.19 Solve spherical pendulum by lagrangian.
t = smp.Symbol('t') g = smp.symbols('g',constant=True); #accleration due to gravity m = smp.symbols('m',real=True,positive=True,constant=True) theta,phi= mcx.dynamicsymbols('theta,phi'); r = smp.symbols('r',constant=True) rdt = smp.diff(r); thd = smp.diff(theta); phd = smp.diff(phi) x = r*smp.sin(theta)*smp.cos(phi); xdt = smp.diff(x,t) y = r*smp.sin(theta)*smp.sin(phi); ydt = smp.diff(y,t) z = r*smp.cos(theta); zdt = smp.diff(z,t); ydt $$r \operatorname{sin}\left(\phi\right) \operatorname{cos}\left(\theta\right) \dot{\theta} + r \operatorname{sin}\left(\theta\right) \operatorname{cos}\left(\phi\right) \dot{\phi}$$V = m*g*r*smp.cos(phi) T = smp.Rational(1,2)*m*(xdt**2+ydt**2+zdt**2); T; smp.simplify(T) $$\frac{m r^{2}}{2} \left(\operatorname{sin}^{2}\left(\theta\right) \dot{\phi}^{2} + \dot{\theta}^{2}\right)$$So the total kinetic energy of the spherical pendulum is
...