Skip to content
Related Articles

Related Articles

Raise Chebyshev series to a power using NumPy in Python

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

In this article, we will cover how to raise a Chebyshev series to power in Python using NumPy.

polynomial.chebyshev.chebpow method

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)

Parameters:

  • 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.

Example 1:

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. 

Python3




# import packages
import numpy as np
from numpy.polynomial import chebyshev 
  
# Creating an array
array = np.array([3,1,4])
print(array)
  
# shape of the array is
print("Shape of the array is : ",array.shape)
  
# dimension of the array
print("The dimension of the array is : ",array.ndim)
  
# Datatype of the array
print("Datatype of our Array is : ",array.dtype)
  
# raising chebyshev series to the power 2
print(chebyshev.chebpow(array,2))

Output:

[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. ]

Example 2:

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”. 

Python3




# import packages
import numpy as np
from numpy.polynomial import chebyshev
  
# Creating an array
array = np.array([3,1,4])
print(array)
  
# shape of the array is
print("Shape of the array is : ",array.shape)
  
# dimension of the array
print("The dimension of the array is : ",array.ndim)
  
# Datatype of the array
print("Datatype of our Array is : ",array.dtype)
  
# raising chebyshev series to the power 2
print(chebyshev.chebpow(array,6,maxpower=5))

Output:

[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>()

     17 

     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([1], dtype=c.dtype)

ValueError: Power is too large


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!