The electromagnetic potential are

$\displaystyle \vec{E} = - \nabla \phi - \frac{\partial}{\partial t}\vec{A}$

$\displaystyle \vec{B} = \nabla \times \vec{A}$

The Lagrange’s equation is

$\displaystyle \frac{d}{dt}\left( \frac{\partial L}{\partial \dot{q_i}}\right) - \frac{\partial L}{\partial q_i} = 0$

By setting

$\displaystyle L = \frac{1}{2} m v^2 - q\phi + q\vec{v} \cdot \vec{A}$

we can recover the Lorentz force,

$\displaystyle \vec{F} = q( \vec{E} + \vec{v} \times \vec{B} )$

Then, the hamiltonian is

$\displaystyle H = \sum_{i=1}^{3}p_i \dot{q_i} - L$

First, we momentum is

$\displaystyle \vec{p} = \frac{\partial L}{\partial \dot{\vec{r}}} = m\vec{v} + q \vec{A}$

$\displaystyle \frac{\partial L }{\partial \vec{r}} = \nabla L = -q \nabla \phi + q \nabla (\vec{v} \cdot \vec{A})$

Using the identity,

$\nabla (\vec{v} \cdot \vec{A}) = \vec{v} \times (\nabla \times \vec{A}) + \vec{A} \times (\nabla \times \vec{v}) + ( \vec{v} \cdot \nabla) \vec{A} + (\vec{A} \cdot \nabla )\vec{v}$

the terms with velocity are zero,

$(\nabla \times \vec{v}) = 0$

$(\vec{A} \cdot \nabla )\vec{v} = 0$

The term $( \vec{v} \cdot \nabla) \vec{A}$ need special treatment, since the electric field depends on partial time derivative of the vector potential, but the time derivative in the Lagrange’s equation is total time derivative.

$\displaystyle \frac{d}{dt} \vec{A} = \frac{\partial}{\partial t} \vec{A} + (\vec{v}\cdot \nabla) \vec{A}$

Thus,

$\displaystyle \nabla (\vec{v} \cdot \vec{A}) = \vec{v} \times (\nabla \times \vec{A}) + (\vec{v}\cdot \nabla) \vec{A} = \vec{v} \times (\nabla \times \vec{A}) + \frac{d}{dt} \vec{A} - \frac{\partial}{\partial t} \vec{A}$

The Lagrange’s equation,

$\displaystyle \frac{d}{dt}\left( \frac{\partial L}{\partial \dot{q_i}}\right) - \frac{\partial L}{\partial q_i} = m\dot{\vec{v}} + q \frac{d \vec{A}}{dt} + q \nabla \phi - q \nabla (\vec{v} \cdot \vec{A}) = 0$

Notice that $\vec{F} = m \dot{\vec{v}}$, then,

$\displaystyle \vec{F} = q( -\nabla \phi - \frac{\partial \vec{A}}{\partial t} + \vec{v} \times (\nabla \times \vec{A}) ) = q (\vec{E} + \vec{v} \times \vec{B})$

we recovered the Lorentz force.

$\displaystyle H = \sum_{i=1}^{3} p_i \dot{q_i} - L = mv^2 + q\vec{v}\cdot \vec{A} - \frac{1}{2} mv^2 + q\phi - q \vec{v} \cdot \vec{A} = \frac{1}{2} m \vec{v} \cdot \vec{v}+ q \phi$

since $\vec{v} = \frac{1}{m}(\vec{p} - q \vec{A} )$

$\displaystyle H = \frac{1}{2m}(\vec{p} - q\vec{A})^2 +q \phi$