2nd Order Inhomogeneous Recurrence Relation with Cosine I got the following homework in university:

Solve with the ansatz-method:
  $$a_n - a_{n-1} + a_{n-2} = \cos (\frac {n \pi } 3)$$

So I solved the characteristcal equation $\lambda^2 - \lambda + 1$ and got the homog. solution
$$x_n^{(h)} = r^n ( C_1 \cos ( \phi ) + C_2 \sin( \phi ))$$
with $r=1$ and $\phi = \frac \pi 3$.
Now I struggle with the particular solution.
I tried to use the following ansatz:
$$A \cos( \frac {n \pi} 3 ) + B \sin ( \frac {n \pi} 3 ) $$
But when I plug that into the given equation I get:
$$A \cos (\phi_n) + B \sin (\phi_n) - A \cos (\phi_{n-1}) - B \sin (\phi_{n-1}) + A \cos (\phi_{n-2}) + B (\sin \phi_{n-2}) = \cos (\phi_n) \\\text{with } \phi_n = \frac {n \pi} 3$$
This brings me nowhere.
Where did I go wrong? And how do I solve this properly?
 A: The homogeneous solution has the form 
$$ {a_n}^{(h)} = c_1\cos (n\phi) + c_2\sin (n\phi) $$
with $\phi = \pi/3$
For the particular, you'll need the ansatz
$$ {a_n}^{(p)} = n\big(A\cos (n\phi) + B\sin (n\phi)\big) $$
Using some trig identities, you can simplify the recurrence terms
$$ \begin{align} 
a_{n-1} &= (n-1) \Big(A\cos\big((n-1)\phi\big) + B\sin\big((n-1)\phi\big) \Big) \\
&= (n-1) \Big(A\cos \phi \cos (n\phi) + A\sin \phi \sin (n\phi) + B\cos \phi \sin (n\phi) - B\sin \phi \cos(n\phi) \Big) \\
&= \frac{n-1}{2}\Big( (A - \sqrt{3}B)\cos (n\phi) + (\sqrt{3}A + B)\sin (n\phi) \Big) \\ \\  
a_{n-2} &= (n-2) \Big(A\cos\big((n-2)\phi\big) + B\sin\big((n-2)\phi\big) \Big) \\
&= (n-2) \Big(A\cos (2\phi) \cos (n\phi) + A\sin (2\phi) \sin (n\phi) \\ 
&\qquad\qquad\quad + B\cos (2\phi) \sin (n\phi) - B\sin (2\phi) \cos(n\phi) \Big) \\
&= \frac{n-2}{2}\Big( -(A + \sqrt{3}B)\cos (n\phi) + (\sqrt{3}A - B)\sin (n\phi) \Big)
\end{align}
$$
And then some more algebra to obtain the $\cos(n\phi)$ and $\sin(n\phi)$ coefficients.
Good luck.
