I had to calculate the general solution to the equation for harmonic oscillator: $$\ddot{z}+\frac{f}{m}\cdot z = g + \frac{fz_0}{m},$$
here $g$ being the gravitational constant, $f$ being the frequency, $m$ being the mass and $z_0$ being the "idle state" of the spring. Let $\omega^2 = \frac{f}{m}$
I calculated the homogeneous solution:
$$z_h(t)=A\cdot \cos(\omega\cdot t - \varphi)$$
To get the general solution, I also need the particular/special solution. My approach for getting the particular was variation of constants, so I treated $A$ as time dependent:
Ansatz: \begin{align} z(t)&=A\cdot \cos(\omega\cdot t - \varphi) \\ \Rightarrow \dot z (t)&=A'(t)\cos(\omega\cdot t - \varphi) - \omega A(t)\sin(\omega\cdot t - \varphi)\\ \Rightarrow \ddot z(t)&=A''(t)\cos(\omega\cdot t - \varphi) - \omega A'(t)\sin(\omega\cdot t - \varphi) \\ &\ \ - \omega A'(t)\sin(\omega\cdot t - \varphi)-\omega^2A(t)\cos(\omega\cdot t - \varphi)\end{align}
We now put that into our differential equation to get:
$$A''(t)\cos(\omega\cdot t - \varphi) - \omega A'(t)\sin(\omega\cdot t - \varphi) - \omega A'(t)\sin(\omega\cdot t - \varphi)-\omega^2A(t)\cos(\omega\cdot t - \varphi) + \omega^2A\cdot \cos(\omega\cdot t - \varphi)=g+\omega z_0$$
The last two terms cancel out:
$$A''(t)\cos(\omega\cdot t - \varphi) - \omega A'(t)\sin(\omega\cdot t - \varphi) - \omega A'(t)\sin(\omega\cdot t - \varphi)=g+\omega z_0.$$
I expected the other two $\sin$ terms to be cancelled out as well but it seems that doesn't happen, so I'm still left with a differential equation.
What did I do wrong?
You can try instead $z(t)=A\cos(\omega t-\varphi)+C$, where $A$ and $C$ are constants. You should get $$\frac{f}{m} C= g+\frac{fz_0}{m}$$ You approach is not wrong, just that it does not lead to the desired solution