As mentioned in the fine print, all of the methods so far for calculating work depend on the fact that the force doing the work is constant. After all, if the force doing the work is not constant, what value are you going to use in the calculation? Yet, many common situations involve non-constant forces, such as the force exerted to stretch a spring.
What to do? Depending on what you know about the force (and your mathematical sophistication), there are a few things to try that could give you, at the minimum, a decent approximation of the work done by the force...
Suppose a force is not constant as it does work, but you know (or can estimate) the average value of the force, Fave, over the distance, x, in which it does work. In this case, the work done by the force is:
Work = Favex - if the direction of Fave is in the direction of motion
Work = -Favex - if the direction of Fave is opposite the direction of motion
or, for the mathematically inclined:
Suppose that it takes a force of 40 Newtons to hold a spring when it is stretched 1 meter from its normal rest position. How much work was done in stretching the spring this distance?
The force required to hold the spring varies from 0 Newtons at its rest position to 40 Newtons at the 1 meter position. You might be tempted to guess that the average force that you exert as you stretch the spring would be 20 Newtons (the average of 0 Newtons and 40 Newtons). The work done to stretch the spring would be:
Work = Favex = (20 Newtons)(1 meter) = 20 Joules
This would be a good guess!