There is following recursive function
$$ \begin{equation} a_n= \begin{cases} -1, & \text{if}\ n = 0 \\ 1, & \text{if}\ n = 1\\ 10a_{n-1}-21a_{n-2}, & \text{if}\ n \geq 2 \end{cases} \end{equation} $$
I know this can be rewritten as $$ a_n=7^n-2\cdot3^n $$
But how can I reach that statement? I found this problem on some particular website. My skills are not enough to solve such things. Someone told me I have to read about Generating function but it didn't help me.
I would be thankful if someone explained it to me.
The way to do this without generating functions is to start with the ansatz that $$ a_n = x^n $$ satisfies the recursion but possibly not the starting points at $n=0$ and $1$.
If we have that solution then any $a_nkx^n$ satisfies the recursion as well.
And if we have two such solutions $x^n$ and $y^n$ then any linear combination $a_n=kx^n+my^n$ will satisfy the recursion, and we can adjust $k,m$ to fit the starting points.
Well, if $a_n = x^n$ then $$ x^n = 10 x^{n-1} - 21x^{n-2} \\ x^2 = 10 x -21 \\ x = 7 \mbox{ or } x=3 $$
So the general solution of the recursion is $$ a_n = k\cdot 7^n + m \cdot 3^n $$
Now plug in $n=0$ and $n=1$ to satisfy the starting points: $$ k \cdot 7^0 + m \cdot 3^0 = -1 \\ k \cdot 7^1 + m \cdot 3^1 = +1 $$
which gives $$ k = 1 \\m = -2$$ so the particular solution is $$ a_n = 7^n -2\cdot 3^n $$