Skip to content
Related Articles

Related Articles

Python NumPy – Convert a Polynomial to a Chebyshev series

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 25 Apr, 2022

In this article, we are going to see how to convert a polynomial to a Chebyshev series in Python using NumPy.

polynomial.chebyshev.poly2cheb() method

The polynomial.chebyshev.poly2cheb() method from the NumPy library converts a polynomial to a Chebyshev series in python. This method is used to Convert an array of coefficients reflecting a polynomial’s coefficients (arranged from lowest to highest degree to an array of coefficients expressing the corresponding Chebyshev series, arranged from lowest to the highest degree.

Syntax: polynomial.chebyshev.poly2cheb(pol):

parameters:

  • pol: array like object.The polynomial coefficients are stored in a 1-D array.

return:

  • c : ndarray. The coefficients of the analogous Chebyshev series are stored in a one-dimensional array.

Example 1:

In this example,  we created two arrays of numbers that represent a polynomial using the np.array() method. coefficients should go from low to high The shape of the array is defined by the .shape attribute and the dimension of the array is defined by .ndim, the datatype of the array is returned by the .dtype attribute. The chebyshev.poly2cheb()  method convert polynomial to Chebyshev series.

Python3




# import package
import numpy as np
 
# Creating an array represebting polynomial
array = np.array([11,22,33])
print(array)
 
# shape of the array is
print("Shape of the array1 is : ",array.shape)
 
# dimension of the array
print("The dimension of the array1 is : ",array.ndim)
 
# Datatype of the array
print("Datatype of our Array is : ",array.dtype)
 
# converting polynomial to chebyshev series
print("polynomial to chebyshev series : ",
      np.polynomial.chebyshev.poly2cheb(array))


Output:

[11 22 33]
Shape of the array1 is :  (3,)
The dimension of the array1 is :  1
Datatype of our Array is :  int64
polynomial to chebyshev series : [27.5 22.  16.5]

Example 2:

We can also use the polynomial.Polynomial.convert() method to convert a polynomial to Chebyshev series.

Python3




# import package
from numpy import polynomial as P
 
# converting polynomial to chebyshev series
poly = P.Polynomial(range(10))
print("polynomial to chebyshev series : ",
      poly.convert(kind=P.Chebyshev))


Output:

polynomial to chebyshev series :  cheb([ 6.5625     14.6328125   9.3125      7.5625      3.375       2.34375

  0.6875      0.42578125  0.0625      0.03515625])


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!