MATLAB: Leverrier method to find polynomial of matrix

\nleverrierleverrier methodmatrixpolynomial

Hi guys,
I need to find a method to generalize Leverrier Method to find matrix's characteristic polynomial.
Input should be only the matrix.
As theory I have:
  1. PA(x)=x^n-c1*n^(n-1)+c2*x(n-2)+…+(-1)^n*c[n] – polynomial
  2. s[k]=trace(A^k), 1<=k<=n
  3. c[k], 1<=k<=n
c1=s1
c2=(s1*c2-s[k])/2
c[k]=(s1*c[k-1]-s2*c[k-2]+…+(-1)^(k+1)*s[k])/k, 2<=k<=n
Also i have to display PA and a graph or something
What I have so far:
function [A,n]=leverrier_n()
for i=1 to n
for j=2 to n
V[j]=A^j
s[i]=trace(V[j])
end
end
for k=2 to n
i=1;
t[1]=s[1]
t[k]=(s[i]*t[k-1]-s[i+1]*t[k-2]+)/k
end
end

Best Answer

function c = leverrier(A)
a=size(A,1);
M=zeros(a);
c=zeros(1,a+1);
c(1)=1;
for k=2:a+1
M=A*M+c(k-1)*eye(a);
c(k)=-1/(k-1)*trace(A*M);
end
end
Related Question