Compute the roots of a Chebyshev series using NumPy in Python
Last Updated :
25 Jul, 2022
This article will discuss how to compute the roots of a Chebyshev series in NumPy using Python.
Chebyshev polynomials are important in approximation theory these are never formally generated. Only the coefficients are required for all calculations. If we want to compute the roots of a polynomial we have to use the chebyshev.chebroots() method in NumPy module available in python which returns an array that contains the series of roots. Out is real if all the roots are real; otherwise, it is complex. The c parameter is a one-dimensional array of coefficients.
Syntax: chebyshev.chebroots((integers))
- integers are the sequence of numbers separated by a comma.
Return:
It will return an array of the roots of the given series of integers. If all the roots are real, then output is also real, otherwise the output is complex.
Example 1
In this example. we will import the Chebyshev module to create regular series with 5 integers and get the roots, data type, and shape.
Python3
from numpy.polynomial import chebyshev
print (chebyshev.chebroots(( - 1 , 0 , 1 , 2 , 3 )))
print (chebyshev.chebroots(( - 1 , 0 , 1 , 2 , 3 )).dtype)
print (chebyshev.chebroots(( - 1 , 0 , 1 , 2 , 3 )).shape)
|
Output:
[-0.96766052 -0.39810338 0.11832406 0.9141065 ]
float64
(4,)
Example 2
In this example. we will import the Chebyshev module to create complex series with 2 data and get the roots, data type, and shape.
Python3
from numpy.polynomial import chebyshev
import cmath
print (chebyshev.chebroots(( complex ( 1 , 2 ),
complex ( 2 , 3 ))))
print (chebyshev.chebroots(( complex ( 1 , 2 ),
complex ( 2 , 3 ))).shape)
print (chebyshev.chebroots(( complex ( 1 , 2 ),
complex ( 2 , 3 ))).dtype)
|
Output:
[-0.61538462-0.07692308j]
(1,)
complex128
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...