A mass on a spring does not come to rest without damping so the problem is inconsistent. Let's assume that this is just an ideal spring with a mass hanging at equilibrium so that we can neglect the effect of gravity that then experiences a forcing function. The equation for the y position would be:
ma = -k(y-ye) + 4cos(ωt)
mys'' + k(ys) = 4cos(ωt) where ys is deviation from equilibrium in y
rewrite as y" + (k/m)y = (4/m)cos(ωt)
This is an inhomogeneous 2nd order differential equation with constant coefficients.
The homogeneous solution is Asin(sqrt(k)t) + Bcos(sqrt(k)t)
The particular solution for sqrt(k/m) ≠ ω can be obtained by the method of undetermined coefficients:
yp is of the form Ccos(ωt)
Solving for particular solution by subbing into the equation:t
-Cω2cos(ωt) + C(k/m)cos(ωt) = 4cos(ωt)/m C = (4/m)/(k/m-ω2)
y = Acos(sqrt(k/m)t)+Bsin(sqrt(k)t) + ((4/m)/(k-ω2))cos(ωt) y and y' = 0 at t=0
y'=0 implies B = 0
y=0 : Acos(sqrt(k/m)t) + ((4/m)/(k/m-ω2))cos(ωt) = so A = -((4/m)/(k-ω2))cos(ωt)) / cos(sqrt(k)t))
As ω approaches sqrt(k/m), the system amplitude of oscillation blows up because the forcing frequency matches the resonance frequency of the system. Strictly speaking you need to solve for that condition separately using undetermined coefficient for tcos(sqrt(k/m)t) which will grow with time.
Please consider a tutor. Take care.