The Hamiltonian of a conservative system is the Legendre transform of its Lagrangian :
are the generalized coordinates, are the conjugate momenta and is a vector field that finds the velocities from . In mechanical systems, it coincides with the total energy:
where is the kinetic energy and is the potential energy. The Hamiltonian changes in the opposite sense as the Lagrangian:
The Hamiltonian is used in the Hamilton equations of the system to find its trajectory.
Examples#
> for some potential energy $V$. The Lagrangian is $L=T-V$. We want to show that the Hamiltonian is instead $H=T+V$. To do that, we'll express the kinetic energy in terms of the [[Linear momentum|momentum]] instead of velocity: > $$p_{x}=\frac{ \partial L }{ \partial \dot{x} } =m \dot{x},\quad p_{y}=\frac{ \partial L }{ \partial \dot{y} } =m \dot{y},\quad p_{z}=\frac{ \partial L }{ \partial \dot{z} } =m \dot{z}> The grand majority of Hamiltonians in physics have this form: $\mathbf{p}^{2}/2m$ plus a potential. This is because [[Cartesian coordinates]] are ubiquitous, as is considering point masses as objects, but it is a matter of "habit". This is not, *in general*, the shape of a Hamiltonian, as that depends on other factors such as the choice of coordinates. It just happens to be an overwhelmingly common specific case. > [!example] Harmonic oscillator > Using the same process of expressing kinetic energy in terms of momentum, the Hamiltonian of a (one-dimensional) [[harmonic oscillator]] is > $$H=\frac{p^{2}}{2m}+ \frac{1}{2}m\omega ^{2}q^{2} > where we used the [[electric potential]] $\phi$ and the [[magnetic vector potential]] $\mathbf{A}$. $e$ is the [[electric charge]] (since $q$ is already taken by position). We'll use the [[Lagrange equation]] to find the Hamiltonian through its definition. Firstly, > $$p_{i}=\frac{ \partial L }{ \partial \dot{q}_{i} } =m \dot{q}_{i}+eA_{i},\quad \dot{q}_{i}=\frac{p_{i}}{m}- \frac{e}{m}A_{i}Hence
and using the Hamiltonian definition
H(p,q)&=\mathbf{p}\cdot \dot{\mathbf{q}}-L|_{\dot{\mathbf{q}}=\frac{p_{i}}{m}- \frac{e}{m}A_{i}} \\ &=\frac{\mathbf{p}^{2}}{m}- \frac{e}{m}\mathbf{A}\cdot \mathbf{p}- \frac{m}{2} \frac{(\mathbf{p}-e\mathbf{A})^{2}}{m^{2}}- \frac{e}{m}(\mathbf{p}-e\mathbf{A})\cdot \mathbf{A}+e\phi \\ &=\frac{(\mathbf{p}-e\mathbf{A})^{2}}{m}- \frac{(\mathbf{p}-e\mathbf{A})^{2}}{2m}+e\phi \\ &=\frac{(\mathbf{p}-e\mathbf{A})^{2}}{2m}+e\phi \end{align}