r = roots(c)
Row vector c contains the coefficients of a polynomial, ordered in descending powers. If c has n+1 components, the polynomial it represents is c1sn + … + cns + cn + 1.
The polynomial s3 – 6s2 – 72s – 27 is represented in MATLAB® software as
p = [1 -6 -72 -27]
The roots of this polynomial are returned in a column vector by
r = roots(p) r = 12.1229 -5.7345 -0.3884
The algorithm simply involves computing the eigenvalues of the companion matrix:
A = diag(ones(n-1,1),-1); A(1,:) = -c(2:n+1)./c(1); eig(A)
It is possible to prove that the results produced are the exact eigenvalues of a matrix within roundoff error of the companion matrix A, but this does not mean that they are the exact roots of a polynomial with coefficients within roundoff error of those in c.