Solve $a_n=2 a_{n-1} - a_{n-2} + 2^n$ using generating function I'm preparing to an exam and trying to solve $a_n=2 a_{n-1} - a_{n-2} + 2^n$, where $a_0=0$ and $a_1=1$.
This is my approach:

Let $A(z)=\sum_{n \geq 0} a_{n+2} z^{n+2}$, then:
$$\sum a_{n+2} z^{n+2} = 2 \sum a_{n+1} z^{n+2} - \sum a_n z^{n+2} + \sum (2z)^{n+2}$$
$$A(z)-a_0-a_1 z = 2z(A(z)-a_0)-z^2 A(z) + z^2 \frac{1}{1-2z}$$
$$A(z)(1-2z+z^2)=z+\frac{z^2}{1-2z}$$
$$A(z)=\frac{z(1-z)}{(1-2z)(1-2z+z^2)}=\frac{z}{(1-2z)(1-z)}=\frac{1}{1-2z}-\frac{1}{1-z}=\sum (\underbrace{2^n - 1}_{=a_n}) z^n$$

According to Wolfram, the result is different. Can you tell me where did I make the mistake?

While the generating function approach works systematically, you can solve this example by hand directly without too much trouble. First I'll define $a_{-1}=1$ (so that the recurrence holds down to $n=1$) and define $b_n=a_n-a_{n-1}$. Then your recurrence becomes $b_n=b_{n-1}+2^n$ for all positive $n$, and from the first few terms ( e.g. -1,1,5,13,...) it's easy to see that the solution is given by $b_n=2^{n+1}-3$. From this we obtain $a_{n\geq 0}$:
\begin{align}
a_n
&=b_n+a_{n-1}\\
&=b_n+b_{n-1}+a_{n-2}\\
&\cdots \\&=b_n+b_{n-1}+\cdots+b_1+a_0\\
&=(2^{n+1}-3)+(2^{n}-3)+\cdots +(2^{2}-3)+0\\
&=\fbox{$4(2^{n}-1)-3n$}.\end{align}
