poly

Coefficients of the polynomial with given roots, or the characteristic polynomial of a matrix.

Category: Mathematics > Elementary Math

Syntax

p = poly(r)

For a vector r, returns the coefficients of the monic polynomial whose roots are the elements of r.

p = poly(A)

For a square matrix A, returns the coefficients of its characteristic polynomial det(s*I - A).

Description

For roots r1, r2, ... the result is the expansion of (s - r1)*(s - r2)*.... When the roots come in complex-conjugate pairs the coefficients are real, and poly returns real numbers; otherwise the output is complex. For a matrix, the roots used are its eigenvalues.

poly and roots are inverses of each other, up to the order of the roots, but the round trip loses accuracy for high degrees or clustered roots.

Input arguments

r
Vector of roots.
A
Square matrix.

Output arguments

p
Row vector of n+1 coefficients, highest power first, with leading coefficient 1.

Example

From roots and from a matrix

poly([1 2 3])
poly([1+2i 1-2i])
poly([1 2; 3 4])
Output
ans = 1×4

     1    -6    11    -6
ans = 1×3

     1    -2     5
ans = 1×3

    1.0000   -5.0000   -2.0000

See also

roots polyval conv eig polyfit