3 Hamiltonian Mechanics
Numerical experiments are just what their name implies: experiments. In describing and evaluating them, one should enter the state of mind of the experimental physicist, rather than that of the mathematician. Numerical experiments cannot be used to prove theorems; but, from the physicist’s point of view, they do often provide convincing evidence for the existence of a phenomenon. We will therefore follow an informal, descriptive and nonrigorous approach. Briefly stated, our aim will be to understand the fundamental properties of dynamical systems rather than to prove them. ~ Michel Hénon, “Numerical Exploration of Hamiltonian Systems,” in Chaotic Behavior of Deterministic Systems [21], p. 57.

The formulation of mechanics with generalized coordinates and momenta as the dynamic state variables is called the Hamiltonian formulation. This is equivalent to the Lagrangian formulation, but present a differnet point of view. It is especially useful for understanding the evolution of a system, especially when there are symmetries and conserved quantities

In systems with symmetries, the conjugate momenta of “cyclic coordinates” (which do not appear in the Lagrangian) are conserved. This insight can be used to simplify and solve many problems in dynamics (e.g. spinning top). The Hamiltonian formulation is motivated by the desire to focus attention on the momenta.

In the Lagrangian formulation, the momenta are “secondary” quantities – they are functions of state variables and the evolution of these state variables only depend on the state variables themselves and not the momenta. Since the momenta can be inferred form velocities, it is possible to represent the dynamics in terms of coordinates and momenta. In such a formulation, if a momentum is conserved, it is immediately apparent from its dynamic equation.

Mechanical systems can exhibit simple or complex behavior  periodic motion, chaotic motion etc. Sometimes the periodicity may be driven by an external force. The Hamiltonian formulation of dynamics provides a convenient framework in which the possible motions may be placed and understood. We will be able to see the range of stable resonance motions and the range of states reached by chaotic trajectories, and discover other unsuspected possible motions.
3.1 Hamilton’s Equations
$\require{cancel}$
Restricting our attention to Lagrangians that only depend onf time, coordinates and velocities, the momenta in a system can be represented as functions of coordinates, velocities and time. It is possible to invert these functions to get a local representation of velocity in terms of time, coordinates and momenta. The equations of motion when recast in terms of coordinates and momenta are called Hamilton’s canonical equations. We will look at three derivations of these equations:

The first strategy is an expansion of the one described in the above paragraph  starting with inverting the momentum state function.

The second derivation in Section 3.1.1 first abstracts a key part of the first derivation and then applies the more abstract machinery to derive Hamilton’s equations. The third (section 3.1.2) uses the action principle.
The equations for the time derivative of a momentum can be found from Lagrange’s equations as:
where (by definition of generalized momenta),
To eliminate $Dq(t)$ from Eq. 3.1, we need to invert Eq.3.2. To avoid confusion, we will do this by assigning simple variable names to the function arguments and its output. If Eq.3.1 is restated as:
Then the equation can be inverted in terms of the third argument to get the new function $\mathscr{V}$ so that:
Substituting $a$ from Eq. 3.3 in 3.4 (and $d$ in Eq. 3.3),
THis pattern can be applied to Eq. 3.1 to get:
Similarly, Eq. 3.2 can be inverted to get:
Equations 3.7 and 3.8 give dynamic equations for $q$ and $p$ as functions of time, coordinates and momenta. To represent this better, we can define a new Lagrangian as a function of time, coordinates and momenta.
Here we are using mnemonic names t, q, p for formal parameters of the function being defined. We could have used names like a, b, c as above, but this would have made the argument harder to read.
To get the equations of motion, we need to compute $\partial_1 L$ (applying the chain rule, assuming that $L$ is not an explicit function of time):
We introduce the “momentum selector” function here, $P(t,q,p) = p$ such that $\partial_1 P = 0$ to get,
In Eq. 3.11, $H$ is the Hamiltonian defined as:
Substituing Eq. 3.11 in 3.7, we get the dynamic equation for momentum as:
The equation for $Dq(t)$ can also be written in terms of the Hamiltonian as shown below:
$\partial_2 \widetilde{L}$ can be computed using the chain rule as:
Eq. 3.14 now reduces to: $\partial_2 H (t, q, \mathscr{V}(t, q, p)) = \mathscr{V}(t, q, p) + \cancel{p\partial_2 \mathscr{V}(t, q, p)}  \cancel{p\partial_2 \mathscr{V}(t, q, p)} = \mathscr{V}(t, q, p)$. This can be substituted in Eq. 3.8 to get:
Equations 3.13 and 3.17 are called Hamilton’s equations.
The first equation in 3.18 is restating the relation between velocity and momenta in terms of the Hamiltonian and applies for all paths regardless of whether they are realizable. The second equation only applies for realizable paths. The Hamiltonian has the same value as the energy function $\mathscr{E}$ from Chapter 1. The only difference is that that the velocities are expressed in terms of time, coordinates, and momenta using $\mathscr{V}$:
Illustration using free particle
The Lagrangian for the motion of a freeparticle of mass $m$ is:
To compute the Hamiltonian, we first ocmpute the momenta as $p = \partial_2 L; p_x = mv_x; p_y = mv_y$. Solving for velocities, we get, $v_x = p_x/m, v_y = p_y/m$ (This is the definition of $\mathscr{V}$). The Hamiltonian is $H = pv  L(t,q,v)$ with $v$ expressed in terms of $(t, q, p)$.
This is the total energy $T + V$ expressed in terms of the momenta. Hamilton’s equations for $Dq(t)$ are:
The Hamilton’s equations for the momenta are:
Hamiltonian State
Given a coordinate path $q$ and a Lagrangian $L$, the corresponding momentum path $p$ is given by Eq. 3.2. This can also be represented in terms of the Hamiltonian as was shown in the section above. The expression for momntum is valid whether or not the path is realizable, i.e., $p = \partial_2 L(t, q, v)$. In the Lagrangian formulation, $(t, q, v)$ represents the state of the path at a given moment and Lagrange’s equations describe a unique path emnating from this state. Similarly, $(t, q, p)$ represents the starte of a path in the Hamiltonian formulation and Hamilton’s equations describe a path emnating from this state. The two formulations are equivalent and creates the same path for the a given initial state.
When converting Lagrange equations into first order ODEs (prior to integration), we need to invert $ \partial_2 \partial_2 L$. While Hamilton’s equations are already first order ODEs, their construction involves an inversion in the form of the function $\mathscr{V}$. A system that is noninvertible in the Lagrangian formulation remains so in the Hamiltonian formulation as well.
For any given path, $q$, the Lagrangian and Hamiltonian state paths can be deduced from it. For the Lagrangian formulation, the state path is given by:
The construction of the Hamiltonian path requires the definition of a Lagrangian. The Hamiltonian path is given by:
The Hamiltonian state path is not unique for a given path as it is dependent on the Lagrangian that we choose when formulating it. There is no unique choice for the Lagrangian and hence there is no unique Hamiltonian state path for a given path.
The $2n$dimensional space whose elements are labeled by the n generalized coordinates $q^i$ and the $n$ generalized momenta $p_i$ is called the phase space. The components of the generalized coordinates and momenta are collectively called the phasespace components. The dynamical state of the system is completely specified by the phasespace state tuple $(t, q, p)$, given a Lagrangian or Hamiltonian to provide the map between velocities and momenta.
Computing Hamilton’s Equations
;; Implementation of Hamilton's Equations
(defn qp>Hstatepath [q p]
(fn [t]
(up t (q t) (p t))))
(defn myHamiltonian>statederivative [Hamiltonian]
(fn [Hstate]
(up 1
(((partial 2) Hamiltonian) Hstate)
( (((partial 1) Hamiltonian) Hstate)))))
(defn myHamiltonequations [Hamiltonian]
(fn [q p]
(let [statepath (qp>Hstatepath q p)]
( (D statepath)
(compose (myHamiltonian>statederivative Hamiltonian)
statepath)))))
#'user/myHamiltonequations
;; Free particle Hamtiltonian
(defn Hrectangular [m V]
(fn [state]
(let [q (coordinate state)
p (momentum state)]
(+ (/ (square p) (* 2 m))
(V (ref q 0) (ref q 1))))))
(rendermd (let [V (literalfunction 'V (> (X Real Real) Real))
q (up (literalfunction 'x)
(literalfunction 'y))
p (down (literalfunction 'p_x)
(literalfunction 'p_y))]
(((Hamiltonequations (Hrectangular 'm V)) q p) 't)))
The zero in the first element of the structure of Hamilton’s equation residuals is just the tautology that time advances uniformly: the time function is just the identity, so its derivative is one and the residual is zero. The equations in the second element of the structure relate the coordinate paths and the momentum paths. The equations in the third element give the rate of change of the momenta in terms of the applied forces.