roots

Roots of a polynomial.

Category: Mathematics > Elementary Math

Syntax

r = roots(p)

Returns the roots of the polynomial with coefficient vector p, as a column.

Description

The roots are the eigenvalues of the companion matrix of the polynomial, which is built from the normalized coefficients. For real coefficients, complex roots come in conjugate pairs.

The problem can be badly conditioned. Roots of high-degree polynomials, and multiple roots, are found with large errors even though the algorithm is stable, because small changes in the coefficients move the roots a lot.

Input arguments

p
Coefficient vector, highest power first. Leading zeros are dropped, and trailing zeros give zero roots.

Output arguments

r
Column vector of n roots for a polynomial of degree n; complex when some roots are complex. A constant or empty p gives [].

Example

Real, complex and zero roots

roots([1 -6 11 -6])
roots([1 2 5])
roots([2 -4 0])
Output
ans = 3×1

    3.0000
    2.0000
    1.0000
ans = 2×1 complex

   -1.0000 + 2.0000i
   -1.0000 - 2.0000i
ans = 2×1

     2
     0

See also

poly polyval polyfit eig residue