numpy.polynomial.polynomial.polyfromroots

numpy.polynomial.polynomial.polyfromroots(roots)

Generate a polynomial with the given roots.

Return the array of coefficients for the polynomial whose leading coefficient (i.e., that of the highest order term) is 1 and whose roots (a.k.a. “zeros”) are given by roots. The returned array of coefficients is ordered from lowest order term to highest, and zeros of multiplicity greater than one must be included in roots a number of times equal to their multiplicity (e.g., if 2 is a root of multiplicity three, then [2,2,2] must be in roots).

Parameters :

roots : array_like

Sequence containing the roots.

Returns :

out : ndarray

1-d array of the polynomial’s coefficients, ordered from low to high. If all roots are real, out.dtype is a float type; otherwise, out.dtype is a complex type, even if all the coefficients in the result are real (see Examples below).

See also

chebfromroots

Notes

What is returned are the a_i such that:

\sum_{i=0}^{n} a_ix^i = \prod_{i=0}^{n} (x - roots[i])

where n == len(roots); note that this implies that 1 is always returned for a_n.

Examples

>>> import numpy.polynomial as P
>>> P.polyfromroots((-1,0,1)) # x(x - 1)(x + 1) = x^3 - x
array([ 0., -1.,  0.,  1.])
>>> j = complex(0,1)
>>> P.polyfromroots((-j,j)) # complex returned, though values are real
array([ 1.+0.j,  0.+0.j,  1.+0.j])

Previous topic

numpy.polynomial.polynomial.polyroots

Next topic

numpy.polynomial.polynomial.polyfit

This Page