# Hamiltonians for harmonic oscillators

References: Shankar, R. (1994), Principles of Quantum Mechanics, Plenum Press. Section 2.5; Exercises 2.5.2 – 2.5.3.

Here are a couple of examples of equations of motion using the Hamiltonian formalism. First, we look at the simple harmonic oscillator, in which we have a mass ${m}$ sliding on a frictionless horizontal surface. The mass is connected to a spring with constant ${k}$, with the other end of the spring connected to a fixed support.

The Hamiltonian is given by

$\displaystyle H\left(q,p\right)=\sum_{i}p_{i}\dot{q}_{i}-L\left(q,\dot{q}\right) \ \ \ \ \ (1)$

where the velocities ${\dot{q}_{i}}$ are expressed in terms of the positions ${q_{i}}$ and momenta ${p_{i}}$. In this case, we have, using the coordinate ${x}$ as the displacement from equilibrium

 $\displaystyle L\left(x,\dot{x}\right)$ $\displaystyle =$ $\displaystyle \frac{1}{2}m\dot{x}^{2}-\frac{1}{2}kx^{2}\ \ \ \ \ (2)$ $\displaystyle p$ $\displaystyle =$ $\displaystyle \frac{\partial L}{\partial\dot{x}}=m\dot{x}\ \ \ \ \ (3)$ $\displaystyle \dot{x}$ $\displaystyle =$ $\displaystyle \frac{p}{m}\ \ \ \ \ (4)$ $\displaystyle L\left(x,\dot{x}\left(x,p\right)\right)$ $\displaystyle =$ $\displaystyle \frac{p^{2}}{2m}-\frac{1}{2}kx^{2}\ \ \ \ \ (5)$ $\displaystyle H$ $\displaystyle =$ $\displaystyle \frac{p^{2}}{m}-\left(\frac{p^{2}}{2m}-\frac{1}{2}kx^{2}\right)\ \ \ \ \ (6)$ $\displaystyle$ $\displaystyle =$ $\displaystyle \frac{p^{2}}{2m}+\frac{1}{2}kx^{2} \ \ \ \ \ (7)$

We can now apply Hamilton’s canonical equations:

 $\displaystyle \frac{\partial H}{\partial p}$ $\displaystyle =$ $\displaystyle \dot{x}\ \ \ \ \ (8)$ $\displaystyle -\frac{\partial H}{\partial x}$ $\displaystyle =$ $\displaystyle \dot{p} \ \ \ \ \ (9)$

We get

 $\displaystyle \frac{\partial H}{\partial p}$ $\displaystyle =$ $\displaystyle \frac{p}{m}=\dot{x}\ \ \ \ \ (10)$ $\displaystyle -\frac{\partial H}{\partial x}$ $\displaystyle =$ $\displaystyle -kx=\dot{p} \ \ \ \ \ (11)$

We thus get a pair of first order ODEs which can be solved in the usual way, given ${x\left(0\right)}$ and ${p\left(0\right)}$. The second order ODE that we got by using the Lagrangian method can be obtained by differentiating the first equation and plugging it into the second:

 $\displaystyle \ddot{x}$ $\displaystyle =$ $\displaystyle \frac{\dot{p}}{m}\ \ \ \ \ (12)$ $\displaystyle$ $\displaystyle =$ $\displaystyle -\frac{k}{m}x \ \ \ \ \ (13)$

From 7 we see that, since in the absence of external force, the total energy ${H=T+V=E}$ is a constant,

$\displaystyle \frac{p^{2}}{2m}+\frac{1}{2}kx^{2}=E=\mbox{constant} \ \ \ \ \ (14)$

This can be written as the equation of an ellipse:

$\displaystyle \frac{p^{2}}{b^{2}}+\frac{x^{2}}{a^{2}}=1 \ \ \ \ \ (15)$

where

 $\displaystyle a^{2}$ $\displaystyle =$ $\displaystyle \frac{2E}{k}\ \ \ \ \ (16)$ $\displaystyle b^{2}$ $\displaystyle =$ $\displaystyle 2mE \ \ \ \ \ (17)$

We can use the Hamiltonian formalism to get the equations of motion of the coupled harmonic oscillator. From our Lagrangian treatment, we had

$\displaystyle L=\frac{1}{2}m\left(\dot{x}_{1}^{2}+\dot{x}_{2}^{2}\right)-k\left(x_{1}^{2}+x_{2}^{2}-x_{1}x_{2}\right) \ \ \ \ \ (18)$

Converting to coordinates and momenta, we have

 $\displaystyle p_{i}$ $\displaystyle =$ $\displaystyle \frac{\partial L}{\partial\dot{x}_{i}}=m\dot{x}_{i}\ \ \ \ \ (19)$ $\displaystyle \dot{x}_{i}$ $\displaystyle =$ $\displaystyle \frac{p_{i}}{m}\ \ \ \ \ (20)$ $\displaystyle H$ $\displaystyle =$ $\displaystyle \sum_{i}p_{i}\dot{x}_{i}-L\left(x,\dot{x}\right)\ \ \ \ \ (21)$ $\displaystyle$ $\displaystyle =$ $\displaystyle \frac{1}{m}\left(p_{1}^{2}+p_{2}^{2}\right)-\left[\frac{1}{2m}m\left(p_{1}^{2}+p_{2}^{2}\right)-k\left(x_{1}^{2}+x_{2}^{2}-x_{1}x_{2}\right)\right]\ \ \ \ \ (22)$ $\displaystyle$ $\displaystyle =$ $\displaystyle \frac{1}{2m}\left(p_{1}^{2}+p_{2}^{2}\right)+k\left(x_{1}^{2}+x_{2}^{2}-x_{1}x_{2}\right) \ \ \ \ \ (23)$

Applying the canonical equations gives

 $\displaystyle \frac{\partial H}{\partial p_{i}}$ $\displaystyle =$ $\displaystyle \frac{p_{i}}{m}=\dot{x}_{i}\ \ \ \ \ (24)$ $\displaystyle -\frac{\partial H}{\partial x_{1}}$ $\displaystyle =$ $\displaystyle -2kx_{1}+kx_{2}=\dot{p}_{1}\ \ \ \ \ (25)$ $\displaystyle -\frac{\partial H}{\partial x_{2}}$ $\displaystyle =$ $\displaystyle -2kx_{2}+kx_{1}=\dot{p}_{2} \ \ \ \ \ (26)$

Again, by taking the derivative of the first line and substituting into the last two lines, we get back the previous equations of motion:

 $\displaystyle \ddot{x}_{1}$ $\displaystyle =$ $\displaystyle -2\frac{k}{m}x_{1}+\frac{k}{m}x_{2}\ \ \ \ \ (27)$ $\displaystyle \ddot{x}_{2}$ $\displaystyle =$ $\displaystyle \frac{k}{m}x_{1}-2\frac{k}{m}x_{2} \ \ \ \ \ (28)$