4. Given $a_{0}=-1, a_{1}=1, a_{n}=2 a_{n-1}+3 a_{n-2}+3^{n}(n \geqslant 3)$, find $a_{n}$.
4. Let $f(x)=a_{0}+a_{1} x+a_{2} x^{2}+\cdots+a_{n} x^{n}+\cdots$
$$
\begin{array}{l}
-2 x \cdot f(x)=-2 a_{0} x-2 a_{1} x^{2}-\cdots-2 a_{n-1} x^{n}-\cdots, \\
-3 x^{2} \cdot f(x)=-3 a_{0} x^{2}-\cdots-3 a_{n-2} x^{n}-\cdots, \\
-\frac{1}{1-3 x}=-1-3 x-3^{2} x^{2}-\cdots-3^{n} x^{n}-\cdots .
\end{array}
$$

Adding the above four equations and using the given conditions, we get $\left(1-2 x-3 x^{2}\right) \cdot f(x)-\frac{1}{1-3 x}=-2$.
Thus, $f(x)=\frac{6 x-1}{(1+x)(1-3 x)^{2}}=\frac{A}{1+x}+\frac{B}{(1-3 x)^{2}}+\frac{C}{1-3 x}$,
then $A=\left.f(x)(1+x)\right|_{x=-1}=-\frac{7}{16}, B=\left.f(x)(1-3 x)\right|_{x=\frac{1}{3}}=\frac{3}{4}$,
$0=\lim _{x \rightarrow \infty} x f(x)=\lim _{x \rightarrow \infty}\left(\frac{A x}{1+x}+\frac{B x}{(1-3 x)^{2}}+\frac{C x}{1-3 x}\right)=A-\frac{1}{3} C$. Therefore, $C=3 A=-\frac{21}{16}$.
$$
\text { Hence } \begin{aligned}
f(x) & =-\frac{7}{16(1+x)}+\frac{3}{4(1-3 x)^{2}}-\frac{21}{16(1-3 x)} \\
& =-\frac{7}{16} \sum_{k=0}^{\infty}(-1)^{k} \cdot x^{k}+\frac{3}{4} \sum_{k=0}^{\infty} C_{k+1}^{1} 3^{k} x^{k}-\frac{21}{16} \sum_{k=0}^{\infty} 3^{k} x^{k} \\
& =\sum_{k=0}^{\infty}\left[\frac{(4 k .-3) \cdot 3^{k+1}-7(-1)^{k}}{16}\right] x^{k} .
\end{aligned}
$$

Therefore, $a_{n}=\frac{1}{16}\left[(4 n-3) \cdot 3^{n+1}-7(-1)^{n}\right]$ is the solution.