Here's a general theory for applying functions to square matrices. Any square matrix $M$ has a Jordan normal form: a decomposition $M = SJS^{-1}$ where $S$ is invertible and $J$ is block-diagonal $J = J_1 \oplus J_2 \oplus \cdots\,$ with the Jordan blocks $J_i$ of the form
$$J_i = \begin{bmatrix}
\lambda_i & 1\\
& \lambda_i & \ddots\\
&& \ddots & 1\\
&&& \lambda_i
\end{bmatrix}$$
for some block size and some scalar $\lambda_i$. Then to apply a (sufficiently well-behaved) function to the matrix, we have $f(M) = S \, f(J) \, S^{-1}$.
In your scenario, we have the function $f : x \mapsto x^n$. To compute the Jordan normal form of $M$, it's already very close to the desired form so we can just determine it by inspection:
$$M = \begin{bmatrix}
1 & 1 & 0\\
0 & 1 & -1\\
0 & 0 & 1
\end{bmatrix} = \begin{bmatrix}
1 & 0 & 0\\
0 & 1 & 0\\
0 & 0 & -1
\end{bmatrix} \begin{bmatrix}
1 & 1 & 0\\
0 & 1 & 1\\
0 & 0 & 1
\end{bmatrix} \begin{bmatrix}
1 & 0 & 0\\
0 & 1 & 0\\
0 & 0 & -1
\end{bmatrix} = SJS^{-1}.$$
Then from the result in the page above, we get
$$f(J) = f\left(\begin{bmatrix}
1 & 1 & 0\\
0 & 1 & 1\\
0 & 0 & 1
\end{bmatrix}\right) = \begin{bmatrix}
f(1) & f'(1) & \frac{f''(1)}{2!}\\
0 & f(1) & f'(1)\\
0 & 0 & f(1)
\end{bmatrix} = \begin{bmatrix}
1 & n & \frac{n(n-1)}{2}\\
0 & 1 & n\\
0 & 0 & 1
\end{bmatrix}.$$
Taking the similarity transformation back, we find that
$$M^n = S f(J) S^{-1} = \begin{bmatrix}
1 & n & -\frac{n(n-1)}{2}\\
0 & 1 & -n\\
0 & 0 & 1
\end{bmatrix}.$$
As an aside, when the matrix is diagonalizable (which yours is not), the formula simplifies because we can take $M = S D S^{-1}$ where $D = \mathrm{diag}(d_1, d_2, \ldots)$ is diagonal, hence applying $f$ to $D$ is simply $f(D) = \mathrm{diag}(f(d_1), f(d_2), \ldots)$ (i.e., we don't need to compute off-diagonal elements and take derivatives).
$$ N^2 = \left( \begin{array}{rrr} 0 & 0 & -1 \ 0 & 0 & 0 \ 0 & 0 & 0 \ \end{array} \right) $$
$$ N^3 = \left( \begin{array}{rrr} 0 & 0 & 0 \ 0 & 0 & 0 \ 0 & 0 & 0 \ \end{array} \right) $$
– Will Jagy Dec 06 '24 at 04:10