Generate a Chebyshev series with given complex roots in Python

To generate a Chebyshev series with given complex roots, use the chebyshev.chebfromroots() method in NumPy. The method returns a 1-D array of coefficients. If all roots are real then the output is a real array; if some of the roots are complex, then the output is complex even if all coefficients in the result are real.

Syntax

numpy.polynomial.chebyshev.chebfromroots(roots)

Parameters

roots ? A sequence containing the roots from which to generate the Chebyshev series.

Example with Complex Roots

Let's generate a Chebyshev series using complex roots -j and j where j is the imaginary unit ?

from numpy.polynomial import chebyshev as C

# Define complex imaginary unit
j = complex(0, 1)

# Generate Chebyshev series with complex roots -j and j
result = C.chebfromroots((-j, j))
print("Chebyshev coefficients:")
print(result)

# Check the datatype
print("\nDatatype:", result.dtype)

# Check the shape
print("Shape:", result.shape)
Chebyshev coefficients:
[1.5+0.j 0. +0.j 0.5+0.j]

Datatype: complex128
Shape: (3,)

Example with Real Roots

For comparison, let's see what happens with real roots ?

from numpy.polynomial import chebyshev as C

# Generate Chebyshev series with real roots
real_result = C.chebfromroots([-1, 1])
print("Real roots result:")
print(real_result)
print("Datatype:", real_result.dtype)
Real roots result:
[-0.5  0.   0.5]

Datatype: float64

How It Works

The chebfromroots() function constructs a Chebyshev polynomial that has the specified roots. For complex roots ±j, the resulting polynomial is P(x) = (x + j)(x - j) = x² + 1, which gets converted to Chebyshev coefficients.

Conclusion

The chebfromroots() method effectively generates Chebyshev series coefficients from given roots. Complex roots produce complex coefficient arrays, while real roots produce real coefficient arrays.

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

271 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements