# Generate a Chebyshev series with given complex roots in Python

PythonNumpyServer Side ProgrammingProgramming

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

## Steps

At first, import the required library −

from numpy.polynomial import chebyshev as C

Given complex roots −

j = complex(0,1)

Generate the series −

print("Result...\n",C.chebfromroots((-j, j)))

Get the datatype −

print("\nType...\n",C.chebfromroots((-j, j)).dtype)


Get the shape −

print("\nShape...\n",C.chebfromroots((-j, j)).shape)

## Example

from numpy.polynomial import chebyshev as C

# To generate a Chebyshev series with given roots, use the chebyshev.chebfromroots() method in Python Numpy.

# The method returns 1-D array of coefficients. If all roots are real then out is a real array, if some of the roots are complex, then out is complex even if all the coefficients in the result are real.

# The parameter roots are the sequence containing the roots.
j = complex(0,1)
print("Result...\n",C.chebfromroots((-j, j)))

# Get the datatype
print("\nType...\n",C.chebfromroots((-j, j)).dtype)

# Get the shape
print("\nShape...\n",C.chebfromroots((-j, j)).shape)

## Output

Result...
[1.5+0.j 0. +0.j 0.5+0.j]

Type...
complex128

Shape...
(3,)
Updated on 02-Mar-2022 05:53:57