MCPcopy Index your code
hub / github.com/numpy/numpy / roots

Function roots

numpy/lib/_polynomial_impl.py:169–262  ·  view source on GitHub ↗

Return the roots of a polynomial with coefficients given in p. .. note:: This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in `numpy.polynomial` is preferred. A summary of the differences can be found in the :doc:`trans

(p)

Source from the content-addressed store, hash-verified

167
168@array_function_dispatch(_roots_dispatcher)
169def roots(p):
170 """
171 Return the roots of a polynomial with coefficients given in p.
172
173 .. note::
174 This forms part of the old polynomial API. Since version 1.4, the
175 new polynomial API defined in `numpy.polynomial` is preferred.
176 A summary of the differences can be found in the
177 :doc:`transition guide </reference/routines.polynomials>`.
178
179 The values in the rank-1 array `p` are coefficients of a polynomial.
180 If the length of `p` is n+1 then the polynomial is described by::
181
182 p[0] * x**n + p[1] * x**(n-1) + ... + p[n-1]*x + p[n]
183
184 Parameters
185 ----------
186 p : array_like
187 Rank-1 array of polynomial coefficients.
188
189 Returns
190 -------
191 out : ndarray
192 An array containing the roots of the polynomial.
193
194 Raises
195 ------
196 ValueError
197 When `p` cannot be converted to a rank-1 array.
198
199 See also
200 --------
201 poly : Find the coefficients of a polynomial with a given sequence
202 of roots.
203 polyval : Compute polynomial values.
204 polyfit : Least squares polynomial fit.
205 poly1d : A one-dimensional polynomial class.
206
207 Notes
208 -----
209 The algorithm relies on computing the eigenvalues of the
210 companion matrix [1]_.
211
212 References
213 ----------
214 .. [1] R. A. Horn & C. R. Johnson, *Matrix Analysis*. Cambridge, UK:
215 Cambridge University Press, 1999, pp. 146-7.
216
217 Examples
218 --------
219 >>> import numpy as np
220 >>> coeff = [3.2, 2, 1]
221 >>> np.roots(coeff)
222 array([-0.3125+0.46351241j, -0.3125-0.46351241j])
223
224 """
225 # If input is scalar, this makes it an array
226 p = atleast_1d(p)

Callers 1

rootsMethod · 0.85

Calls 8

atleast_1dFunction · 0.90
diagFunction · 0.90
eigvalsFunction · 0.90
_to_real_if_imag_zeroFunction · 0.90
hstackFunction · 0.90
nonzeroMethod · 0.80
astypeMethod · 0.80
ravelMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…