Hamiltonian from Lagrangian $L= \frac{m}{2}(\dot{r}^2+r^2\dot{\theta^2})+ \frac{k\cos(\theta)}{r^2}$ I'm doing the first exercises with the Lagrangians and Hamiltonians. 
Let:
$$L= \frac{m}{2}(\dot{r}^2+r^2\dot{\theta^2})+ \frac{k\cos(\theta)}{r^2}$$
$$p_1=m\dot{r}$$
$$p_2=mr^2\dot{\theta}$$
$$H=\frac{p^2}{2m}-\frac{k\cos(\theta)}{r^2}$$
I do not understand why the Hamiltonian is:
$$H=\frac{1}{2m}\left(p_1^2+\frac{p_2^2}{r^2}\right)-\frac{k\cos(\theta)}{r^2}$$
and not 
$$H=\frac{1}{2m}(p_1^2+ p_2^2)-\frac{k\cos(\theta)}{r^2}$$

The first term in the Lagrangian $L = T-V$ is the kinetic energy $T$, whereas the second term is minus the potential energy $V$. The corresponding Hamiltonian is $H = T+V$, i.e.
\begin{aligned}
H &= \frac{m}{2} \left({\dot r}^2 + r^2{\dot \theta}^2\right) - \frac{k\cos\theta}{r^2} \\
& = \frac{1}{2m} \left((m {\dot r})^2 + (m r {\dot \theta})^2\right) -\frac{k\cos\theta}{r^2} \\
& = \frac{1}{2m} \left({p_1}^2 + \frac{{p_2}^2}{r^2}\right) - \frac{k\cos\theta}{r^2} \, .
\end{aligned}
You may have made an algebra mistake replacing $(m r {\dot \theta})^2$ by ${p_2}^2$, which is wrong.
