Solve recurrence relation $a(n) = -a(n - 2) + \cos({n} \cdot {\frac{\pi}{2}})$ Given recurrence equation
$$a(n) = -a(n - 2) + \cos({n} \cdot {\frac{\pi}{2}})$$
find the closed form solution.
Here is my attempt.
First solve the homogeneous equation:
$$a^{(0)}(n) = -a^{(0)}(n - 2)$$
My solution is:
$$a^{(0)}(n) = k_1 \cos({n} \cdot {\frac{\pi}{2}}) + k_2 \sin({n} \cdot {\frac{\pi}{2}})$$
Now the main concern is how should the particular solution look like.
I understand that if we have a recurrence equation $b(n) = c_1 b(n - 1) + c_2 b(n - 2) + 2^n$ and $f(n) = 2^n$ resonates with the solutions to $b^{(0)}(n) = c_1 b^{(0)}(n - 1) + c_2 b^{(0)}(n - 2)$, we just multiply it by $n$, so we look for $b(n) = k_3 n 2^n$.
If I repeat blindly the same multiplication, I get
$$a(n) = k_3 n \cos({n} \cdot {\frac{\pi}{2}}) + k_4 n \sin({n} \cdot {\frac{\pi}{2}})$$
Is it the correct way to look for particular solution?

If I proceed this way, I get the following general solution:
$$a(n) = k_1 \cos({n} \cdot {\frac{\pi}{2}}) + k_2 \sin({n} \cdot {\frac{\pi}{2}}) + \frac {n}{2} \cos({n} \cdot {\frac{\pi}{2}})$$
Is it the correct solution?

The $\cos$ seems to add a lot of complexity. Why not consider instead separately the even and odd subsequences, which do not "interact" and — rewriting the recurrence relation — satisfy:
$$\begin{align}
a_{2n+2} &= -a_{2n} + \cos (n+1)\pi = -a_{2n} - (-1)^n\\
a_{2n+1} &= -a_{2n-1}
\end{align}$$
for all $n$. Solving this gives directly
$$\begin{align}
a_{2n} &= (-1)^n a_0 + (-1)^n n\\
a_{2n+1} &= (-1)^{n}a_1
\end{align}$$
(If the first one is not straightforward, you can compute the first few terms to get an idea, then show it by induction.)
