Can someone explain how to solve this? Cheers.
Okay, I will go through the particular solution first. I will let $\displaystyle x_p$ denote the particular solution. Since the nonhomogeneous part is a trigonometric function we will let the particular solution be of the form $\displaystyle x_p = A\sin \gamma t + B\cos \gamma t$. Now we must determine the coefficients $\displaystyle A,B$. To do this we will plug $\displaystyle x_p$ back into the original DEQ.
$\displaystyle x''_p = -\gamma^2 A \sin \gamma t - \gamma^2 B \cos \gamma t$
and so
$\displaystyle -\gamma^2 A \sin \gamma t - \gamma^2 B \cos \gamma t + w^2 \cdot \left( A\sin \gamma t + B\cos \gamma t \right) = \cos \gamma t$
$\displaystyle \left(w^2 -\gamma^2\right) A \sin \gamma t + \left(w^2 - \gamma^2\right) B \cos \gamma t = \cos \gamma t$.
Thus we have
$\displaystyle \left(w^2 - \gamma^2\right)A \sin \gamma t = 0$
and
$\displaystyle \left(w^2 - \gamma^2\right)B \cos\gamma t = \cos \gamma t$.
Therefore, we have
$\displaystyle \left(w^2 - \gamma^2\right)A = 0$
and
$\displaystyle \left(w^2 - \gamma^2\right)B = 1$,
so
$\displaystyle A = 0$
$\displaystyle B = \frac{1}{w^2 - \gamma^2}$.
Finally, we see that our particular solution is
$\displaystyle x_p = \frac{1}{w^2 - \gamma^2} \cos \gamma t$.
Deleted mistake see following post.
Sorry I made a mistake. The homogeneous solution is wrong. The solution of the characteristic equation is not $\displaystyle \lambda = \pm w$. The solution is $\displaystyle \lambda = \pm w i$.
Therefore, the homogeneous solution is of the form
$\displaystyle x_h = C_1\cos w t + C_2 \sin w t$.
Finally, the general solution should be
$\displaystyle x(t) = C_1\cos w t + C_2 \sin w t + \frac{1}{w^2 - \gamma^2} \cos \gamma t$.
To determine the constants $\displaystyle C_1,C_2$ we must have initial conditions.