Khinchin’s book on statistical mechanics (ISBN=0486601471) introduced me to Hamiltonians.
The simple idea there is that H is merely the total energy of the system where H is taken to be some function of the **dynamic coordinates** p_{i} and q_{i} for 1≤i≤s.
This idea is evidently in stark contrast to the historical origin of Hamiltonians which is by way of Lagrangians, in terms of which
Hamiltonians are normally introduced.
We require:

ṗ_{i} = ∂H/∂q_{i}
| q̇_{i} = −∂H/∂p_{i} |
| (1) |

These two equations provide simple means to compute the evolution of p_{i} and q_{i} as time passes.
So far we merely have a way to compute the evolution of p’s and q’s if we have a function H of them.
H determines the course of the dynamic variables.
Clarification?

I characterize p_{i} and q_{i} as positions and momenta respectively for the following but this formalism can be extended to many other physics problems by taking p_{i} and q_{i} to be other physical quantities so long as the two equations above hold.
(See conjugate coordinates.)

### simple oscillator

We consider a simple oscillator first.
A mass=m has one degree of freedom x and a spring imposes a force = −hx.
Kinetic energy = mx'^{2}/2.
When the mass is displaced to x the work against the spring (potential energy) is hx^{2}/2.
Using our conventional notions of energy and taking p_{1} = x/√h; q_{1} = x'/√m

we propose the following Hamiltonian:

H = ((K.E.) + (P.E.)) = ((mx'^{2}/2) + (hx^{2}/2))/2 = (hp_{1}^{2} + mq_{1}^{2})/2.
Note that if H is a serviceable Hamiltonion then so is bH where b is a constant; H and bH predict the same evolution of the dynamic variables but 2H evolves twice as fast as H.

We try ṗ_{1} = ∂H/∂q_{1} and q̇_{1} = −∂H/∂p_{1} with our proposed H.
ṗ_{1} = ∂H/∂q_{1} = mq_{1} and
q̇_{1} = −∂H/∂p_{1} = −hp_{1}.
These simple differential equations yield:

(p_{1}, q_{1}) = (a sin(√(h/m)t + b), a cos(√(h/m)t + b))

for some constants a and b.

Presumably the reader is not yet impressed of the magic of the Hamiltonian; but wait:

### compound pendulum

Lets take a compound pendulum
(too—better graphics):
Two masses, one beneath the other.
Inelastic links hinged at the top and at the middle mass each mass = 1
each link length = 1 g = 1.
| |

The angle of the upper link relative to the vertical is θ_{1} and of the lower link θ_{2}.
p_{i} = θ_{i}.
We will need the velocity of the lower weight to compute its kinteic energy.
The velocity of the upper weight is d(sin^{2} θ_{1},)/dt

H = (K.E.) + (P.E.) = (−2 cos(θ_{1}) − cos(θ_{2}))
+ (1/2 (θ_{1}^{2})