Integrate Legendre series and set the lower bound of the integral using NumPy in Python
Last Updated :
02 Jun, 2022
In this article, we will see how to integrate a Legendre series and set the lower bound of the integral in Python using NumPy.
To perform Legendre integration, NumPy provides a function called legendre.legint which can be used to integrate Legendre series.
Syntax: legendre.legint(c, lbnd=0, scl=1, axis=0)
Parameters:
c – Array of Legendre 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 an lbnd set to -2. 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 legendre
# 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 = legendre.legint(c, lbnd=-2)
# integrated legendre 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 ---> [220.5 8.4 2. 0.93333333 2.
1.66666667]
Example 2:
In this 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 legendre
# 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 = legendre.legint(c, lbnd=-1)
# integrated legendre 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 ---> [[ -7.66666667 -6.33333333 -1.66666667 -212. -14.66666667]
[ 11. 12. 13. 14. 15. ]
[ 18.66666667 18.33333333 14.66666667 226. 29.66666667]]
Similar Reads
Integrate a Chebyshev series and set the lower bound of the integral using NumPy in Python 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, sc
2 min read
Integrate a Chebyshev series and set the order of integration using NumPy in Python 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 interp
4 min read
Integrate a Legendre series over axis 0 using NumPy in Python In this article, we will cover how to integrate a Legendre series over axis 0 using NumPy in Python. polynomial.legendre.legint method The polynomial.legendre.legint() method from the NumPy library is used to Integrate a Legendre series over axis 0 in python.The resulting series is multiplied by scl
3 min read
Differentiate a Legendre series and set the derivatives using NumPy in Python In this article, we will cover how to differentiate a Legendre series and set the derivatives using NumPy in Python. numpy.polynomial.legendre.legder The numpy.polynomial.legendre.legder() method from the NumPy library is used to differentiate a Legendre series and set the derivatives in Python. The
3 min read
Differentiate a Legendre series using NumPy in Python In this article, we will cover how to differentiate a Legendre series in Python using NumPy. legendre.legder method In python, the Legendre module provides many functions like legder to perform arithmetic, and calculus operations on the Legendre series. It is one of the functions provided by the Leg
3 min read