Work done by spring over distance I'm working through a problem involving energy conservation. Unfortunately, I cannot calculate the work done by a spring.
Before:

+------------+
|            |
|  spring    | d1
|            |
+------------+

After:

+------------+
|            |
|  spring    |
|            | d2
|            |
|            |
+------------+

Given the spring constant, d1, and d2, how can I determine the work done? Also, please explain how the formula was calculated instead of just posting an answer.
 A: You know the basic spring equation, right? $F = -Kx$, where $K$ is the spring constant, in units of force per distance.
You also know work (energy) is the dot product of force and distance, right?
So all you've got to do is integrate $-Kx$ $dx$ from $d_1$ to $d_2$.
(Hint: you can pull $-K$ out of the integral.)
You could do it on graph paper if you happened to know $d_1$ and $d_2$.
ADDED: OK, here's the graph paper approach:
A graph of force, $F$, versus displacement, $x$, looks like this, right?

    \ | F
     \|
______|____________
      |\           X
      | \
      |  \
      |   \
      |    \
      |     \
      |      \
      |       \

The slope of the graph is $-K$.
The area under the graph is work $W$, because it is just the sum of a bunch of vertical slivers with area $F$ times the width $dx$ of each sliver.
So here's how you get the answer to your question:

     \|
______|_________
      |\   |||||
      | \  |||||
      |  \ |||||
    F |   \|||<---- just get the area of this piece
      |    |||||
      |   d1\|||
      |      \||
      |       \|
               d2

That help?
A: Work is defined as
$$W=\int_{x_1}^{x_2}\mathbf{F} \cdot d \mathbf{x} $$
The force exerted by a spring is 
$$\mathbf{F}=-k\mathbf{x} $$
where $\mathbf{x}$ is the distance from the equilibrium point of the spring.
Plugging the first equation into the second yeilds:
$$\begin{eqnarray}
W&=&\int_{x_1}^{x_2}-k\mathbf{x} \cdot d \mathbf{x} \\
&=&\frac{1}{2}kx_1^2-\frac{1}{2}kx_2^2
\end{eqnarray} $$
