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?

We can compute $A^2$ directly:
$$
A^2 = \left(
\begin{array}{ccc}
 2 & 0 & 2 \\
 0 & 2 & 1 \\
 0 & 0 & 3 \\
\end{array}
\right)\left(
\begin{array}{ccc}
 2 & 0 & 2 \\
 0 & 2 & 1 \\
 0 & 0 & 3 \\
\end{array}
\right)
= 
\left(
\begin{array}{ccc}
 4 & 0 & 10 \\
 0 & 4 & 5 \\
 0 & 0 & 9 \\
\end{array}
\right).
$$
From the Cayley-Hamilton theorem, it follows that
\begin{align}
A^3 &= 7A^2 -16A + 12I\\
&= 7\left(
\begin{array}{ccc}
 4 & 0 & 10 \\
 0 & 4 & 5 \\
 0 & 0 & 9 \\
\end{array}
\right) - 16\left(
\begin{array}{ccc}
 2 & 0 & 2 \\
 0 & 2 & 1 \\
 0 & 0 & 3 \\
\end{array}
\right) + 12\left(
\begin{array}{ccc}
 1 & 0 & 0 \\
 0 & 1 & 0 \\
 0 & 0 & 1 \\
\end{array}
\right)\\
&= \left(
\begin{array}{ccc}
 8 & 0 & 38 \\
 0 & 8 & 19 \\
 0 & 0 & 27 \\
\end{array}
\right).
\end{align}
Observe the pattern
$$
A^n = \left(
\begin{array}{ccc}
 2^n & 0 & -2 \left(2^n-3^n\right) \\
 0 & 2^n & -2^n+3^n \\
 0 & 0 & 3^n \\
\end{array}
\right).
$$
Clearly this holds for $n=1$. Assume that it holds for some $n\geqslant 1$, then
\begin{align}
A^{n+1} &= AA^{n}\\
&= \left(
\begin{array}{ccc}
 2 & 0 & 2 \\
 0 & 2 & 1 \\
 0 & 0 & 3 \\
\end{array}
\right)\left(
\begin{array}{ccc}
 2^n & 0 & -2 \left(2^n-3^n\right) \\
 0 & 2^n & -2^n+3^n \\
 0 & 0 & 3^n \\
\end{array}
\right)\\
&= \left(
\begin{array}{ccc}
 2^{n+1} & 0 & -2 \left(2^{n+1}-3^{n+1}\right) \\
 0 & 2^{n+1} & -2^{n+1}+3^{n+1} \\
 0 & 0 & 3^{n+1}. \\
\end{array}
\right)
\end{align}
So by induction, this formula holds for all positive integers $n$.
