# Movement equation for the Simple harmonic oscillator

The force of the harmonic oscillator is written as
$$
F_{ho} = - D \cdot (x - x_0)
$$
where $D$ is the so called *spring constant* and $x_0$ is the location of reference, where the mass does not experience any force. Now, let's add a constant force, like gravity. The total force acting on the mass $m$ reads
$$
F_{total} = F_{g} + F_{ho} = -m g - D \cdot (x - x_0) = - D \cdot (x - \tilde x_0)
$$
where we used $\tilde x_0 := x_0 - \frac{mg}{D}$. Thus, by adding a constant term, we simply change the reference position.

Okay, so, look at it like this. In the equation you described, shown below, $x_0$ is a constant, being the resting point of the spring under zero gravity. $$ m\cdot a_y = - mg + D \cdot (x_0 - x_1) $$ We also know that $D$, $m$, and $g$ are similarly, constant values under normal circumstances, which means we can rewrite your original function as follows: $$ m\cdot a_y = D \cdot (x_0' - x_1) $$ with $x_0'$ the new resting point under constant acceleration (in this case, gravity): $$x_0'= x_0 - \frac{m \cdot g}{D}$$ Note that this result holds more generally, so long as the acceleration is constant in time and position. For gravity, it only holds because at the surface of the earth, the difference in position between an extended spring and an non-extended spring is negligible when compared to the distance to the center of mass of the earth.

As you asked, here is a mathematical argument to why gravitational force can be ignored. In general your equation would look like:

\begin{align*} x'' + \omega^2 x &= C \\ \end{align*} with $\omega^2=\frac{k}{m}$.

The solutions can be written as a solution of the homogeneous asociated equation (RHS =0) plus a particular solution. The homogeneous solution is, as you know, $x_h(t) = A e^{i\omega t}$, $A\in\mathbb{C}$. Now you have to get a particular solution, with the method you like the most. In this case, a trivial solution is $x_p(t) = C \frac{m}{k}$ which is constant. So, the final solution (taking the real part) is: \begin{align*} x(t) &= x_h(t) + x_p(t) \\ x(t) &= A \cos(\omega t+\phi) + C \frac{m}{k} \\ \end{align*} I don't know what it would be in your case, because I don't understand what $(x_0 - x_1)$ is.

Edit: Now I understand you meant a spring-mass system hanging vetically In that case, you would have: $$x''=-\frac{D(x-x_0)+mg}{m}$$ where $x_0$ would be the equilibrium position without gravity. Then, \begin{align*} x'' &= -\frac{D}{m} x + \frac{D x_0 - mg}{m} \end{align*} Defining \begin{cases} k &= D \\ C &= \frac{D x_0 - mg}{m} \\ \end{cases} you get $$\Rightarrow x(t)= A \cos\left(\sqrt{\frac{D}{m}}t+\phi\right)+x_0-\frac{mg}{D} \text{.}$$