Compute the roots of a Chebyshev series with given complex roots in Python

To compute the roots of a Chebyshev series, use the chebyshev.chebroots() method in Python NumPy. The method returns an array of the roots of the series. If all the roots are real, then the output is also real, otherwise it is complex. The parameter c is a 1-D array of coefficients.

The root estimates are obtained as the eigenvalues of the companion matrix. Roots far from the origin of the complex plane may have large errors due to the numerical instability of the series for such values. Roots with multiplicity greater than 1 will also show larger errors as the value of the series near such points is relatively insensitive to errors in the roots. Isolated roots near the origin can be improved by a few iterations of Newton's method.

Syntax

numpy.polynomial.chebyshev.chebroots(c)

Parameters:

  • c : array_like - 1-D array of Chebyshev series coefficients ordered from low to high degree

Returns:

  • out : ndarray - Array of the roots of the series

Example with Complex Coefficients

Let's compute the roots of a Chebyshev series with complex coefficients ?

from numpy.polynomial import chebyshev as C

# Define complex coefficients
j = complex(0, 1)
coefficients = (-j, j)

# Compute the roots of the Chebyshev series
roots = C.chebroots(coefficients)
print("Result (roots)...")
print(roots)

# Get the datatype
print("\nDatatype:")
print(roots.dtype)

# Get the shape
print("\nShape:")
print(roots.shape)
Result (roots)...
[1.+0.j]

Datatype:
complex128

Shape:
(1,)

Example with Real Coefficients

When all coefficients are real, the output roots are also real ?

from numpy.polynomial import chebyshev as C

# Real coefficients
real_coefficients = [1, -2, 1]  # Represents x^2 - 2x + 1
roots = C.chebroots(real_coefficients)

print("Roots with real coefficients:")
print(roots)
print("\nDatatype:", roots.dtype)
Roots with real coefficients:
[1.41421356]

Datatype:
float64

Multiple Roots Example

Here's an example with a Chebyshev series that has multiple roots ?

from numpy.polynomial import chebyshev as C
import numpy as np

# Coefficients for a higher degree polynomial
coefficients = [1, 0, -1, 0, 1]
roots = C.chebroots(coefficients)

print("Roots of higher degree series:")
print(roots)
print(f"\nNumber of roots: {len(roots)}")
print(f"All roots real: {np.all(np.isreal(roots))}")
Roots of higher degree series:
[-1.30656296  0.54119610  1.30656296 -0.54119610]

Number of roots: 4
All roots real: True

Conclusion

The chebyshev.chebroots() method efficiently computes roots of Chebyshev series using eigenvalue decomposition. For complex coefficients, it returns complex roots, while real coefficients typically yield real roots. Be aware that numerical instability may affect roots far from the origin.

Updated on: 2026-03-26T20:02:38+05:30

229 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements