<s>[INST] Find the $n$-th power of a $3{\times}3$ matrix using the Cayley-Hamilton theorem. I need to find $A^n$ of the matrix $A=\begin{pmatrix}
 2&0  & 2\\ 
 0& 2 & 1\\ 
 0& 0 & 3
\end{pmatrix}$ using Cayley-Hamilton theorem.
I found the characteristic polynomial $P(A)=(2-A)^2(3-A)$ from which I got $A^3=7A^2-16A+12$. How to continue?
 [/INST] Since $p(A)=0$ where $p(x)=(2-x)^2(3-x)$, if we divide $x^n$ by $p(x)$ to get $x^n=p(x)q(x)+r(x)$, then $A^n=p(A)q(A)+r(A)=0q(A)+r(A)=r(A)$, so it suffices to figure out $r$.  However, if $n$ is large, actually doing division will not be effective.
Since $p(2)=p(3)=0$, we have that $r(2)=2^n$ and $r(3)=3^n$.  However, since all we know about the degree of $r$ is that it is less than $3$, we need another value to specify it.  However, if we differentiate
$$x^n=p(x)q(x)+r(x)$$
to get
$$nx^{n-1}=p'(x)q(x)+p(x)q'(x)+r'(x)$$
and use the fact that, because $2$ is a double root of $p(x)$, $p(2)=p'(2)=0$, then we get $n2^{n-1}=r'(2)$.
If we write $r(x)=a_nx^2+b_nx+c_n$, then we get the system of equations:
$$\begin{align} 2^n &=4a_n+2b_n+c_n \\ 3^n&=9a_n+3b_n+c_n \\ n2^{n-1}&=4a_n+b_n \end{align}.$$
Then we can solve
$$\pmatrix{a_n \\ b_n \\ c_n}=\pmatrix{4&2&1\\9&3&1\\4&1&0}^{-1}\pmatrix{2^n\\3^n\\n2^{n-1}}=\pmatrix{3^n-2^n-n2^{n-1}\\4\cdot 2^n+5n\cdot 2^n-3^n\\4\cdot 3^n-3\cdot 2^n-6n\cdot 2^n}.$$
However, we can simplify things if we note that $A$ actually satisfies the quadratic equation $(A-2I)(A-3I)=0$ (the minimal polynomial will always divide the characteristic polynomial and has the same roots but with potentially smaller multiplicities, so there aren't many combos to check here), so we can use this quadratic polynomial instead of the characteristic polynomial to obtain that $A^n=a_nA+b_nI$ for some $a_n,b_n$.  If $r_n(x)=a_nx+b_n$ is the remainder polynomial, we have (using the exact same proceedure as before) 
$$2^n=2a_n+b_n, \quad 3^n=3a_n+b_n,$$
so $$a_n=3^n-2^n, \quad b_n=-2\cdot 3^n-3\cdot 2^n.$$
</s>