Hey guys, look what I did!

Which is to say that I wrote a Mathematica notebook which, given a Lagrangian, derives the canonical equations of the system. The test run (pictured) is a pendulum under the influence of gravity (V=mgh) where the mass m can move up and down the massless pendulum rod but is connected to the origin by a spring with spring constant k and rest length R.

The amazing thing is how wild non-linear systems can be; the graph shown is for k=0.8, m=0.8, R=1, g=0.2, released from rest at π/2 from the vertical (where θ=0), but playing around with these constants morphs the trajectory in various different ways and you can get a lot of different but interesting plots.

A quick educational bit: the Hamiltonian dynamics happens in phase space, Γ, but since this system has two degrees of freedom dim(Γ)=4 and you and I can’t visualize it. Nevertheless, there’s a trajectory γ[t] parameterized by the time that runs through Γ which the particle will follow given initial conditions. The graph here is the projection of that curve onto the configuration space, Q, so information about the particle’s momentum is lost here.