Hello! Welcome back to our journey through analytical mechanics.
In our previous lesson, we discovered the profound connection between symmetries and conservation laws through Noether's theorem. We saw that the Lagrangian formalism, expressed in terms of generalized coordinates and velocities , elegantly reveals these fundamental principles.
Today, we transition to a new, equally powerful framework: Hamiltonian mechanics. This formalism shifts our perspective from the configuration space of to a new space called phase space, which is described by generalized coordinates and their corresponding generalized momenta . This change is not merely cosmetic; it provides a deeper insight into the structure of dynamics, yields a set of first-order differential equations that are often easier to solve and analyze, and forms the essential bridge to advanced topics like statistical mechanics and quantum mechanics.
Our main goal in this lesson is to learn the mathematical procedure for moving from the Lagrangian to the Hamiltonian. This procedure is called the Legendre transformation, and by performing it, we will derive the fundamental equations of Hamiltonian dynamics: Hamilton's canonical equations.
1. The Legendre Transformation: The Mathematical Tool
At its heart, a Legendre transformation is a systematic way to change the independent variable of a function. Instead of describing a function by its value at each point , we can describe it by the slope of its tangent line, , at each point. The Legendre transform, , is the new function that contains all the original information, but expressed in terms of the slope .
The transformation is defined by the relationship between the original function and the y-intercept of its tangent lines.

To formalize this and see its properties, let's watch a detailed explanation.
Legendre Transformation | Get Hamiltonian from Lagrangian | Spring Mass, Harmonic Oscillator, Lect 2
To properly understand the mathematical machinery for switching from the Lagrangian to the Hamiltonian, we'll start with the Legendre Transformation as a general mathematical concept. This video by Dr. Shane Ross from Virginia Tech provides an excellent, rigorous introduction.
Watch from 03:26 to 13:46. Focus on how a new function g(v) is constructed from an old function f(u) by changing the independent variable from u to v = ∂f/∂u. Pay close attention to the general definition g = u⋅v - f and the 'involutive' property, which means that applying the transformation twice returns the original function.
A key condition for the Legendre transformation to be well-defined is that the relationship between the old variable and the new one (e.g., between and ) must be invertible. For a function , this corresponds to the function being either strictly convex or strictly concave, ensuring that each slope corresponds to a unique point .
2. From the Lagrangian to the Hamiltonian
Now, let's apply this mathematical tool to our physical system. The Lagrangian, , is a function of generalized coordinates and velocities: . Our goal is to create a new function, the Hamiltonian , that depends on coordinates and momenta: .
This is a perfect scenario for a Legendre transformation. We will transform the Lagrangian with respect to the generalized velocities .
- The original function is the Lagrangian: .
- The variables we transform are the generalized velocities . These are the "active" variables.
- The generalized coordinates and time are held constant during the transformation. These are the "passive" variables.
- The new variables are the generalized momenta , defined as the partial derivatives of the Lagrangian with respect to the active variables:
- The new function is the Hamiltonian , which is the Legendre transform of :
Let's see how this mapping works in detail.
Legendre Transformation | Get Hamiltonian from Lagrangian | Spring Mass, Harmonic Oscillator, Lect 2
Continuing with Dr. Ross's video, we'll see how the general transformation is applied directly to the Lagrangian.
Watch from 13:46 to 22:32. This segment first explains the concept of 'passive' variables, then maps the general Legendre transform directly onto the Lagrangian. The key results are the definition of the generalized momentum, pᵢ = ∂L/∂q̇ᵢ, and the definition of the Hamiltonian function itself: H = Σ pᵢq̇ᵢ - L.
So, the Hamiltonian is formally defined as:
A crucial and often tricky step follows this definition. The final expression for the Hamiltonian must be a function of only , and . To achieve this, you must first calculate , and then algebraically solve these equations to express each in terms of the and . These expressions for are then substituted back into the definition of .
This is a common source of error. The following resource highlights why this step is so critical.
A common pitfall in deriving Hamiltonian from Lagrangian mechanics
The following short article clarifies a common pitfall in this derivation. It's essential to understand that once the Hamiltonian is constructed, it lives in phase space, where q and p are the independent variables.
Read the sections 'Legendre transformation', 'The 'pitfall'', and 'The fix'. The key takeaway is that when you take partial derivatives of H, you must treat q and p as the independent variables. You cannot use relations like the Euler-Lagrange equation before differentiating H, because H is a function on a different space than L.
Test your understanding!
A particle of mass is subject to a potential . Its Lagrangian is . Perform the first two steps of finding the Hamiltonian:
- Calculate the generalized momentum .
- Invert the relation to find as a function of .
- Write down the Hamiltonian .
Show answer
-
Find momentum :
-
Invert for :
-
Construct the Hamiltonian :
Notice that for this standard system, the Hamiltonian is simply the kinetic energy () plus the potential energy (), which is the total energy of the system.
3. Deriving Hamilton's Equations of Motion
Now that we have the Hamiltonian , how do we find the equations of motion? We need to derive Hamilton's canonical equations. The derivation is a beautiful piece of calculus that flows from the definition of .
Let's start by taking the total differential of the Hamiltonian, . (For simplicity, we'll write it for one degree of freedom, but it generalizes with a sum over the index ).
This simply follows from the chain rule for a function of three variables.
Next, we take the differential of the definition of the Hamiltonian, :
We know from the chain rule that . Substituting this in:
Now we use two key relationships from the Lagrangian formalism:
- The definition of generalized momentum:
- The Euler-Lagrange equation:
Substituting these into our expression for :
The terms cancel out, leaving a remarkably clean expression:
Now we compare our two expressions for . By matching the coefficients of the independent differentials , , and , we arrive at Hamilton's equations:
These are Hamilton's canonical equations of motion. Notice their beautiful symmetry (apart from the minus sign). Instead of one second-order differential equation from Lagrange, we now have two first-order differential equations.
For a more guided walk-through of this derivation, we can use our primary resources.
Legendre Transformation | Get Hamiltonian from Lagrangian | Spring Mass, Harmonic Oscillator, Lect 2
With the Hamiltonian defined, we can now derive its corresponding equations of motion. Dr. Ross provides a clean derivation that flows directly from the properties of the Legendre transformation.
Watch from 34:33 to 42:37. Follow how the two main Hamilton's equations emerge by using the properties of the forward and reverse Legendre transforms and combining them with the Euler-Lagrange equation. Notice the elegant symmetry of the final equations.
Legendre transforms and the Hamiltonian Formalism
For a formal, text-based derivation that you can review at your own pace, this handout from the University of Chicago is excellent. It presents the derivation from a slightly different starting point but arrives at the same crucial result.
Read the section titled 'Transforming Hamilton’s principle to eliminate velocity constraint', starting from the subsection 'Imposing the constraint' on page 3. Follow the argument through to the end of page 4, where Hamilton's equations are summarized. This text rigorously defines H as the Legendre transform and then derives the equations of motion.
4. Worked Example: The Simple Harmonic Oscillator
Let's solidify this entire process with a concrete example: the one-dimensional simple harmonic oscillator.
The Lagrangian is .
-
Find the momentum :
-
Invert to find :
-
Construct the Hamiltonian :
As we found earlier, is the total energy, . -
Write and solve Hamilton's equations:
We now have two coupled, first-order ODEs. The first tells us , which is just the definition of momentum. Differentiating it gives . Substituting the second equation () into this gives:
This is exactly the familiar second-order equation of motion for a simple harmonic oscillator we would get from Newton's second law or the Euler-Lagrange equation.
The following video segment walks through this exact example.
Legendre Transformation | Get Hamiltonian from Lagrangian | Spring Mass, Harmonic Oscillator, Lect 2
Let's watch the application of this entire procedure to the classic spring-mass system.
Watch from 45:12 to 53:18. Follow the step-by-step process: writing the Lagrangian, finding the momentum, constructing the Hamiltonian, and finally writing out Hamilton's canonical equations for the system.
Conclusion
In this lesson, we have built the foundation for an entirely new formulation of classical mechanics. We've seen that the Hamiltonian formalism provides a symmetric and powerful description of dynamics in phase space.
Key Takeaways:
- Hamiltonian mechanics describes a system in phase space using generalized coordinates and generalized momenta .
- The Hamiltonian is obtained from the Lagrangian via a Legendre transformation with respect to the generalized velocities .
- The definition is , where , and all must be eliminated in favor of .
- The dynamics of the system are governed by Hamilton's canonical equations, a set of first-order ODEs:
Preview of the Next Lesson:
We have successfully derived the machinery of the Hamiltonian formalism. In our next lesson, we will put it to use. We will focus on solving mechanics problems using the Hamiltonian formalism, applying these techniques to more complex systems and exploring the unique insights and advantages this powerful framework offers.