numpy.roots#

numpy.roots(p)[原始碼]#

Return the roots of a polynomial with coefficients given in p.

備註

這是舊版多項式 API 的一部分。自 1.4 版本起,建議使用 numpy.polynomial 中定義的新版多項式 API。有關差異的概述,請參閱 transition guide

The values in the rank-1 array p are coefficients of a polynomial. If the length of p is n+1 then the polynomial is described by:

p[0] * x**n + p[1] * x**(n-1) + ... + p[n-1]*x + p[n]
參數:
parray_like

Rank-1 array of polynomial coefficients.

回傳值:
outndarray

An array containing the roots of the polynomial.

Raises:
ValueError

When p cannot be converted to a rank-1 array.

也參考

poly

Find the coefficients of a polynomial with a given sequence of roots.

polyval

Compute polynomial values.

polyfit

Least squares polynomial fit.

poly1d

A one-dimensional polynomial class.

Notes

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

References

[1]

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

範例

>>> import numpy as np
>>> coeff = [3.2, 2, 1]
>>> np.roots(coeff)
array([-0.3125+0.46351241j, -0.3125-0.46351241j])