Source: High school physics (Chinese)
Problem
A 2.0 kg block is dropped from a height of 0.40 m onto a vertical spring standing on the ground. The spring has a spring constant $k = 2000$ N/m.
The total mechanical energy of the block-spring-Earth system is conserved. Let the maximum compression be $x$. The block falls a total distance of $(h+x)$. The initial energy (gravitational potential) equals the final energy (elastic potential). We set the zero level for gravitational potential energy at the point of maximum compression.
$$E_{initial} = E_{final}$$ $$U_{g,i} = U_{el,f}$$ $$mg(h+x) = \frac{1}{2}kx^2$$This can be rearranged into a quadratic equation for $x$:
$$\frac{1}{2}kx^2 - mgx - mgh = 0$$Substituting the values ($g=9.8 \text{ m/s}^2$):
$$\frac{1}{2}(2000)x^2 - (2.0)(9.8)x - (2.0)(9.8)(0.40) = 0$$ $$1000x^2 - 19.6x - 7.84 = 0$$Solving using the quadratic formula yields the positive root for $x$.