numpoly.roots

numpoly.roots(poly: numpoly.typing.PolyLike)numpy.ndarray[source]

Return the roots of a polynomial.

Assumes the polynomial has a single dimension.

Args:
poly:

Polynomial to take roots of, or if constant, the coefficients of said polynomial. This to be compatible with numpy.roots().

Return:

An array containing the roots of the polynomial.

Raise:
ValueError:

When poly cannot be converted to a rank-1 polynomial.

Note:

The algorithm relies on computing the eigenvalues of the companion matrix 1.

1

R. A. Horn & C. R. Johnson, Matrix Analysis. Cambridge, UK: Cambridge University Press, 1999, pp. 146-7.

Example:
>>> q0 = numpoly.variable()
>>> poly = 3.2*q0**2+2*q0+1
>>> numpoly.roots(poly)
array([-0.3125+0.46351241j, -0.3125-0.46351241j])
>>> numpoly.roots([3.2, 2, 1])
array([-0.3125+0.46351241j, -0.3125-0.46351241j])