### Note

A lot of what I'm about to summarize comes from *Classical Mechanics: The Theoretical Minimum* by Leonard Susskind and
George Hrabovsky. It's an amazing book with the perfect amount of rigour to make for an enjoyable read while remaining
challenging if you're a beginning physics student - I highly recommend reading it. Also, just a disclaimer: Lagrangian and
Hamiltonian mechanics are both quite new to me, and writing this will probably allow me
understand what I've been reading more than teach the reader something - however, continue on if you want to see a fresh take on
this subject or you're in a similar place, because this is all pretty fresh at the moment.

## What is Phase Space?

Phase space is a powerful depiction of an object’s trajectory through time, whereby the evolution of its position and momentum can be depicted on a coordinate system (which may have 6 dimensions all together - 3 spatial dimensions and their corresponding momenta). Considering the movement of a particle in one dimension, the phase space depiction will have double that, so 2 dimensions. Essentially, a point on this coordinate system represents a unique combination of values along a set of position and momentum axes.

This allows for an elegant demonstration of utilising Hamiltonian mechanics to analyse the energy of a simple harmonic oscillator.

The action is an integral of a function over time, the function being the Lagrangian `$L = T - V$`

where T is the kinetic energy
and V is the potential energy. This isn’t always true but for a lot of systems it is. Thus, the action of a trajectory is
defined as such:

According to Richard Feynman, the principle of stationary action is one of the most beautiful in all of physics, and it comes
down to this - if you plot a function of A over all possible `$q$`

and `$\dot{q}$`

where these represent the coordinates and the
time derivative of the coordinates respectively, the trajectory, or path, taken is the one
for which A is a stationary point i.e. `$\delta A = 0$`

. In Cartesian coordinates, for example, q can be x, y, or z.

Deriving what follows requires maths known as the calculus of variations and is beyond the scope so I will skip straight to the important result:

which is known as the Lagrangian equation.

The statement above is analogous to Newton’s Second Law in that, along with some initial conditions, it is possible to determine
an object’s position at another point in time. In fact, you can transform the above equation into Newton’s Law by substituting
some known relations. Since `$L = T - V = \frac{1}{2}m\dot{q}^2 - V(q)$`

, this means that
`$\frac{\partial L}{\partial\dot{q}} = m\dot{q}$`

and `$\frac{\partial L}{\partial q} = -\frac{dV}{dq}$`

. Plugging these
equations into equation 1 yields

as expected. So this reconciles with Newtonian mechanics, which is great because then physics isn’t broken. An important thing
to take note of is the relationship `$\frac{\partial L}{\partial\dot{q}} = m\dot{q}$`

. This is the conjugate momentum of
a system and essentially the left-hand side is the Lagrangian definition of momentum.

The Hamiltonian is the energy of a system and its definition with relation to Lagrangian dynamics can be avoided for now
because for the SHM system this is just `$H = E_{\text{tot}} = T + V$`

.

Now take the Lagrangian for the SHM system: `$L = m \frac{\dot{x}^2}{2} - \frac{k}{2}x^2$`

. In order to get the Hamiltonian into
the nicest form possible, we can make the substitution `$q = (km)^{\frac{1}{4}}x$`

: since k and m are constants, this is allowed.

Let `$\omega = \sqrt{\frac{k}{m}}$`

(the angular velocity of the oscillator).

And now, using the Lagrangian definition of momentum,
`$p = \frac{\partial L}{\partial \dot{q}} = \frac{\dot{q}}{\omega}$`

. Also, we can identify the two terms in the
Lagrangian to be the kinetic and potential energies of the system.

and since in this system energy is conserved, we see that although the momentum and position vary continuously, the sum of the squares of these values is a constant. In other words, the state of the system can be depicted as a circle with one axis representing momentum and the other position. As the system evolves over time, the point moves around this circular trajectory forever, and it is this set-up that is known as phase space. After reading about all this, I made the animation above using p5.js to show such a system.