How can I derive this Hamiltonian? I have a Lagrangian $L$, a momentum $p$ and a Hamiltonian $H$:
$$L=\frac m 2(\dot z + A\omega\cos\omega t)^2 - \frac k 2 z^2$$
$$p=m\dot z + mA\omega\cos\omega t$$
$$H=p\dot z - L=\frac m 2 \dot z^2 - \frac m 2 (A\omega\cos\omega t)^2 - \frac k 2z^2$$
And I want to calculate $\frac {\partial H} {\partial z}$ and $\frac {\partial H} {\partial p}$. I understand from this question that I need to algebraically manipulate $H$ to express it in terms of $p$ and $z$. The answers there suggested trying to express $\dot z$ in terms of $z$ and $p$, and presumably I need to express $t$ in terms of $z$ and $p$ as well. But that seems like its going to lead into very nasty territory... first of all, I've got quadratics, so that's not an invertible function. Second of all, for $t$, if I have to use inverse trigonometric functions, then it'll only be valid over a particular range of the variable.
Could I get some pointers on how to tackle this calculation? Is inverting the various relations really the way to go?
 A: I believe you went wrong somewhere when determining the Hamiltonian. For example the $\frac{k}{2}z^2$ Term has opposite sign. Finding the Hamiltonian is a lot easier if you identify the $(\dot{z}+A\omega\cos\omega t)$ term as $\frac{p^2}{m^2}$. The only variable still in lagrangian form is then $\dot{z}$ which you can eliminate by rearranging the second relation.Your Hamiltonian will still depend on $t$, but that doesn't matter if you take partial derivatives.
A: You don't need to express $t$ in terms of $z$ and $p$, explicit time dependence is permissible in the Hamiltonian. (It would not even be possible without restoring to $\dot z$.) In the other question it was not mentioned because it was not needed, the Lagrangian was time-symmetric and consequently so was the Hamiltonian. This is very often the case so many people would omit $t$ as a parameter completely.
Thus the next step in your calculation would be simply inverting
$$p(z,\dot z,t) = m\dot z + mA\omega\cos\omega t$$
to
$$\dot z(z,p,t) = \frac{p - m A \omega \cos \omega t}m = \frac pm - A\omega\cos\omega t,$$
followed by
$$\begin{aligned}
H(z,p,t)\, &= p\dot z - L =  p\dot z(z,p,t) - L(z,\dot z(z,p,t),t) =\\
&= \frac{p^2}m - pA\omega\cos\omega t - \left[ \frac m2\left(\frac pm\right)^2 - \frac k2 z^2\right] =\\
&= \frac{p^2}{2m} - pA\omega\cos\omega t + \frac k2 z^2.
\end{aligned}$$
You can check this is correct by comparing the equations of motion following from Hamiltonian formalism
$$\begin{aligned}
\dot z&\, = \frac{\partial H}{\partial p} = \frac pm - A\omega\cos\omega t,\\
\dot p&\, = -kz\\
\Rightarrow& \quad \ddot z = -\frac{kz}m + A\omega^2 \sin^2(\omega t),
\end{aligned}$$
with those obtained from the Lagrangian directly,
$$\frac{\mathrm{d}}{\mathrm{d}t} \left(\frac{\partial L}{\partial\dot z}\right) - \frac{\partial L}{\partial z} = 0$$
$$\begin{aligned}
\frac{\mathrm{d}}{\mathrm{d}t} \left(m\dot z + mA\omega\cos\omega t\right) - (-kz) &\, = 0 \\
m\ddot z - mA\omega^2\sin^2(\omega t) + kz &\, = 0
\end{aligned}$$
