One (and the simplest) way of getting to equations of motion in Hamiltonian mechanics is through calculus of variation. It is illuminating enough to consider 1-D senario at the beggining, since the higher dimensional case merely needs adding summation. First, we know that by definition:

H=pq˙L \mathcal{H} = p\dot{q} - \mathcal{L}

where qq is generalized coordinates and pp is the corresponding generalized momentum. Of course, L\mathcal{L} is our old friend Lagrangian L(q,q˙,t)\mathcal{L}(q,\dot{q},t) .

Then, if we consider imposing variation on qq and pp so that, if we denote the true path of them as:

{q(t)p(t) \begin{cases} q(t)\\ p(t) \end{cases}

We can impose also a variation on them:

{qα(t)=q(t)+γα(t)pα(t)=p(t)+γα(t) \begin{cases} q_\alpha(t) = q(t) + \gamma_\alpha(t) \\ p_\alpha(t) = p(t) + \gamma^\prime_\alpha(t) \end{cases}

Here, we can thing of gammagamma's as the difference between true path and altered path at any given time. If our system begins at t1t_1 and ends at t2t_2, we naturally have:

γα(t1)=γα(t2)=0 \gamma_\alpha(t_1) = \gamma_\alpha(t_2) = 0

Because the two ends are known to us. Now, by definition of action, we see that the variation of action is:

δS=dααt1t2dtL=dααt1t2dt[pαq˙αH] \delta \mathcal{S} = d\alpha \frac{\partial}{\partial \alpha}\int_{t_1}^{t_2} dt \mathcal{L} = d\alpha \frac{\partial}{\partial \alpha}\int_{t_1}^{t_2} dt \left[ p_\alpha\dot{q}_\alpha - \mathcal{H} \right]

Now we want to move the partial derivative into the integration because the variation we impose is not related to time, also bear in mind that the partial derivative would hit term and we will be using chain rule here:

{δS=dααt1t2dt[pαq˙αH(p,p˙)]=dαdt[pααq˙α+pαq˙ααHqαqααHpαpαα] \begin{cases} \delta \mathcal{S} &=d\alpha \frac{\partial}{\partial \alpha}\int_{t_1}^{t_2} dt \left[ p_\alpha\dot{q}_\alpha - \mathcal{H}(p,\dot{p}) \right] \\ &=d\alpha\int dt \left[ \frac{\partial p_\alpha}{\partial \alpha}\dot{q}_\alpha + p_\alpha\frac{\partial \dot{q}_\alpha}{\partial \alpha} - \frac{\partial \mathcal{H} }{\partial q_\alpha}\frac{\partial q_\alpha}{\partial \alpha}- \frac{\partial \mathcal{H}}{\partial p_\alpha}\frac{\partial p_\alpha}{\partial \alpha} \right] \end{cases}

Then if we apply inverse by parts to the second term in the bracket, we see that:

t1t2dtpαq˙αα=[pαqαα]t1t2t1t2dtp˙αqαα=0t1t2dtp˙αqαα \int_{t_1}^{t_2}dt p_\alpha\frac{\partial \dot{q}_\alpha}{\partial \alpha} = \left[ p_\alpha\frac{\partial q_\alpha}{\partial \alpha}\right]_{t_1}^{t_2}- \int_{t_1}^{t_2}dt\dot{p}_\alpha\frac{\partial q_\alpha}{\partial \alpha}=0-\int_{t_1}^{t_2}dt\dot{p}_\alpha\frac{\partial q_\alpha}{\partial \alpha}

The term evaluated to zero because we know the ends have no variation.

Plug this result back into the original integration we see that:

0=δS=dαdt[pααq˙αp˙αqααHqαqααHpαpαα] 0=\delta\mathcal{S}=d\alpha\int dt \left[ \frac{\partial p_\alpha}{\partial \alpha}\dot{q}_\alpha -\dot{p}_\alpha\frac{\partial q_\alpha}{\partial \alpha} - \frac{\partial \mathcal{H} }{\partial q_\alpha}\frac{\partial q_\alpha}{\partial \alpha}- \frac{\partial \mathcal{H}}{\partial p_\alpha}\frac{\partial p_\alpha}{\partial \alpha} \right]

If we re-group terms with the same partial derivative together, and argue that since those derivative are not necessariley zero, we must have:

{q˙=Hpp˙=Hq \begin{cases} \dot{q} = \frac{\partial \mathcal{H}}{\partial p}\\ \dot{p} = - \frac{\partial \mathcal{H}}{\partial q} \end{cases}

Which is what we wanted.