<s>[INST] solve the recurrence relation $a_n = 7a_{n-1} - 16a_{n-2} +12a_{n-3} + n4^n $ Solve the recurrence relation
$$a_n = 7a_{n-1} - 16a_{n-2} +12a_{n-3} +  n4^n $$
With initial conditions:
$a_0 = −2$
$a_1 = 0$
$a_2 = 5$
I solve the homogenous part like that:
$$a_n - 7a_{n-1} + 16a_{n-2} -12a_{n-3} = 0 $$
$$ p(r) = r^3 -7r^2 + 16r - 12 $$
$$ p(r) = (r-2)^2(r-3) $$
But I am stucked with the non-homogenous part.
For $$ g(n) = 4^n $$ We can use $$ q(r) = A4^n $$ But for $$ g(n) = n4^n $$
What we should do?
 [/INST] You can find a particular solution using the $Z$ transform:
$$
Z[a_n-7a_{n-1}+16a_{n-2}-12a_{n-3}]=Z[n 4^n]
$$
then
$$
\left(1-\frac 7z+\frac {16}{z^2}-\frac{12}{z^3}\right)Z[a_n]=\frac{4z}{(z-4)^2}+7a_{-1}-16 \left(a_{-2}+\frac{a_{-1}}{z}\right)+12\left(a_{-3}+\frac{a_{-2}}{z}+\frac{a_{-1}}{z^2}\right)
$$
now taking the initial values $a_{-1}= a_{-2}=a_{-3}=0$ (a particular solution) we have
$$
Z[a_n] = \frac{4 z^4}{(z-4)^2 \left(z-2\right)^2(z-3)}
$$
and now inverting we have a particular solution
$$
a_{n}^p = 4 \left(2^n \left(2^{n+2} (n-5)-n-7\right)+3^{n+3}\right)
$$
</s>