Calculation of work on a compressed spring