Cayley-Hamilton theorem illustration

CAYLEY-HALMITON theorem

It states that any square matrix is solution of its characteristic equation. That is to say: let us denote , the vector of the n characteristic polynomial coefficients such that:
Then:

Computation of from , , , , , :

Then by using this theoreom it can be shown that, for :
where the coefficients are recursively defined by:
and for ,
Notation : .
Illustration :
n=5;
A=rand(n,n);
a=poly(eig(A));
vector :
a=a(n+1:-1:2);
vector :
f0=-a;
exemple: (the objective is to compute ):
k=3;
Recurcive computation of :
fk=f0;
for ii=1:k,
temp=-a(1)*fk(end);
fk(2:end)=-a(2:end)*fk(end)+fk(1:end-1);
fk(1)=temp;
end
Check the result:
bid=zeros(n,n);
for ii=1:n, bid=bid+fk(ii)*A^(ii-1);end;
bid-A^(n+k)
ans = 5×5
10-11 ×
-0.1364 -0.0909 -0.1364 -0.1364 -0.0909 -0.1819 -0.1819 -0.1819 -0.1592 -0.1592 -0.2728 -0.2274 -0.2728 -0.2274 -0.2728 -0.2728 -0.1819 -0.2274 -0.3183 -0.3183 -0.3183 -0.2274 -0.3638 -0.3183 -0.2728

Computation of from , , , , , :

The characteristc polynomial of is:
Then, for :
where the coefficients are recursively defined by:
and for ,
Notation : .

Computation of from , , , , :

with:
Notation : .
Remark: in the following example we show how the matrix exponential can be computed thanks to the Cayley-Hamilton theorem. It is just an illustrative example. There is more efficient algorithms to compute the matrix exponential (see: help expm ).
Example (in the sum operation, k is limited to ):
t=0.1;
At=A*t;
Vector of characteristic polynomial coefficients:
for ii=1:n, at(ii)=a(ii)*t^(n+1-ii);end;
f0t=-at;
Recursive computation of :
gt=1./factorial([0:n-1]);
for k=0:20,
fkt=f0t;
for ii=1:k,
temp=-at(1)*fkt(end);
fkt(2:end)=-at(2:end)*fkt(end)+fkt(1:end-1);
fkt(1)=temp;
end
gt=gt+1/factorial(n+k)*fkt;
end
Check the result:
bid=zeros(n,n);
for ii=1:n, bid=bid+gt(ii)*A^(ii-1)*t^(ii-1);end;
bid-expm(At)
ans = 5×5
10-15 ×
0.2220 0.0052 0.0069 0.0035 0.0278 0.0416 0 0.0555 0.0069 0.0052 0.0173 0 0 0.0278 0 0.0971 0.0694 0.0416 0 0.0139 0.0555 0.0555 0.0139 0.0139 -0.2220