Different Spring constant when calculating different ways? I'm stumped on this one, so any clarification is appreciated.  The problem statement gives the following:
A mass weighing $10 N$ is placed on a vertical spring and causes the spring to compress 1 meter.  What is the spring constant, $k$?
From a perspective of balancing forces, the upward force of the spring must balance the downward force of gravity (if the system is at equilibrium and no other forces are involved), which gives the expression:
$F_{net} = ma \implies F_{spring} + F_{gravity} = 0$
$-kx = mg$
$-k(-1 m) = 10 N \implies k = 10 N/m$
However, if the conservation of energy is used, where E_total is constant before and after compression of the spring, the change in gravitational potential energy should be compensated by the change in the potential energy stored in the spring.
$\Delta U_{gravity} = 10N(1 m) = 10 J$
$\Delta U_{spring} = 1/2k(1 m)^2 = (0.5 m^2)k$
Setting the two expressions equal gives:
$10 J = (0.5 m^2)k$
$k = 20 N/m $
What is causing the two values of $k$ to differ?  I can't spot the error in either formulation, but they definitely give me different results.
 A: This means that something else must have taken 5 J of the total mechanical energy in your energy diagram. Your first equation to calculate the spring coefficient is correct:
$$mg = kx$$
But in this scenario, some external force has dampened the system, i.e. it has brought the mass to rest on the spring, which must be taken into account when considering the energy diagram.

This is the differential equation that describes motion on a spring when there are no external forces involved:
$$m \ddot{x} = mg - kx \quad \text{or} \quad \ddot{x} + \omega^2 x = g$$
where $\omega^2 = \frac{k}{m}$. What this means is that when you release the mass from its rest state, it will never stop oscillating. The solution to the above differential equation is:
$$x(t) = \frac{g}{\omega^2} ( 1 - \cos(\omega t)) \quad \text{and} \quad \dot{x}(t) = \frac{g}{\omega} \sin(\omega t)$$
where $x$ is displacement and $\dot{x}$ is velocity of the mass.
In your energy diagram from which you were calculating the spring coefficient $k$, you were calculating the mechanical energy for the displacement
$$x(t^\star) = \frac{mg}{k} = \frac{g}{\omega^2}$$
where $t^\star$ is the time at which displacement $x$ takes the value of $\frac{g}{\omega^2}$. Let's see what is the velocity at the time $t = t^\star$:
$$\text{from} \quad x(t^\star) = \frac{g}{\omega^2} = \frac{g}{\omega^2} (1 - \cos(\omega t^\star)) \quad \text{it follows} \quad \omega t^\star = \frac{\pi}{2} \quad \text{and} \quad \dot{x}(t^\star) = \frac{g}{\omega}$$
At that point there is also a kinetic energy you are forgetting:
$$K(t^\star) = \frac{1}{2} m v^2 = \frac{1}{2} m \frac{g^2}{\omega^2} = \frac{1}{2} \frac{(mg)^2}{k}$$
If you evaluate the above expression, you get the missing 5 J of the mechanical energy. In a scenario in which the mass is at rest on the spring, there must have been some external force which compensated kinetic energy so that the mass does not oscillate. The work from that force must also be taken into account in the energy diagram, and I showed here it equals exactly 5 J which was missing in your calculations.
The correct energy diagram of the spring-mass system without any external forces or dampening is as follows:
$$E = U_g + U_s + K = mgx + \frac{1}{2}kx^2 + \frac{1}{2}m\dot{x}^2$$
In the absence of external forces or dampening, the mechanical energy of the system always remains the same. In other words, the total mechanical energy $E$ is continuously distributed between gravitational and elastic potential energy, and kinetic energy. That is why the mass will oscillate forever. At some point the $U_p$ and $U_s$ will cancel out, but at that point all the mechanical energy $E$ is in $K$ which means the mass has the maximum velocity.

To conclude, your energy diagram for the total mechanical energy
$$mgx = \frac{1}{2} k x^2 \qquad \text{WRONG!}$$
is not correct because it does not include work from an external force that would bring the mass to rest on the spring. That is why you were getting the wrong value for $k$ when calculating it from the energy diagram. The correct calculation would be
$$\boxed{mgx + W_\text{ext} = \frac{1}{2} k x^2}$$
where $W_\text{ext} = -5 \text{ J}$.
A: The change in gravitational potential energy will not be just equal to the energy that will get stored in the spring. That means if you just leave the mass above the spring (just touching to the head of spring) partial energy will get converted into the kinetic energy of the block as well.
And in the case if we bring the block very slowly that the velocity will be nearly equal to zero that means we are also applying the force just in the opposite direction to the displacement of the mass.by applying the equal force so that the small velocity should remain constant . means work done by that external agent will come out to be negative and hence some amount of potential energy will get converted into our workdone and rest of the energy will get converted into the potential energy of the spring. (That amount of velocity is very small so that the kinetic energy can almost be treated as zero )
