x = asint + bcost
dx/dt = acost - bsint
d2x/dt2 = -asint - bcost
So, substituting into the differential equation d2x/dt2 - dx/dt - x = cost, we have:
(-asint - bcost) - (acost - bsint) - (asint + bcost) = cost
(-a - 2b)cost + (-2a - b)sint = (1)cost + (0)sint
So, -a - 2b = 1 and -2a - b = 0
Multiply the first equation by -2:
2a + 4b = -2
-2a - b = 0
3b = -2
So, b = -2/3 and a = 1/3
x(t) = (1/3)sint - (2/3)cost