How to solve a recurrence relation of the type $a_{n+1} = K(n)a_{n} + P(n)a_{n-1}$ where $K(n)$ and $P(n)$ are rational functions

discrete mathematicsrecurrence-relations

I've been stuck on a problem for days now and was able to boil it down to this recurrence relation. I researched a bit about ways to solve it — generating functions, characteristic polynomials, homogenous and non-homogenous recurrence relations — but couldn't find a method of tackling this specific one. Any tips, solutions, or suggestions would be welcomed. Thanks.

Edit: As made clear in the comments, treating the functions as any rational function is too general to solve. The specific problem I am solving requires $K(n) = (2n+5)/(n+2)$ and $P(n) = (n+1)(n+3)^2/(n+2)$

Edit #2: As requested, $a_1 = 5 ; a_2 = 33 ; a_3 = 168$

Best Answer

$a_{n+1} = \dfrac{2n+5}{n+2} a_{n} + \dfrac{(n+1)(n+3)^2}{n+2} a_{n-1}$

Rewriting $\,2n+5 = (n+3)^2 - (n+2)^2\,$:

$$ \quad\quad a_{n+1} = \frac{(n+3)^2 - (n+2)^2}{n+2} a_{n} + \frac{(n+1)(n+3)^2}{n+2} a_{n-1} \\ \iff\quad\quad a_{n+1} + (n+2) a_n = \frac{(n+3)^2}{n+2} \big(a_n + (n+1) a_{n-1}\big) $$

With $\,b_n = a_{n} + (n+1) a_{n-1}\,$, this telescopes to:

$$ \require{cancel} b_{n+1} = \frac{(n+3)^2}{n+2} \,b_n = \frac{(n+3)^2}{\bcancel{n+2}} \,\frac{(n+2)^{\bcancel{2}}}{n+1} \, b_{n-1} = \dots = (n+3)\,\frac{(n+3)!}{2} \, b_0 $$

Once $\,b_n\,$ is determined, what's left to solve is the simpler recurrence:

$$ a_{n} + (n+1) a_{n-1} = b_n \quad\iff\quad \frac{a_n}{(n+1)!} = -\frac{a_{n-1}}{n!} + \frac{b_n}{(n+1)!} $$