1.24 Verify the Cayley-Hamilton theorem that every matrix is zero of its characteristic polynomial

Problem, given the matrix \[ \left ( {\begin {array} [c]{cc}1 & 2\\ 3 & 2 \end {array}} \right ) \] Verify that matrix is a zero of its characteristic polynomial. The Characteristic polynomial of the matrix is found, then evaluated for the matrix. The result should be the zero matrix.

Mathematica

Remove["Global`*"] 
a = {{1,2},{3,2}}; 
n = Length[a]; 
p = CharacteristicPolynomial[a,x]
 

\(x^2-3 x-4\)

(-4 IdentityMatrix[n] - 3 a + 
  MatrixPower[a,2])//MatrixForm
 

\[ \left ( {\begin {array}{cc} 0 & 0 \\ 0 & 0 \\ \end {array}} \right ) \]

Another way is as follows

a  = {{1,2},{3,2}}; 
p  = CharacteristicPolynomial[a,x]; 
cl = CoefficientList[p,x]; 
Sum[MatrixPower[a,j-1] cl[[j]], 
     {j,1,Length[cl]}]
 

\[ \left ( {\begin {array}{cc} 0 & 0 \\ 0 & 0 \\ \end {array}} \right ) \]

 

Matlab

MATLAB has a build-in function polyvalm() to do this more easily than in Mathematica. Although the method shown in Mathematica can easily be made into a Matlab function

clear; 
A=[1 2;3 2]; 
p=poly(A); 
poly2str(p,'x') 
polyvalm(p,A)
 

ans = 
   x^2 - 3 x - 4 
ans = 
     0     0 
     0     0