The hamiltonian for a free falling body is $$H = \dfrac{p^2}{2m} + mgy$$ and since we are using cartesian coordinates that do not depend on time and the potential only depends on the position, we know that $H=E$. For this hamiltonian, using the Hamilton's equations and initial conditions $y(0)=0$ and $p(0)=0$, we get the evolution in the phase space: $$y(t) = -\dfrac{1}{2}gt^2\quad p(t)=-mgt$$
Now, imagine the opposite problem: we don't know anything about the system and the potentials involved, but someone gives us the phase space evolution, $x(t)$ and $p(t)$, for the same initial conditions. Can we get the energy using the hamiltonian formalism?.
From the phase space evolution, we know that $\dot{y}=-gt = p/m$ and $\dot{p} = -mg$. Then $$ \dot{y}=\dfrac{\partial H}{\partial p} \ \Rightarrow\ H = \dfrac{p^2}{2m} + f(y,t) $$ $$ \dot{p} = -\dfrac{\partial H}{\partial y} = -\dfrac{\partial f}{\partial y} \ \Rightarrow\ f(y,t) = mgy + g(t) $$ Concluding that $$H = \dfrac{p^2}{2m} + mgy + g(t) $$
Apparently, we don't have enough information to determine the form of $g(t)$. Two questions came to my mind:
- Were the Hamilton's equations integrated correctly? This seems to work when I put $\dot{y}$ as a function of $p$, but woud it work expressing $\dot{y}$ in terms of other combinations of $y$, $p$ or $t$?. When is it mathematically correct to get rid of the time variable to integrate the equations?
- How can we know the expression for $g(t)$, and how can we know the relation of the found hamiltonian with the energy if we don't have any explicit information about the potentials?.
Extra example
If I don't get rid of the time at the beginning, then $$ \dot{y} = \dfrac{\partial H}{\partial p} = -gt \ \Rightarrow\ H = -gtp + f(y,t) \ \Rightarrow\ H = \dfrac{p^2}{m} + f(y,t) $$ We have lost the $1/2$ factor, and the equations of motions derivated from this hamiltonian won't be the same.
What is mathematically incorrect there?