Hamiltonian Mechanics

In Lagrangian mechanics, just like in Newtonian mechanics, work is done in coordinate space, whereas in Hamiltonian mechanics, phase space is used. In phase space, the total energy of a system is called the Hamiltonian, which can be calculated by a type of transformation of the Lagrangian. The Hamiltonian (energy function) is

$$ H(q_i,p_i,t) = \sum_i p_i \dot{q}_i - L(q_i,p_i,t) $$

which is a kind of Legendre transformation of the Lagrangian \( L \). Here, \( p_i = \partial L / \partial \dot{q}_i \) is the momentum, and \( \dot{q}_i \) is the first time derivative of the generalized coordinate \( q_i \), i.e., the velocity. In Lagrangian mechanics, coordinates and velocities are used, whereas in Hamiltonian mechanics, momentum and velocity are used.

So, for a spring oscillating along the x-axis, the Hamiltonian will be

$$ H = p\dot{x} - L = p\dot{x} - \frac{1}{2}m\dot{x}^2 + \frac{1}{2} kx^2 $$

which can be simplified further by substituting momentum in place of velocity. Since \( p = \partial L / \partial \dot{x} = m\dot{x} \), then \( \dot{x} = p/m \), and substituting in the above equation gives

$$ H = \frac{p^2}{2m} + \frac{1}{2} kx^2 $$

which represents the total energy of the spring-mass system, i.e., the sum of kinetic and potential energy. If the Lagrangian is the difference between the two types of energy, the Hamiltonian is the sum of those two types of energy.

Integrating the Lagrangian with respect to time gives the action. However, in Hamiltonian mechanics, the action is often calculated as the integral of momentum with respect to coordinate. In this case, the action is

$$ S = \int p dq $$

which, for a system with periodic motion like the spring-mass system, becomes a closed integral—\( \oint p dq \)—and in systems like plasma, where there are many periodic motions, the action variable \( J \) and the angle variable \( \theta \) are used together.