Work done by a variable force

A spring is a good example of a one-dimensional system where the force varies with position. In general, in one-dimension, the work done by a variable force F(x) is given by:

W = F(x) dx

Work is the area under the force vs. distance graph.