Open In App
Related Articles

Integrate a Chebyshev series and set the order of integration using NumPy in Python

Improve Article
Improve
Save Article
Save
Like Article
Like

In this article, we will discuss how to integrate the Chebyshev series and set the order of integration in Python and NumPy.

chebyshev.chebint method

Chebyshev polynomials are significant in approximation theory because the Chebyshev nodes are used as matching points for optimizing polynomial interpolation. To perform Chebyshev Integration, NumPy provides a function called Chebyshev.chebint() method, which is used to integrate the Chebyshev series with a given order. It will take two parameters, the first is c which takes an array and, the second is m which is used to set the integration order.

Syntax: chebyshev.chebint(c,m)

Parameter:

  • c: an array
  • m: order of integration.

Return: Chebyshev series coefficients of the integral.

Example 1:

In this example, we will create a one-dimensional NumPy coefficient array with 6 elements and integrate the series by setting orders with 3,4,1, and 6.

Python3




# import the numpy module
import numpy
  
# import chebyshev
from numpy.polynomial import chebyshev
  
# Create an array of Chebyshev series 
# coefficients with 6 elements
coefficient_array = numpy.array([1,2,3,4,3,5])
  
# display array
print("Coefficient array: ", coefficient_array)
  
# display the dimensions
print("Dimensions: ", coefficient_array.ndim)
  
# integrate chebyshev series with order 3
print("\nChebyshev series with order 3"
      chebyshev.chebint(coefficient_array, m = 3))
  
# integrate chebyshev series with order 4
print("\nChebyshev series with order 4",
      chebyshev.chebint(coefficient_array, m = 4))
  
# integrate chebyshev series with order 1
print("\nChebyshev series with order 1",
      chebyshev.chebint(coefficient_array, m = 1))
  
# integrate chebyshev series with order 6
print("\nChebyshev series with order 6",
      chebyshev.chebint(coefficient_array, m = 6))

Output:

Coefficient array:  [1 2 3 4 3 5]

Dimensions:  1

Chebyshev series with order 3 [ 0.08072917  0.          0.08854167 -0.01458333 -0.00104167 -0.00625

 -0.00699405  0.00178571  0.00186012]

Chebyshev series with order 4 [ 0.00390625  0.03645833  0.00364583  0.01493056 -0.00104167  0.00059524

 -0.00066964 -0.00063244  0.00011161  0.00010334]

Chebyshev series with order 1 [ 0.04166667 -0.5        -0.5         0.         -0.125       0.3

  0.41666667]

Chebyshev series with order 6 [ 2.28949653e-04  1.05251736e-03  3.25520833e-04  5.98338294e-04

  1.02306548e-04  1.68960813e-04  1.55009921e-06  1.05923446e-05

 -3.87524802e-06 -2.84184854e-06  3.10019841e-07  2.34863516e-07]

Example 2:

In this example, we will create a two-dimensional NumPy coefficient array with 6 elements with shape 2×2 and, integrate the series by setting orders with 3,4,1, and 6.

Python3




# import the numpy module
import numpy
  
# import chebyshev
from numpy.polynomial import chebyshev
  
# Create an 2 D array of Chebyshev series 
# coefficients with 6 elements
coefficient_array = numpy.array([[1, 2, 3, 4, 3, 5], [5, 6, 8, 9, 0, 0]])
  
# display array
print("Coefficient array: ", coefficient_array)
  
# display the dimensions
print("Dimensions: ", coefficient_array.ndim)
  
# integrate chebyshev series with order 3
print("\nChebyshev series with order 3",
      chebyshev.chebint(coefficient_array, m=3))
  
# integrate chebyshev series with order 4
print("\nChebyshev series with order 4",
      chebyshev.chebint(coefficient_array, m=4))
  
# integrate chebyshev series with order 1
print("\nChebyshev series with order 1",
      chebyshev.chebint(coefficient_array, m=1))
  
# integrate chebyshev series with order 6
print("\nChebyshev series with order 6",
      chebyshev.chebint(coefficient_array, m=6))

Output:

Coefficient array:  [[1 2 3 4 3 5]

 [5 6 8 9 0 0]]

Dimensions:  2

Chebyshev series with order 3 [[0.078125   0.09375    0.125      0.140625   0.         0.        ]

 [0.125      0.25       0.375      0.5        0.375      0.625     ]

 [0.10416667 0.125      0.16666667 0.1875     0.         0.        ]

 [0.04166667 0.08333333 0.125      0.16666667 0.125      0.20833333]

 [0.02604167 0.03125    0.04166667 0.046875   0.         0.        ]]

Chebyshev series with order 4 [[0.015625   0.03125    0.046875   0.0625     0.046875   0.078125  ]

 [0.02604167 0.03125    0.04166667 0.046875   0.         0.        ]

 [0.02083333 0.04166667 0.0625     0.08333333 0.0625     0.10416667]

 [0.01302083 0.015625   0.02083333 0.0234375  0.         0.        ]

 [0.00520833 0.01041667 0.015625   0.02083333 0.015625   0.02604167]

 [0.00260417 0.003125   0.00416667 0.0046875  0.         0.        ]]

Chebyshev series with order 1 [[1.25 1.5  2.   2.25 0.   0.  ]

 [1.   2.   3.   4.   3.   5.  ]

 [1.25 1.5  2.   2.25 0.   0.  ]]

Chebyshev series with order 6 [[4.34027778e-04 8.68055556e-04 1.30208333e-03 1.73611111e-03

  1.30208333e-03 2.17013889e-03]

 [5.42534722e-04 6.51041667e-04 8.68055556e-04 9.76562500e-04

  0.00000000e+00 0.00000000e+00]

 [6.51041667e-04 1.30208333e-03 1.95312500e-03 2.60416667e-03

  1.95312500e-03 3.25520833e-03]

 [3.25520833e-04 3.90625000e-04 5.20833333e-04 5.85937500e-04

  0.00000000e+00 0.00000000e+00]

 [2.60416667e-04 5.20833333e-04 7.81250000e-04 1.04166667e-03

  7.81250000e-04 1.30208333e-03]

 [1.08506944e-04 1.30208333e-04 1.73611111e-04 1.95312500e-04

  0.00000000e+00 0.00000000e+00]

 [4.34027778e-05 8.68055556e-05 1.30208333e-04 1.73611111e-04

  1.30208333e-04 2.17013889e-04]

 [1.55009921e-05 1.86011905e-05 2.48015873e-05 2.79017857e-05

  0.00000000e+00 0.00000000e+00]]


Last Updated : 01 May, 2022
Like Article
Save Article
Similar Reads
Related Tutorials