Variable Force
It is a force whose magnitude is a function of position /displacement, i.e., \(F=f(x)\)
Work Done by Variable Force
 Suppose a force is acting on a body which is not constant but depends upon displacement.
 Work done by constant force is expressed as the product of force and displacement, only when force is constant.
\(W=F_{\text {constant}}×\text {Displacement}\)
 Thus, this expression can't be used to calculate work done by variable force.
 To solve this problem, the displacement is divided into very small parts.
 Since, the parts are so small, so we can assume that force during that part of displacement is constant.
 So, summing up the work done by these small displacements, gives the total work.
 Consider an example, a force \(F=k\,x\) is acting on a body where \(x\) is the distance from origin.
 As we move from A to B, the value of the force changes (increases).
 So, to calculate the work done by force from A to B, we can't take any value of force.
 So, work done by small element \(dx\) is
\(W=\vec F \cdot d\vec x\)
 Since the displacement and force are opposite, making an angle of 180°
so, \(W=F \,dx\,×cos\,180°\)
\(W= F \cdot dx\)
 So, the total work done from all parts of displacement from A to B
\(W_ T=\sum\limits _{\text {From 1st element}}^{\text {To last element}}F.dx\)
 This can also be calculated by using calculus.
\(W_ T=\int\limits_{\text {From 1st element}}^{\text {To last element}}\;F.dx\)
 In short, we can say that to find total work done by variable force following steps can be followed:
 Write \(F\) as a function of \(x\).
 Write \(x\)as \(dx\).
 Integrate the force from first element \((x_i)\) to final element \((x_f)\).
 Spring follows Hook's law which states that force experienced by spring is directly proportional to the extension or compression from its natural length.
\(F\propto x\)
 Spring will exert a force \(K_x\) where \(K\) is a constant and \(x\) is the distance from natural length, as shown in figure.
 The direction of spring force is always along its natural length.
 So, when the spring is stretched or compressed, the force of spring continuously increases as \(x\) increases.
 For the calculation of work done by spring force, integration is used, as force is variable.
\(W=\displaystyle\int\limits_{x_i}^{x_f}Kx\;dx=\dfrac {1}{2}K\Big[ x_f^2x_i^2\Big]\)
Work done \(=\dfrac {1}{2}Kx_i^2\dfrac {1}{2}Kx_f^2\)
Negative and Positive Work by Spring
 When the spring is stretched or compressed, force and displacement are opposite to each other, thus work done by spring force is negative.
 When a spring is stretched, its distance increases from natural length but the force acts towards the natural length. Thus, both act opposite to each other.
Conclusion: On moving away from natural length, work done by spring force is negative and on moving towards natural length, work done is positive.
Variable Force
It is a force whose magnitude is a function of position /displacement, i.e., \(F=f(x)\)
Work Done by Variable Force
 Suppose a force is acting on a body which is not constant but depends upon displacement.
 Work done by constant force is expressed as the product of force and displacement, only when force is constant.
\(W=F_{\text {constant}}×\text {Displacement}\)
 Thus, this expression can't be used to calculate work done by variable force.
 To solve this problem, the displacement is divided into very small parts.
 Since, the parts are so small, so we can assume that force during that part of displacement is constant.
 So, summing up the work done by these small displacements, gives the total work.
 Consider an example, a force \(F=k\,x\) is acting on a body where \(x\) is the distance from origin.
 As we move from A to B, the value of the force changes (increases).
 So, to calculate the work done by force from A to B, we can't take any value of force.
 So, work done by small element \(dx\) is
\(W=\vec F \cdot d\vec x\)
 Since, the displacement and force are opposite making an angle of 180°
so, \(W=F \,dx\,×cos\,180°\)
\(W= F \cdot dx\)
 So, the total work done from all parts of displacement from A to B.
\(W_ T=\displaystyle\sum\limits_{\text {From 1st element}}^{\text {To last element}}Fdx\)
 This can also be calculated by using calculus.
\(W_ T=\displaystyle\int\limits_{\text {From 1st element}}^{\text {To last element}}\;F\;dx\)
 In short, we can say that to find total work done by variable force following steps can be followed:
 Write \(F\) as a function of \(x\).
 Write \(x\)as \(dx\).
 Integrate the force from first element \((x_i)\) to final element \((x_f)\).
 Spring follows Hook's law which states that force experienced by spring is directly proportional to the extension or compression from its natural length.
\(F\propto x\)
 Spring will exert a force \(Kx\) where \(K\) is a constant and \(x\) is the distance from natural length as shown in figure.
 The direction of spring force is always along its natural length.
 So, when the spring is stretched or compressed, the force of spring continuously increases as \(x\) increases.
 For the calculation of work done by spring force, integration is used, as force is variable.
\(W=\displaystyle\int\limits_{x_i}^{x_f}Kx\;dx=\dfrac {1}{2}K\Big[ x_f^2x_i^2\Big]\)
Work done \(=\dfrac {1}{2}Kx_i^2\dfrac {1}{2}Kx_f^2\)
 Consider a spring having natural length (NL) = \(\ell\,\)cm and spring constant \(K\).
 Its one end is attached to a rigid support and another end is attached to a small ring which can slide on a smooth vertical wire, as shown in figure.
 Since, work done by spring force is given as
\(W=\displaystyle\int\limits_{\text {Initial displacement}(x_i)}^{\text {Final displacement}(x_f)} K\,x\;dx\)
\(=\dfrac {1}{2}K\Big[ x_f^2x_i^2 \Big]\)
\(=\dfrac {1}{2}K\,x_i^2\dfrac {1}{2}K\,x_f^2\)
Calculation of \(x_i\) and \(x_f\)

Since when a spring is stretched or compressed, the variation occurs from its natural length \(\ell\).

Thus, natural length of spring is considered as reference.
 So, calculation of limits can be done as \(X=NL\text {Length}\)
 So, initial displacement \((x_i)=\)  Natural length – Initial length  \(=\ell  \ell_1\) and
final displacement \((x_f)=\) Natural length – Final length  \(=\ell  \ell_2\)
Conclusion: Work done by a spring force only depends on the initial and final position of spring with respect to its natural length.
 Work done by a variable force can be calculated using graphs also.
 The graph of force v/s displacement, provides the work done.
 The area between the graph and xaxis of a force v/s displacement graph gives the work done by force.
 Consider a force \(F=kx\), the work done can be calculated as
\(W= \displaystyle\int\limits_0^x\,k\,x\;dx\)
\(=k\displaystyle\int\limits_0^x\,x\;dx\)
\(=k\left [ \dfrac {x^2}{2} \right ]_0^x\)
\(= \dfrac {k\,x^2}{2}\)
 Now, using graph the work done will be calculated as
Area of shaded region = work done = \(\dfrac {1}{2}×(x)×(kx)\)
\(=\dfrac {1}{2}×k\,x^2\)
 Thus the work done is same as of calculus.
 Work done by a variable force can be calculated using graphs also.
 The graph of force v/s displacement, provides the work done.
 The area between the graph and xaxis of a force v/s displacement graph gives the work done by force.
 Consider a force \(F=kx\), the work done can be calculated as
\(W=\displaystyle\int\limits_0^x\,k\,x\;dx\)
\(=k\displaystyle\int\limits_0^x\,x\;dx\)
\(=k\left [ \dfrac {x^2}{2} \right ]_0^x\)
\(= \dfrac {k\,x^2}{2}\)
 Now, by using graph, work done will be calculated as
Area of shaded region = Work done = \(\dfrac {1}{2}×(x)×(kx)\)
\(=\dfrac {1}{2}×k\,x^2\)
 Thus the work done is same as of calculus.