Hamiltonian and non-conservative EM force I have to find the Hamiltonian of a charged particle in a uniform magnetic field; the potential vector is $ \vec {A}= B/2 (-y, x, 0)$.
I know that $$H=\sum_i p_i \dot q_i -L$$ where $p_i$ is conjugated momentum,  $\dot q_i$ is the velocity and $L$ is the Lagrangian.
The result that I should obtain is $$H=\frac{1}{2} m(\dot x^2+ \dot y^2)= \frac {1}{2m}(p_x^2+ p_y^2)+ \frac{1}{2}\omega^2 (x^2+y^2)+ \omega (p_x y- p_y x),$$ where $\omega= \frac{eB}{2mc}$.
I obtain this result only if I don't consider in the Hamiltonian the potential magnetic, and if I substitute only at the last step the values of velocities in function of conjugate momenta.
Considering that the magnetic field isn't a field of conservative forces, I ask you:
if I have a system in a non-conservative field, is it correct to not consider the potential of the non-conservative force when I'm writing the Hamiltonian? are my steps correct?
 A: 1) We start writing the Lagrangian
$$L=\frac{1}{2}mv^2+q\vec{v}\cdot\vec{A}=\frac{1}{2}m(v_x^2+v_y^2+v_z^2)+q\frac{B}{2}\left(-yv_x+xv_y \right)$$
2) We find the momenta
$$p_{x}=\frac{\partial L}{\partial v_{x}}=mv_{x}-\frac{qBy}{2}$$
$$p_{y}=\frac{\partial L}{\partial v_{y}}=mv_{y}+\frac{qBx}{2} $$
$$ p_{z}=\frac{\partial L}{\partial v_{z}}=mv_{z} $$
3) We express the Hamiltonian, performing a Legrende transformation between velocities and momenta as usual, and solving for the velocities as a function of the coordinates and momenta
$$ v_{x}=\frac{1}{m}\left(p_x+\frac{qBy}{2}\right) $$
$$ v_{y}=\frac{1}{m}\left( p_y-\frac{qBx}{2} \right) $$
$$ v_{z}=\frac{p_{z}}{m} $$
So
$$ H=\sum_{i} p_{i}v_{i}-L\bigg|_{v=v(p,q)}=\frac{p_{x}}{m}\left(p_{x}+\frac{qBy}{2}\right)+\frac{p_{y}}{m}\left(p_{y}-\frac{qBx}{2} \right)+\frac{p_z^2}{m}-\frac{1}{2m}\left[\left(p_{x}+\frac{qBy}{2}\right)^2+\left(p_{y}-\frac{qBx}{2} \right)^2+p_z^2\right]-q\frac{B}{2}\left[-\frac{y}{m}\left(p_{x}+\frac{qBy}{2}\right)+\frac{x}{m}\left(p_{y}-\frac{qBx}{2} \right) \right]$$
Expanding the squares
$$ H=\frac{p_x^2}{m}+\frac{p_xqBy}{2m}+\frac{p_y^2}{m}-\frac{p_yqBx}{2m}+\frac{p_z^2}{m} -\frac{1}{2m}\left(p_x^2+\frac{q^2B^2y^2}{4}+p_xqBy+p_y^2+\frac{q^2B^2x^2}{4}-p_yqBx+\frac{p_{z}^2}{m}\right)-\frac{qB}{2m}\left( -yp_x -\frac{qBy^2}{2}+xp_y-\frac{qBx^2}{2}\right)$$
Taking common factors
$$ H=\frac{p_x^2}{2m}+\frac{p_y^2}{2m}+\frac{p^2_{z}}{2m}+p_{x}\left( \frac{qBy}{2m}-\frac{qBy}{2m}+y\right)+p_y\left( -\frac{qBx}{2m}+\frac{qBx}{2m}-x\right) -\frac{q^2B^2y^2}{2·4m}-\frac{q^2B^2x^2}{2·4m}+\frac{qB^2y^2}{4m}+\frac{qB^2x^2}{4m}$$
Finally
$$H=\frac{p_x^2}{2m}+\frac{p_y^2}{2m}+\frac{p^2_{z}}{2m}+\frac{q^2B^2}{4m}(x^2+y^2)+\frac{qB}{2m}(p_xy-p_yx)$$
In the textbook they problably decided to obviate the $p_z$ because, given that $A_z=0$ the Lagrangian does not depende on $v_z$ so $p_z$ is a constant. 
A: The potential of a charged particle in an electromagnetic field is:
$$U(r,v,t)=q\phi -q\mathbf{v}\cdot A$$
Being $\phi$ the electric potential, $v$ the speed of the particle, $q$ the charge of the particle, and $A$ the vector potential of the magnetic field. Make sure su haven't made any mistakes calculating the lagrange equations (when you derive by $d/dt$, remember $\mathbf{v}$ is a function of time.
The Lagrangian will be:
$$L=\frac{1}{2}mv^2-q\phi +q\mathbf{v}\cdot A$$
Again, make sure you haven't made arithmetic mistakes.
