Calculation of the potential energy of a capacitor