(U = mgy) with (y = -L\cos\theta) gives (U = -mgL\cos\theta).
A mass (m) attached to a massless rod of length (L). The rod pivots without friction. Use the angle (\theta) from the vertical.
For deeper study, the following resources provide extensive problem sets and solutions: