<s>[INST] 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?
 [/INST] You have to be more careful with your indexing. I prefer to always cast the equation so that it is defined for $n \geq 0$ for greater consistency, but of course it doesn't matter as long as you keep track of your indices.
Anyway, the correct equation would be 
$$A(z)(z^2-2z+1) = z + z^2 \frac{4}{1-2z}$$
if you defined $A(z) = \sum_{n=0}a_nz^n$. If you do the algebra you'll get
$$A(z) = \frac{4}{1-2z}+\frac{z-4}{(z-1)^2} = \frac{4}{1-2z}-\frac{1}{1-z}-3\frac{d}{dz}\left(\frac{1}{1-z}\right)$$
and hence
$$\sum_{n=0}a_nz^n = 4\sum_{n=0}2^nz^n-\sum_{n=0}z^n-3\sum_{n=1}nz^{n-1}$$
or
$$\sum_{n=0}a_nz^n = 4\sum_{n=0}2^nz^n-\sum_{n=0}z^n-3\sum_{n=0}(n+1)z^{n}=\sum_{n=0}(-3n+2^{n+2}-4)z^n,$$
as desired.
</s>