The magnetic analogue of the inverted pendulum