# Is the Hamiltonian conserved or not?

The question is the very last sentence at the end of this post. In this post, I'll first show that the Hamiltonian is conserved since it does not have explicit dependence on time and then show that the Hamiltonian is not conserved since when directly calculate, the derivative is found not to vanish. A bead is threaded on a friction-less vertical wire loop of radius $R$. The loop is spinning w.r.t. a fixed axis shown in the figure at a constant angular speed $\omega$. The Lagrangian is given by

$$L=\frac{1}{2}\dot\theta^2R^2+\frac{1}{2}R^2\sin^2\theta\omega^2+gR(\cos\theta-1)$$, where $\theta$ is defined in the figure(the arrow near the character $\theta$ indicates the direction in which it increases).

The equation of motion:

$$\ddot\theta=\sin\theta\cos\theta\omega^2-\frac gR\sin\theta$$

Since the Hamiltonian is given by $H=\frac{1}{2}\dot\theta^2R^2+\frac{1}{2}R^2\sin^2\theta\omega^2-gR(\cos\theta-1)$, we see that there is no explicit dependence on time; therefore we expect that the Hamiltonian is conserved. However, when we directly compute the total derivative of the Hamiltonian, we can see that the derivative is not zero:$$\dot H=\dot \theta(\ddot \theta R^2+R^2\sin\theta\cos\theta{\omega}^2+gR\sin\theta)=2\dot\theta R^2\sin\theta\cos\theta{\omega}^2,$$ where we make use of the e.o.m. and substitute $\ddot\theta R^2$ for the corresponding terms.

Concern:Something is clearly missing here. I hope that some other people can help point out some mistake that I've made in the above reasoning.

1. The Hamiltonian $H(\theta,p_\theta)$ needs to be formulated in terms of the coordinate $\theta$ and its canonically conjugate momentum $p_\theta = \frac{\partial L}{\partial \dot{\theta}} = R^2 \dot\theta$. The correct expression for the Hamiltonian is \begin{align} H(\theta,p_\theta) & = p_\theta \dot{\theta}(\theta,p_\theta) - L(\theta,\dot{\theta}(\theta,p_\theta)) \\ & = \frac{p_\theta^2}{2R^2} - \frac{1}{2}R^2\sin^2(\theta)\omega^2 - gR\left(\cos(\theta)-1\right)\end{align} where you have to be careful with the signs (note the differing sign for the second term compared to yours). If you take the same expression with dependence on $\dot{\theta}$ instead of $p_\theta$, it is not the Hamiltonian, but merely some expression which is often the energy.
2. For general Hamiltonian systems with time-independent Hamiltonian on coordinates $q$ with momenta $p$ we have the following: Since the Hamiltonian is not explicitly time-dependent, its derivative vanishes upon use of the Hamiltonian equations of motion $$\dot{p} = -\frac{\partial H}{\partial q} \quad \land \quad \dot{q} = \frac{\partial H}{\partial p}$$ for a Hamiltonian trajectory $(q(t),p(t))$ since plugging this into $$\frac{\mathrm{d}H}{\mathrm{d}t} = \frac{\partial H}{\partial p}\dot{p}+\frac{\partial H}{\partial q}\dot{q}$$ gives zero regardless of the actual form of the equations of motion. If you get a different result, you simply made an error in your calculations somewhere, it cannot happen that the Hamiltonian is not constant along a trajectory that is a solution of the equations of motion.