Work by Springs

How much work is done by a spring when its end is moved from one position xi to another xf? Because the force is not constant, the work equation becomes:

W = ò F dx, with xi and xf the limits on the integral. Substituting -kx for F gives:

W = - ò kx dx, which works out to:

W = - ½ kx2 | with lower limit xi and upper limit xf

W = ½ kxi2 - ½ kxf2