# roots

## Purpose

Polynomial roots.

## Synopsis

    r = roots(p)

## Description

Polynomial coefficients are ordered in descending powers: if a vector `c` has `n+1` components, the polynomial it represents is

If `c` is a row vector containing the coefficients of a polynomial, `roots(c)` is a column vector whose elements are the roots of the polynomial.

If `r` is a column vector containing the roots of a polynomial, `poly(r)` returns a row vector whose elements are the coefficients of the polynomial.

For vectors, `roots` and `poly` are inverse functions of each other, up to ordering, scaling, and roundoff error.

## Examples

The polynomial

is represented in MATLAB 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

## Algorithm

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`.

## See Also

    conv, fzero, poly, polyval, residue

(c) Copyright 1994 by The MathWorks, Inc.