Answer:
[tex]U = MgD + \frac{1}{2}kD^2[/tex]
Explanation:
In the first case, the mass is at equilibrium. Therefore, the net force on the mass is equal to zero.
In the second case, the spring is compressed by an amount of D, which is equal to an elastic potential energy of
[tex]U_e = \frac{1}{2}kD^2[/tex]
At this height, the gravitational potential energy of the mass is equal to
[tex]U_g = MgD[/tex]
Then, the total potential energy at height D is
[tex]U = MgD + \frac{1}{2}kD^2[/tex]