I'm asked to find a recursive formula to this closed formula:
$$f(n) = 2n + 3^nn$$
I tried to transform this formula to a formula that I might get using the Characteristic polynomial method.
As I understand the $3^nn$ here implies that $x_{1}=x_{2}=3$ are solutions of the Characteristic polynomial but there should be $3^nn^0$ too. So I'm not sure how to solve this.
Nice problem, thank you.
First, find the ordinary generating function for the sequence $f(n).$ We have $$ \sum_{n >0}f(n)z^n=\sum_{n >0}(2\,n +n\, 3^n)z^n=2\sum_{n >0}n z^n+\sum_{n >0}n 3^n z^n=\\=2\,{\frac {z}{ \left( z-1 \right) ^{2}}}+3\,{\frac {z}{ \left( 3\,z-1 \right) ^{2}}}={\frac {z \left( 21\,{z}^{2}-18\,z+5 \right) }{ \left( 3\,z-1 \right) ^{2} \left( z-1 \right) ^{2}}}. $$ We see that the generating function is a rational function. It implies that $f(n)$ is a solution of a linear recurrence relation with constant coeficents of degree $4.$
The coeficients of the reccurence relation we find from the denominator of the generating function. We have $$ \left( 3\,z-1 \right) ^{2} \left( z-1 \right)^{2}=9\,{z}^{4}-24\,{z}^{3}+22\,{z}^{2}-8\,z+1 $$ These coefficients equal to the coefficients of the reccurence relation ( see for instance Stanley book Enumerative combinatorics): The sequence $$ a_n=\alpha_1 a_{n-1}+\alpha_2 a_{n-2}+\cdots+ \alpha_k a_{n-k}. $$ has a generating function with the denominator $$ 1-\alpha_1 z- \alpha_2 z^2 -\cdots- \alpha_k z^k, $$ and visa versa.
At last we get the reccurence relation $$ f(n)=8f(n-1)-22f(n-2)+24f(n-3)-9f(n-4),\\ f(0)=0, f(1)=5,f(2)=22,f(3)=87. $$