MCPcopy Create free account
hub / github.com/numpy/numpy / chebroots

Function chebroots

numpy/polynomial/chebyshev.py:1719–1777  ·  view source on GitHub ↗

Compute the roots of a Chebyshev series. Return the roots (a.k.a. "zeros") of the polynomial .. math:: p(x) = \\sum_i c[i] * T_i(x). Parameters ---------- c : 1-D array_like 1-D array of coefficients. Returns ------- out : ndarray Array of the

(c)

Source from the content-addressed store, hash-verified

1717
1718
1719def chebroots(c):
1720 """
1721 Compute the roots of a Chebyshev series.
1722
1723 Return the roots (a.k.a. "zeros") of the polynomial
1724
1725 .. math:: p(x) = \\sum_i c[i] * T_i(x).
1726
1727 Parameters
1728 ----------
1729 c : 1-D array_like
1730 1-D array of coefficients.
1731
1732 Returns
1733 -------
1734 out : ndarray
1735 Array of the roots of the series. If all the roots are real,
1736 then `out` is also real, otherwise it is complex.
1737
1738 See Also
1739 --------
1740 numpy.polynomial.polynomial.polyroots
1741 numpy.polynomial.legendre.legroots
1742 numpy.polynomial.laguerre.lagroots
1743 numpy.polynomial.hermite.hermroots
1744 numpy.polynomial.hermite_e.hermeroots
1745
1746 Notes
1747 -----
1748 The root estimates are obtained as the eigenvalues of the companion
1749 matrix, Roots far from the origin of the complex plane may have large
1750 errors due to the numerical instability of the series for such
1751 values. Roots with multiplicity greater than 1 will also show larger
1752 errors as the value of the series near such points is relatively
1753 insensitive to errors in the roots. Isolated roots near the origin can
1754 be improved by a few iterations of Newton's method.
1755
1756 The Chebyshev series basis polynomials aren't powers of `x` so the
1757 results of this function may seem unintuitive.
1758
1759 Examples
1760 --------
1761 >>> import numpy.polynomial.chebyshev as cheb
1762 >>> cheb.chebroots((-1, 1,-1, 1)) # T3 - T2 + T1 - T0 has real roots
1763 array([ -5.00000000e-01, 2.60860684e-17, 1.00000000e+00]) # may vary
1764
1765 """
1766 # c is a trimmed copy
1767 [c] = pu.as_series([c])
1768 if len(c) < 2:
1769 return np.array([], dtype=c.dtype)
1770 if len(c) == 2:
1771 return np.array([-c[0]/c[1]])
1772
1773 # rotated companion matrix reduces error
1774 m = chebcompanion(c)[::-1,::-1]
1775 r = la.eigvals(m)
1776 r.sort()

Callers

nothing calls this directly

Calls 2

chebcompanionFunction · 0.85
sortMethod · 0.80

Tested by

no test coverage detected