Suppose I have a weightless spring connected perpendicularly to the ground, and it has on top of it some weightless surface. Now, I release some sticky object from height $h$ above the system of light spring-surface. The object eventually hits the surface and the spring is starting to contract till all the kinetic energy of the object is transformed to elastic potential energy. And the system continues to oscillate harmonically. I want to find the maximal contraction of the spring, therefore, I did:
(we assume that no energy is lost during the collision)
$U_{GR}=E_{k,max}=U_{SP, max}$
$mgh=\frac{1}{2}kx_{max}^2$
where $k$ is the stiffness coefficient.
Therefore:
$x_{max}=\sqrt{\frac{2mgh}{k}}$
I've chosen my 0 level for gravitational potential energy to be on the same level as 0 level of potential elastic energy. Suppose I want to choose another 0 level for GPE, e.g. at maximum contraction. Then my equation would be:
$mg(h+x_{max})=\frac{1}{2}kx_{max}^2$
It obviously leads us to a slightly different $x_{max}$ value.
According to the numbers in the answer in my book it seems like the second equation is correct.
My question is - how then correct equations should look like if I want to arbitrary choose my PE 0 level at any point? Or why the first one is wrong?
Also, I'm wondering why the amplitude of the oscillations is not $x_{max}$ (according to the book it is slightly less the correct $x_{max}$ value, even though we assumed that no kinetic energy was lost. Interesting coincidence: the amplitude on the contrary, according to the book, equals to the $x_{max}$ value of my first equation).