Skip to content
Related Articles

Related Articles

Generate Chebyshev series with given complex roots using NumPy in Python

View Discussion
Improve Article
Save Article
  • Last Updated : 03 Jun, 2022

In this article, we will cover how to generate the Chebyshev series with given complex roots in Python using NumPy.

Example

Input: (4+5j)
Output: [9.5-40.j 0.  +0.j 0.5 +0.j]
Explanation: An array of Chebyshev series.

chebyshev.chebfromroots() method

In python, the Chebyshev module provides many functions like chebfromroots to perform arithmetic, and calculus operations on the Chebyshev series. It is one of the functions provided by the Chebyshev class that returns an array of coefficients. This method is used to generate the Chebyshev series which is available in the NumPy module in python. Below is the syntax of the chebfromroots method.

  • If all roots are real then the output will be a real array,
  • If any of the roots are complex, the output is a complex array.

Syntax: chebyshev.chebfromroots((-my_value, my_value))

Parameter:

  • my_value: is the complex number.

Return: 1-D array of coefficients.

Example 1:

In this example, we will create a complex number using a complex function, which will return an array of Chebyshev roots. 

Python3




# import chebyshev
from numpy.polynomial import chebyshev 
  
# create a complex variable
my_value = complex(4,5)
  
# display value
print("Complex value: ", my_value)
  
# generate chebyshev roots
print("chebyshev roots: ", chebyshev.chebfromroots((-my_value, my_value)))

Output:

Complex value:  (4+5j)
chebyshev roots:  [9.5-40.j 0.  +0.j 0.5 +0.j]

Example 2:

In this example, we will create a complex variable -> 45+4j and generate Chebyshev roots. We can also get the shape and dimensions of the resultant array using dim and shape functions.

Python3




# import chebyshev
from numpy.polynomial import chebyshev 
  
# create a complex variable
my_value = complex(45,4)
  
# display value
print("Complex value: ", my_value)
  
# generate chebyshev roots
print("chebyshev roots: ", chebyshev.chebfromroots(
  (-my_value, my_value)))
  
# get the dimensions
print("Dimensions: ", chebyshev.chebfromroots(
  (-my_value, my_value)).ndim)
  
# get the shape
print("shape: ",chebyshev.chebfromroots(
  (-my_value, my_value)).shape)

Output:

Complex value:  (45+4j)

chebyshev roots:  [-2.0085e+03-360.j  0.0000e+00  +0.j  5.0000e-01  +0.j]

Dimensions:  1

shape:  (3,)


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!