The Hamiltonian for a simple harmonic oscillator is
$$H(p,q)=\frac{p^2}{2m}+\frac{k}{2}q^2$$
Then a possible Lagrangian corresponding to $H$ can be
$L=\frac{1}{2}m\dot{q}^2-\frac{k}{2}q^2$
$L=\frac{1}{2}m\dot{q}^2-\frac{k}{2}(q^2+3q^2\dot{q})$
$L=\frac{1}{2}m\dot{q}^2+\frac{k}{2}q^2$
$L=\frac{1}{2}m\dot{q}^2+\frac{k}{2}(q^2+3q^2\dot{q})$
We know by Legendre transformation that
$$H = \frac{\partial L}{\partial \dot{q}}\dot{q}-L=p\dot{q}-L$$
hence
$$L=p\dot{q}-H$$
Now since $H$ is given, by Hamilton movement equation we get
$$\dot{q}=\frac{\partial H}{\partial p}=\frac{p}{m}$$
Substituting $p = m\dot{q}$ in $L=p\dot{q}-H$ we get the expression as in $(1)$. But this only determines one Lagrangian uniquely whereas another possible Lagrangian is given to be $(2)$. How to prove $(2)$ is also another Lagrangian for the given $H$? Any help will be appreciated.
The second Lagrangian is not equivalent to the given Hamiltonian. Let $$L=\frac{1}{2}m\dot{q}^2-\frac{k}{2}q^2-\frac{3}{2}kq^2\dot{q}$$ Then the momentum is $$p=\frac{\partial L}{\partial \dot{q}}=m\dot{q}-\frac{3}{2}kq^2$$ Which means that the Hamiltonian is \begin{align} H &=p \dot{q}-L\\ &=m\dot{q}^2-\frac{3}{2}kq^2\dot{q}-\frac{1}{2}m\dot{q}^2+\frac{1}{2}kq^2+\frac{3}{2}kq^2 \dot{q}\\ &=\frac{1}{2}m\dot{q}^2+\frac{1}{2}kq^2 \end{align} And clearly: $$\frac{p^2}{2m}\neq \frac{1}{2}m\dot{q}^2$$