Solution (source code)

= Solution

Measure the vertical displacement $x$ downward from the spring's unstretched position. The <kinetic energy> is $m\dot x^2/2$, while the spring and gravitational <potential energies> are $kx^2/2$ and $-mgx$. Thus the <Lagrangian> is
$$
\boxed{\mathcal L=\frac12m\dot x^2-\frac12kx^2+mgx.}
$$
Applying the <Euler-Lagrange equation>, $d(\partial\mathcal L/\partial\dot x)/dt-\partial\mathcal L/\partial x=0$, gives
$$
\boxed{m\ddot x+kx=mg.}
$$
Gravity shifts the equilibrium to $x_*=mg/k$. For displacement $\xi=x-x_*$ from that equilibrium, the <equation of motion> becomes $\ddot\xi+(k/m)\xi=0$, giving <simple harmonic motion> with <angular frequency> $\omega=\sqrt{k/m}$. Choosing an upward coordinate instead reverses the gravitational term, but leaves the equilibrium-relative <angular frequency> unchanged.