<s>[INST] Generating functions ( recurrence relations ) Find $a_n$ using Generating Functions : $a_n = -a_{n-1} + 2a_{n−2}$, $n\ge2$ and $a_0 = 1$, $a_1 = 2$.
Approach : So I will form a characteristic equation $ r^2 + r - 2 = 0$ whose roots are $r_1 = -2$, $r_2 = 1$.
So my general solution is $a_n = α_1r_1^n + α_2r_2^n$.
$a_n = α_1(-2)^n + α_2(1)^n$
When $a_0 = 1$, then $1 =  α_1(-2)^0 + α_2(1)^0$, then $α_2 = 1 - α_1 $.
When $a_1 = 2$, then $2 =  α_1(-2)^1 + α_2(1)^1$, then $-2α_1 + 1 - α_1 = 2$.
$α_1 = -1/3$  and $α_2 = 4/3 $
So $a_n = -1/3r_1^n + 4/3r_2^n$.
Can anyone tell me if it is correct or not and any help will be appreciated :) .
Also, if I have $a_{n+2}=a_{n+1}+2a_n$. Can someone tell me if its char. equation should be like $r^2-r-2 = 0$? Just asking because of the addition symbol rather than subtraction.
 [/INST] If you really want to use generating functions to get $a_n$. In general with a recurrence relation with initial conditions $a_0$ and $a_1$ and \begin{equation}
a_n = r_1a_{n-1}+r_2a_{n-2}
\end{equation}
you can write the generating function as \begin{equation}
G(x) = \frac{-a_0-a_1x+a_0r_1x}{r_2x^2+r_1x-1}
\end{equation}
so your question will have \begin{equation}
G(x) = \frac{1+3x}{1+x-2x^2} = 1 + 2x +0x^2 + 4x^3 -4x^4 + \cdots
\end{equation}
where the coefficients of the expansion are the sequence $a_n$. To extract  the coefficients we can see that \begin{equation}
\frac{1}{n!}\frac{d^nG(x)}{dx^n}\bigg|_{x=0} =a_n
\end{equation}
however working out the $n^{th}$ derivative if a function can be tricky.
</s>