# 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?


I'll consider $\ds{b_{n} = -b_{n - 2} + \ic^{n}}$ such that $\ds{\,\mathrm{a}\pars{n} = \Re\pars{b_{n}}}$.

With $\ds{\ul{\quad z \in \mathbb{R}\quad \mbox{and}\quad 0 < z < 1}}$: \begin{align} \sum_{n = 2}^{\infty}b_{n}\,z^{n} & = -\sum_{n = 2}^{\infty}b_{n - 2}\,\,z^{n} + \sum_{n = 2}^{\infty}\ic^{n}\,z^{n} \\[4mm] \sum_{n = 0}^{\infty}b_{n}\,z^{n} - b_{0} - b_{1}\,z & = -\sum_{n = 0}^{\infty}b_{n}\,\,z^{n + 2}\ -\ {z^{2} \over 1 - \ic z} \\[4mm] \pars{1 + z^{2}}\sum_{n = 0}^{\infty}b_{n}\,z^{n} & = b_{0} + b_{1}\,z - {z^{2} \over 1 - \ic z} \\[4mm] \sum_{n = 0}^{\infty}b_{n}\,z^{n} & = {b_{0} + b_{1}\,z \over 1 + z^{2}} - {z^{2} \over \pars{1 + z^{2}}\pars{1 - \ic z}} \end{align}

\begin{align} \sum_{n = 0}^{\infty}\,\mathrm{a}\pars{n}\,z^{n} & = {\,\mathrm{a}\pars{0} + \,\mathrm{a}\pars{1}\,z \over 1 + z^{2}} - {z^{2} \over \pars{1 + z^{2}}^{2}} \\[4mm] & = \bracks{\,\mathrm{a}\pars{0} + \,\mathrm{a}\pars{1}\,z} \sum_{n = 0}^{\infty}\pars{-1}^{n}\,z^{2n} - z^{2}\sum_{n = 0}^{\infty}{-2 \choose n}z^{2n} \end{align}
With $\ds{{-2 \choose n} = {2 + n - 1 \choose n}\pars{-1}^{n} = \pars{-1}^{n}\pars{n + 1}}$: \begin{align} &\sum_{n = 0}^{\infty}\,\mathrm{a}\pars{2n}\,z^{2n} + \sum_{n = 0}^{\infty}\,\mathrm{a}\pars{2n + 1}\,z^{2n + 1} \\[4mm] = &\ \,\mathrm{a}\pars{0} \sum_{n = 0}^{\infty}\pars{-1}^{n}\,z^{2n} + \sum_{n = 1}^{\infty}\pars{-1}^{n}\, n\,z^{2n} + \,\mathrm{a}\pars{1} \sum_{n = 0}^{\infty}\pars{-1}^{n}\,z^{2n + 1} \\[4mm] = &\ \,\mathrm{a}\pars{0} + \sum_{n = 1}^{\infty}\bracks{\,\mathrm{a}\pars{0} + n}\pars{-1}^{n}\,z^{2n} + \sum_{n = 0}^{\infty}\,\mathrm{a}\pars{1}\pars{-1}^{n}\,z^{2n + 1} \end{align}
$$\color{#f00}{\,\mathrm{a}\pars{n}} = \color{#f00}{\left\lbrace\begin{array}{lcl} \ds{\pars{-1}^{\pars{n - 1}/2}\,\,\,\mathrm{a}\pars{1}} & \mbox{if} & \ds{n}\ \mbox{is}\ \ul{odd} \\[2mm] \ds{\pars{-1}^{n/2}\,\,\,\bracks{\mathrm{a}\pars{0} + {n \over 2}}} & \mbox{if} & \ds{n}\ \mbox{is}\ \ul{even} \end{array}\right.}$$

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.)