Harmonic oscillator action-angle variables (source code)

= Harmonic oscillator action-angle variables
{title2=$I=H/\omega,\quad\dot\theta=\omega$}

For a <harmonic oscillator> with <Hamiltonian> $H=p^2/(2m)+m\omega^2q^2/2$, where $m,\omega>0$, define
$$
I=\frac12\left(m\omega q^2+\frac{p^2}{m\omega}\right),\qquad
q=\sqrt{\frac{2I}{m\omega}}\sin\theta,\qquad
p=\sqrt{2Im\omega}\cos\theta.
$$
These <action-angle variables> are defined for $I>0$, with a local <angle> $\theta$ modulo $2\pi$. A proof of canonicity is $\theta_q=p/(2I)$ and $\theta_p=-q/(2I)$, which give $\{\theta,I\}=1$ using the <Poisson bracket>. Substitution gives $H=\omega I$. <Hamilton's equations> then prove $I(t)=I(0)$ and $\theta(t)=\theta(0)+\omega t$. The <action integral> around the corresponding <phase space> <ellipse> is $\oint p\,dq=2\pi I$, so $I$ is the usual normalized <action variable>. The <angle> is undefined at the zero-energy origin.