The Hamiltonian, $\mathcal H$, is quantity related to $\mathcal L$ defined as

$$ \mathcal H=\sum_ip_i\dot q_i-\mathcal L $$

Where $p_i$ is the generalized momentum for the coordinate $q_i$ also called the momentum conjugate to $q_i$ or the canonical momentum. It is defined in Lagrangian mechanics as

$$ p_i=\frac{\partial\mathcal L}{\partial \dot q_i} $$

Where does this quantity come from, what’s the motivation? → The Hamiltonian is motivated by how the Lagrangian changes with time and most importantly it is conserved for time invariant Lagrangians. This is covered in Symmetry and Conservation Laws.

$\mathcal H$ and Total Energy

A special property presents itself when we consider generalized coordinates, $\vec q$, that are only functions of our original coordinates, $\vec r$, (like Cartesian coordinates for our system of particles). These coordinates are called natural coordinates. It turns out when our coordinates are natural the Hamiltonian is simply the total energy of our system, that is $\mathcal H=T+U$.

Natural Coordinates:

$$ q_i=q_i(r_1,r_2,\dots,r_n) $$

Unnatural Coordinates:

$$ q_i=q_i(r_1,r_2,\dots,r_n,t) $$

Coordinates

The Lagrangian is a function of $n$ generalized coordinates $q_1,q_2,\dots,q_n$ and their $n$ time derivatives (or generalized velocities) $\dot q_1,\dot q_2,\dots,\dot q_n$ and time, $t$

$$ \mathcal L=\mathcal L(q_i;\dot q_i,t)=T-U $$

The $n$ coordinates define a configuration space of the system and the $2n$ coordinates define a point in state space (both position and velocity) that completely determine the unique state of the system. If we give a set of $2n$ initial conditions at a chosen time $t_0$ we can determine a unique solution of the $n$ second-order differential Lagrangian equations of motion

$$ \frac{\partial\mathcal L}{\partial q_i}=\frac{d}{dt}\frac{\partial\mathcal L}{\partial \dot q_i}~~~~[i=1,\dots,n] $$