Learning Scientific Programming with Python (2nd edition)

P8.2.5: The general pendulum

Question P8.2.5

The equation governing the motion of a pendulum consisting of a mass $m$ at the end of a light, rigid rod of length $l$ may be written $$ \frac{\mathrm{d}^2\theta}{\mathrm{d}t^2} = -\frac{g}{l}\sin\theta, $$ where $\theta$ is the angle the pendulum makes with the vertical.

Taking $l=1\;\mathrm{m}$ and $g=9.81\;\mathrm{m\,s^{-2}}$, determine the subsequent motion of the pendulum if it is started at rest with an initial angle $\theta_0 = 30^\circ$. Compare the motion with the harmonic approximation reached by assuming $\theta$ is small which has the analytical solution $\theta = \theta_0\cos(\omega t)$ with $\omega = \sqrt{g/l}$.