Open In App
Related Articles

Integrate a Chebyshev series and set the lower bound of the integral using NumPy in Python

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

In this article, we will see how to integrate a Chebyshev series and set the lower bound of the integral in Python using Numpy.

To perform Chebyshev integration, NumPy provides a function called chebyshev.chebint which can be used to integrate Legendre series.

Syntax: chebyshev.chebint(c, lbnd=0, scl=1, axis=0)

Parameters:

c – Array of Chebyshev series coefficients.
lbnd – The lower bound of the integral. (Default: 0) 
scl – Following each integration the result is multiplied by scl before the integration constant is added. (Default: 1)
axis – Axis over which the integral is taken.

Example 1:
In the first example. let us consider a 1D array with 5 elements with a lbnd set to -2. Import the necessary packages as shown and pass the appropriate parameters as shown below. We are also displaying shape, dimensions, and data type of created numpy array.

Python3

import numpy as np
from numpy.polynomial import chebyshev
  
# co.efficient array
c = np.array([11, 12, 13, 14, 15])
  
print(f'The shape of the array is {c.shape}')
print(f'The dimension of the array is {c.ndim}D')
print(f'The datatype of the array is {c.dtype}')
  
res = chebyshev.chebint(c, lbnd=-2)
  
# integrated chebyshev series
# with  lbnd=-2
print(f'Resultant series ---> {res}')

                    

Output:

The shape of the array is (5,)

The dimension of the array is 1D

The datatype of the array is int64

Resultant series —> [ 3.77083333e+02  4.50000000e+00 -5.00000000e-01 -3.33333333e-01

  1.75000000e+00  1.50000000e+00]

Example 2:

In the first example. let us consider a 2D array with 5 elements each with a lbnd set to -1. Import the necessary packages as shown and pass the appropriate parameters as shown below. We are also displaying the shape, dimensions, and data type of created NumPy array.

Python3

import numpy as np
from numpy.polynomial import chebyshev
  
# co.efficient array
c = np.array([[11, 12, 13, 14, 15], [56, 55, 44, 678, 89]])
  
print(f'The shape of the array is {c.shape}')
print(f'The dimension of the array is {c.ndim}D')
print(f'The datatype of the array is {c.dtype}')
  
res = chebyshev.chebint(c, lbnd=-1)
  
# integrated chebyshev series
# with  lbnd=-1
print(f'Resultant series ---> {res}')

                    

Output:

The shape of the array is (2, 5)

The dimension of the array is 2D

The datatype of the array is int64

Resultant series —> [[  -3.     -1.75    2.   -155.5    -7.25]

 [  11.     12.     13.     14.     15.  ]

 [  14.     13.75   11.    169.5    22.25]]



Last Updated : 02 Jun, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads