Recall that we obtained the equations of motion by requiring that the action, \(S\), is stationary under variations of the \(q_i\):
The Euler-Lagrange equations of motion were obtained by requiring that the variations of the \(q_i\) were zero at the end points. We can write the variation of \(S\) in terms of the Hamiltonian:
In the Lagrangian formalism, we found that variations of the action with respect to the \(q_i\) led to the equations of motion. The \(\dot q_i\) did not vary independently from the \(q_i\), since:
In the Hamiltonian formalism, we must treat the \(q_i\) and \(p_i\) on equal footing, that is, we must allow them to be varied independently. We know from the properties of the Legendre transformation that variations of the \(p_i\) do not affect the Lagrangian, and hence the variation of the action will not be affected by independently varying the \(p_i\):
We can write:
The first term, being a total time derivative, will not contribute to the variation of the action (since it just adds a constant), so it can be dropped:
For the variation of \(S\) to be zero when \(q_i\) and \(p_i\) are varied independently, then the terms in front of the \(\delta q_i\) and \(\delta p_i\) must always be zero, which is precisely the canonical equations.