Solve $a_n=7a_{n-1}-12a_{n-2}+3^n$ $a_0=1\:a_1=2$
Using generating functions I get:
$f\left(x\right)-1-2x=7xf\left(x\right)-7x-12x^2f\left(x\right)+\frac{1}{1+3x}-1-3x$
$f\left(x\right)=\frac{3}{14\left(1+3x\right)}-\frac{13}{2\left(3x-1\right)}\:+\:\frac{40}{7\left(4x-1\right)}$
Now how can I express $a_n$ from this?

Hint (without generating functions): eliminate $3^n$ between the recurrence relations for $n$ and $n+1$, then you get a $3^{rd}$ order linear homogeneous recurrence:
$$\require{cancel}
a_{n+1}-3 a_n=7 a_n-12a_{n-1}+\cancel{3^{n+1}} - 3(7 a_{n-1}-12 a_{n-2}+ \cancel{3^n}) \\[3px]
\iff a_{n+1} = 10 a_n - 33 a_{n-1}+36 a_{n-2}
$$
The characteristic polynomial of the latter is $t^3-10t^2+33t-36=(t-3)^2(t-4)$ so the solution of the recurrence will be of the form $a_n=(a+b\cdot n)\cdot 3^n+c \cdot 4^n$ where constants $a,b,c$ remain to be determined from the initial conditions.
