References: Shankar, R. (1994), Principles of Quantum Mechanics, Plenum Press. Section 2.5; Exercise 2.5.1.
The Lagrangian formulation of classical mechanics is one of two principal formalisms used to obtain equations of motion for a system. The other method is the Hamiltonian formalism. The main difference between the two methods is that the Lagrangian treats the generalized coordinates and their respective velocities as the independent variables, while in the Hamiltonian formalism, the coordinates and their associated momenta are the independent variables. The momentum corresponding to a coordinate is defined by
The Lagrangian is replaced by a function (where we’re using unsubscripted variables and to represent the sets of coordinates and momenta) with the property that
The method for transforming from the Lagrangian picture to the Hamiltonian picture is known as a Legendre transformation and works as follows. Suppose we start with a function (here, the can be any independent variables; we’re not considering coordinates explicitly yet) and we want to replace a subset with different variables , where
We now construct the function
We’re assuming that all the in the set can be written as functions of . In other words, when written out in full, 4 contains only the variables . We can now take the derivative:
where the second line follows from the definition 3.
To move from the Lagrangian formalism to the Hamiltonian formalism, the Lagrangian plays the role of , the generalized velocities are the variables to be replaced, and the Hamiltonian is the new function . That is, we have
There are a total of momenta and coordinates , for a total of independent coordinates. In 8, it is assumed that we can express all the velocities as functions of and . With these definitions, we can see by following through the derivation of 7 that 2 is satisfied.
We can get another equation by considering the derivative
In the third line, we used 1, in the fifth line we used the Euler-Lagrange equation
and in the last line, we used 1 again. We thus get Hamilton’s canonical equations:
[As an aside at this point, I was (and still am) unsure exactly what the term ‘canonical’ means in this, or in almost any other, context. Google is not very helpful in this respect, as it appears that nobody else really knows where the term came from. According to Wikepedia, the term ‘canonical’ is used to describe equations in several areas of mathematics, physics and even computer science, but ultimately the term appears to originate in religion, as in ‘canon law’, which is a system of laws created by the Catholic church. Presumably the term in physics is used to describe some equation or principle which is widely applicable and general. Any other thoughts are welcome in the comments.]
In cases where the potential energy doesn’t depend on velocity, the Lagrangian is , where is the kinetic energy. The Hamiltonian (as you’ve probably guessed) can be interpreted as the total energy of such a system, as we can see as follows.
Using rectangular coordinates, where each mass has a kinetic energy (this is true in one dimension; to extend to 3 dimensions, we write and the same argument follows). Thus the momentum is
Thus the first term in 8 is
and the Hamiltonian is
Now consider a more general kinetic energy defined as
That is, is a matrix that depends on the positions of the various masses. We have
The first term in 8 now becomes
where the last line follows because the RHS of the first line is symmetric under the exchange of and .