### Small angle approximation

We can take the example of the simple pendulum and make the angle very small. Then, $$\begin{align*}\cos(\theta) &\approx 1 - \tfrac{1}{2}\theta^2 \\ \sin(\theta) &\approx \theta \end{align*}$$

We could use the $sin$ approximation in the force law, or the $cos$ approximation in the potential, which becomes $$U(\theta) = -mgrcos \theta \approx -mgr \left(1 - \tfrac{1}{2}\theta^2 \right)$$

We can add or subtract any constant from the potential without changing the physics of the situation, thus we can write $$U(\theta) = \tfrac{1}{2}mgr\theta^2$$ which is the potential for a **harmonic oscillator**.

The general function, which doesn't necessarily involve masses, gravity or even angles, is written $$U(x) = \tfrac{1}{2}kx^2$$ where $k$ is some constant. This is a form of Hooke's Law, where $k$ is the spring constant and the force on a particle is $$F = -kx$$

### General solution

The Lagrangian, (conjugate) momentum and (generalised) force are given by $$\begin{align*}L &= \tfrac{1}{2}m\dot{x}^2 - \tfrac{1}{2}kx^2\\p &= \pi_x = \frac{\partial L}{\partial \dot{x}} = m\dot{x}\\F &= G_x = \frac{\partial L}{\partial x} = -kx\end{align*}$$ thus, the equation of motion is (as expected) $$m \ddot{x} = -kx$$

This usually gets written as $$\ddot{x} + \omega^2 x = 0 \quad \text{ where }\quad \omega = \sqrt{\frac{k}{m}}$$

The solution can be written in a few equivalent ways $$\begin{align*}x(t) &= a \cos \omega t + b \sin \omega t\\x(t) &= A \cos (\omega t + \phi)\\x(t) &= A \cos \omega(t - t_0)\end{align*}$$ where $a, b, A, \phi, t_0$ are constants to be determined by initial conditions.

### The Hamiltonian form

The Hamiltonian for the harmonic oscillator is $$\begin{align*}H &= p \dot{x} - L\\&= m \dot{x}^2 - (\tfrac{1}{2}m\dot{x}^2 - \tfrac{1}{2}kx^2)\\&= \tfrac{1}{2}m\dot{x}^2 + \tfrac{1}{2}kx^2\end{align*}$$

In the Hamiltonian form, the equations of motion are written in terms of coordinates and their conjugate momenta, rather than their velocities (time derivatives). For one thing, the equations become somewhat simpler, although not by much in simple expressions $$H(p, x) = \frac{1}{2m}p^2 + \frac{k}{2}x^2$$

In principle, it is always possible to solve $p = p(x, \dot{x})$ for $\dot{x}$, and then replace it in the original expression for $H$.

This is the energy of the system, and for any particular energy, $E$, the expression for the Hamiltonian is an ellipse in the phase space $$\frac{1}{2m}p^2 + \frac{k}{2}x^2 = E$$

Any point on the ellipse will remain on the ellipse for all time. Both the coordinate and the momentum oscillate and the period of the oscillation is related to the frequency.

In this form, $p$ and $x$ are essentially interchangeable.