Raise Chebyshev series to a power using NumPy in Python
The Chebyshev polynomials are like the other classical orthogonal polynomials which can be defined from a variety of starting locations. Here, we will see how to raise a Chebyshev series to power in Python. The NumPy package provides us polynomial.chebyshev.chebpow() method to raise a Chebyshev series. Below is the syntax of the method:
Syntax: polynomial.chebyshev.chebpow(c, pow, maxpower=16)
- c: The coefficients of the chebyshev series are arranged in a 1-D array from low to high.
- pow: The series’ power will be increased according to the number specified.
- maxpower: by default it is 16. Maximum power is permitted.
Returns: an array of raised chebyshev series is returned.
Here, the NumPy package is imported and an array is created which represents the coefficients of the Chebyshev series. polynomial.chebyshev.chebpow() is used to raise the Chebyshev series, the pow parameter raises the Chebyshev series by power 2. and the shape, datatype, and dimension of the array are found by using the .shape, .dtype, and .ndim attributes.
[3 1 4] Shape of the array is : (3,) The dimension of the array is : 1 Datatype of our Array is : int64 [17.5 10. 24.5 4. 8. ]
In this example a new parameter maxpower is returned, it represents the maximum permitted power. we cannot give a value to the pow parameter which is greater than the max power, else a ValueError gets raised, saying “power is too large”.
[3 1 4]
Shape of the array is : (3,)
The dimension of the array is : 1
Datatype of our Array is : int64
ValueError Traceback (most recent call last)
<ipython-input-9-67269c531325> in <module>()
18 # raising chebyshev series to the power 2
—> 19 print(chebyshev.chebpow(array,6,maxpower=5))
/usr/local/lib/python3.7/dist-packages/numpy/polynomial/chebyshev.py in chebpow(c, pow, maxpower)
858 raise ValueError(“Power must be a non-negative integer.”)
859 elif maxpower is not None and power > maxpower:
–> 860 raise ValueError(“Power is too large”)
861 elif power == 0:
862 return np.array(, dtype=c.dtype)
ValueError: Power is too large