Calculation of work done and potential energy