# Solve the following second order linear differential equation

I'm having trouble finding the solution for the following differential equation

$x'' + x = \frac{-2}{cost}$

So the solution of the homogeneous equation is trivial $x_H = c_1\cos(t) + c_2 \sin(t)$

I'm having trouble with the particular solution

How can I pass my $b(t) =\frac{-2}{cost}$ to something like $b(t) = e^{\alpha t}(p_1(t)\cos(\beta t) + c_2(t) \sin(\beta t))$?

You wanted to solve $$x''(t) + x(t) = b(t)$$ with $$b(t) = \frac{-2}{\cos(t)}$$ and you know $$x_c(t) = \underbrace{c_1 \cos(t)}_{x_1(t)} + \underbrace{c_2 \sin(t)}_{x_2(t)} = x_1(t) + x_2(t)$$ define $$W(x_1,x_2):=x_1(t)x_2'(t) - x_1'(t)x_2(t)$$ which is called the Wronskian, in this case $$W(c_1 \cos(t),c_2 \sin(t))=c_1c_2$$ then the general solution is $$x_p(t) = x_2(t)\int \frac{x_1(t)b(t)}{W(x_1,x_2)}\;dt - x_1 \int \frac{x_2(t)b(t)}{W(x_1,x_2)}\;dt$$ which in this particular case is $$x_p(t) = -c_2 \sin(t)\int \frac{2c_1 \cos(t)}{c_1c_2 \cos(t)}\;dt + c_1 \cos(t) \int \frac{2c_2 \sin(t)}{c_1c_2 \cos(t)}\;dt$$ you can cancel the constants and the first integral is easily resolved $$x_p(t) = 2\cos(t) \int \tan(t)\;dt -2(t+c_3)\sin(t)$$ $$x_p(t) = -2\cos(t) (\log(\cos(t))+c_4) -2(t+c_3)\sin(t)$$ and $x(t)=x_c(t)+x_p(t)$ so $$x(t) = c_1 \cos(t) + c_2 \sin(t) -2(t+c_3)\sin(t)-2\cos(t)( \log(\cos(t))+c_4)$$