Main Content

poly

Polynomial with specified roots or characteristic polynomial

Description

p = poly(r), where r is a vector, returns the coefficients of the polynomial whose roots are the elements of r.

example

p = poly(A), where A is an n-by-n matrix, returns the n+1 coefficients of the characteristic polynomial of the matrix, det(λIA).

example

Examples

collapse all

Calculate the eigenvalues of a matrix, A.

A = [1 8 -10; -4 2 4; -5 2 8]
A = 3×3

     1     8   -10
    -4     2     4
    -5     2     8

e = eig(A)
e = 3×1 complex

  11.6219 + 0.0000i
  -0.3110 + 2.6704i
  -0.3110 - 2.6704i

Since the eigenvalues in e are the roots of the characteristic polynomial of A, use poly to determine the characteristic polynomial from the values in e.

p = poly(e)
p = 1×4

    1.0000  -11.0000   -0.0000  -84.0000

Use poly to calculate the characteristic polynomial of a matrix, A.

A = [1 2 3; 4 5 6; 7 8 0]
A = 3×3

     1     2     3
     4     5     6
     7     8     0

p = poly(A)
p = 1×4

    1.0000   -6.0000  -72.0000  -27.0000

Calculate the roots of p using roots. The roots of the characteristic polynomial are the eigenvalues of matrix A.

r = roots(p)
r = 3×1

   12.1229
   -5.7345
   -0.3884

Input Arguments

collapse all

Polynomial roots, specified as a vector.

Example: poly([2 -3])

Example: poly([2 -2 3 -3])

Example: poly(roots(k))

Example: poly(eig(A))

Data Types: single | double
Complex Number Support: Yes

Input matrix.

Example: poly([0 -1; 1 0])

Data Types: single | double
Complex Number Support: Yes

Output Arguments

collapse all

Polynomial coefficients, returned as a row vector.

  • If the input is a square n-by-n matrix, A, then p contains the coefficients for the characteristic polynomial of A.

  • If the input is a vector of roots, r, then p contains the coefficients for the polynomial whose roots are in r.

In each case, the n+1 coefficients in p describe the polynomial

p1xn+p2xn1+...+pnx+pn+1.

Tips

  • For vectors, r = roots(p) and p = poly(r) are inverse functions of each other, up to roundoff error, ordering, and scaling.

Algorithms

The algorithms employed for poly and roots illustrate an interesting aspect of the modern approach to eigenvalue computation. poly(A) generates the characteristic polynomial of A, and roots(poly(A)) finds the roots of that polynomial, which are the eigenvalues of A. But both poly and roots use eig, which is based on similarity transformations. The classical approach, which characterizes eigenvalues as roots of the characteristic polynomial, is actually reversed.

If A is an n-by-n matrix, poly(A) produces the coefficients p(1) through p(n+1), with p(1) = 1, in

det(λIA)=p1λn++pnλ+pn+1.

The algorithm is

z = eig(A);
p = zeros(n+1,1); 
p(1) = 1;
for j = 1:n
    p(2:j+1) = p(2:j+1)-z(j)*p(1:j);
end

This recursion is derived by expanding the product,

(λλ1)(λλ2)(λλn).

It is possible to prove that poly(A) produces the coefficients in the characteristic polynomial of a matrix within roundoff error of A. This is true even if the eigenvalues of A are badly conditioned. The traditional algorithms for obtaining the characteristic polynomial do not use the eigenvalues, and do not have such satisfactory numerical properties.

Extended Capabilities

Version History

Introduced before R2006a