How do I solve this comparing of coefficient in this differential equation? 
Solve $y'' + 2y' = \cos \pi x$

Homogeneous equation: $y= C_1 + C_2e^{-2x}$
Particular solution:
$y_p = A \cos \pi x + B\sin \pi x$
$y'=-A \pi \sin \pi x + B\pi \cos \pi x$
$y'' = -A \pi^2 \cos \pi x - B\pi^2 \sin \pi x$
Substituting back into the equation, $-A \pi^2 \cos \pi x - B\pi^2\sin \pi x + 2(-A\pi\sin \pi x + B\pi \cos \pi x) = \cos \pi x$
$\cos \pi x (-A\pi^2 + 2B\pi) - \sin\pi x(B\pi^2 + 2A\pi)= \cos \pi x$
So,
$ (-A\pi^2 + 2B\pi) =1 $
$(-B\pi^2 - 2A\pi) =0$
How do I solve this to get $y_p = \frac{1}{(4+\pi^2)\pi} (-\pi \cos \pi x + 2 \sin \pi x)$

From the second equation
$$A = -\dfrac{B \pi}{2}$$
Substituting into the first
$$B \pi^3 + 4 B \pi = 2$$
Solving for $B$
$$B = \dfrac{2}{\pi(\pi^2+4)}$$
Can you finish it off?
There are other approaches to finding $A$ and $B$.
