% get_poly_roots.m

%

% function [xr,iflag] = get_poly_roots(coeff)

%

% This MATLAB m-file uses the eigenvalue method

% to calculate the roots of a polynomial.

% Note that the MATLAB roots function performs

% this task automatically.

%

% K. Beers

% MIT ChE. 7/9/2002

 

function [xr,iflag] = get_poly_roots(coeff)

 

iflag = 0;

 

% First, determine the degree of the polynomial.

N = length(coeff) - 1;

 

% If the leading order coefficient is zero,

% return an error.

if(coeff(1) == 0)

    iflag = -1;

    error('get_poly_roots: leading coefficient is zero');

end

 

% Next, construct the companion matrix.

A = zeros(N);

 

% Set the first row of A with the coefficients.

A(1,:) = -coeff(2:N+1) ./ coeff(1);

 

% Set the ones below the first column.

A(2:N,1:(N-1)) = eye(N-1);

 

% Determine the roots by evaluating the eigenvalues

% of the companion matrix.

xr = eig(A);

 

iflag = 1;

 

return;