\begin{problem}
A mass $m$ is attached to the free end of a light vertical spring
(unstretched length $l$) of spring constant $k$ and suspended from a
ceiling. The spring stretches by $\Delta l$ under the load and comes
to equilibrium at a height $h$ above the ground level (y = 0). The
mass is pushed up vertically by $A$ from its equilibrium position and
released from rest. The mass-spring executes vertical
oscillations. Assuming that gravitational potential energy of the mass
$m$ is zero at the ground level, show that the total energy of the
spring-mass system is $\frac{1}{2}k(\Delta l^2 + A^2) + mgh$.

Hint: Draw four clear sketches of the vertical free spring,
spring-mass in equilibrium and the two extreme positions of
oscillation of the mass. Below each of the above sketches (except free
spring), write equations for kinetic energy, elastic potential energy,
gravitational potential energy, and total energy using symbols $k$,
$\Delta l$, $m$, $A$, $g$, $h$, and $v_m$.
\end{problem}

\begin{solution}
\begin{center}
\begin{asy}
import Mechanics;

real u = 1cm;
real L = 1.5u;
real dL = 0.7L;
real A = 0.5L;
real h = 2L;

draw((0,0)--(4L,0), green);
label("ground", (0,0), W);

draw((0,h+dL+L)--(4L,h+dL+L));
label("fixed end", (0,h+dL+L), W);

draw((0,h)--(4L,h), gray(0.6)+dashed);
label("equilibrium", (0,h), W);

draw((0,h+dL)--(4L,h+dL), gray(0.6)+dashed);
label("unstretched", (0,h+dL), W);

draw((0,h+A)--(4L,h+A), gray(0.6)+dashed);
label("maximum", (0,h+A), W);

draw((0,h-A)--(4L,h-A), gray(0.6)+dashed);
label("minimum", (0,h-A), W);

Mass m;
Spring s;

real x = 0;
s = Spring(pFrom=(x,h+dL+L), pTo=(x,h+dL));
s.draw();

real x = 2L;
m = Mass((x,h), radius=1.5mm);
s = Spring(pFrom=(x,h+dL+L), pTo=m.center);
s.draw();
m.draw();

real x = 3L;
m.center = (x,h+A);
s = Spring(pFrom=(x,h+dL+L), pTo=m.center);
s.draw();
m.draw();

real x = 4L;
m.center = (x,h-A);
s = Spring(pFrom=(x,h+dL+L), pTo=m.center);
s.draw();
m.draw();

real dx = 0.5u;
Distance Dh = Distance(pFrom=(0,0), pTo=(0,h), "$h$");
Dh.draw(rotateLabel=false);
Distance DdL = Distance(pFrom=(dx,h), pTo=(dx,h+dL), "$\Delta l$ ");
// inline asymptote crowds the label.  this space intentional  -^
DdL.draw(rotateLabel=false);
Distance DL = Distance(pFrom=(2dx,h+dL), pTo=(2dx,h+dL+L), "$L$");
DL.draw(rotateLabel=false);
Distance Aup = Distance(pFrom=(3dx,h), pTo=(3dx,h+A), "$A$");
Aup.draw(rotateLabel=false);
Distance Adn = Distance(pFrom=(4dx,h-A), pTo=(4dx,h), "$A$");
Adn.draw(rotateLabel=false);
\end{asy}
\end{center}

\begin{tabular}{l l l l}
  &
  Equilibrium &
  Top &
  Bottom \\
Kinetic energy &
  $\frac{1}{2}mv_m^2$ &
  $0$ &
  $0$ \\
Elastic energy &
  $\frac{1}{2}k\Delta l^2$ &
  $\frac{1}{2}k(\Delta l-A)^2$ &
  $\frac{1}{2}k(\Delta l+A)^2$ \\
Gravitational energy &
  $mgh$ & 
  $mg(h+A)$ &
  $mg(h-A)$ \\
Total energy &
  $\frac{1}{2}mv_m^2+mgh+\frac{1}{2}k\Delta l^2$ &
  $mg(h+A)+\frac{1}{2}k(\Delta l-A)^2$ &
  $mg(h-A)+\frac{1}{2}k(\Delta l+A)^2$
\end{tabular}

These energies are all equivalent to the suggested formula, because
\begin{align}
  k\Delta l &= mg \\
  v_m &= \omega A = \sqrt{\frac{k}{m}} A \\
  E_e &= \frac{1}{2}mv_m^2 +mgh+\frac{1}{2}k\Delta l^2
    = mgh + \frac{1}{2}m\frac{k}{m}A^2 +\frac{1}{2}k\Delta l^2
    = mgh + \frac{1}{2}k(\Delta l^2 + A^2) \\  
  E_t &= mg(h+A)+\frac{1}{2}k(\Delta l-A)^2
    = mgh + k\Delta l A + \p({\frac{1}{2}k\Delta l^2 - k\Delta l A + \frac{1}{2}kA^2})
    = mgh + \frac{1}{2}k(\Delta l^2 + A^2) \\
  E_b &= mg(h-A)+\frac{1}{2}k(\Delta l+A)^2
    = mgh - k\Delta l A + \p({\frac{1}{2}k\Delta l^2 + k\Delta l A + \frac{1}{2}kA^2})
    = mgh + \frac{1}{2}k(\Delta l^2 + A^2)
\end{align}
\end{solution}
