Integrate a Legendre series over axis 0 using NumPy in Python
Last Updated :
03 Jun, 2022
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 and an integration constant, k, is added at each iteration. The scaling factor is intended for usage in linear variable changes. The argument c is an array of coefficients ranging in degree from low to high along each axis, for example, [4,3,1] represents the series 4. If axis=0 is x and axis=1 is y, [[2,1],[2,1]] symbolises 2*L 0(x)*L 0(y) + 2*L 1(x)*L 0(y) + 1*L 0(x)*L 1(y) + 1*L 1(x)*L 1(y) + 1*L 1(x)*L 1(y) + 1*L
Syntax: polynomial.legendre.legint(c, m=1, scl=1, axis=0)
Parameters:
- c: array like object.
- m: int, optional value.The integration order must be positive. Standard value is 1.
- axis: optional value,int. The axis on which the integral is computed. The default value is 0.
Returns: Legendre series coefficient array of the integral.
Example 1:
Here, we will create a NumPy array and use polynomial.legendre.legint() to Integrate a Legendre series over axis 0 in python. The shape of the array is found by the .shape attribute, the dimension of the array is found by .ndim attribute, and the data type of the array is .dtype attribute. even if we don't specify by default axis is set to '0'.
Python3
# import packages
import numpy as np
from numpy.polynomial import legendre as L
# array of coefficients
array1 = np.array([1,2,3,4,5])
print(array1)
# shape of the array is
print("Shape of array1 is: ", array1.shape)
# dimension of the array
print("The dimension of array1 is: ", array1.ndim)
# datatype of the array
print("Datatype of Array1 is: ", array1.dtype)
# adding two hermite series along axis =0
print('Integrating the legendre series : ')
print(L.legint(array1,axis=0))
Output:
[1 2 3 4 5]
Shape of array1 is: (5,)
The dimension of array1 is: 1
Datatype of Array1 is: int64
Integrating the legendre series :
[-0.16666667 0.4 0.0952381 0.04444444 0.57142857 0.55555556]
Example 2:
In this example, we specify axis =1, which represents that we're integrating according to columns.
Python3
# import packages
import numpy as np
from numpy.polynomial import legendre as L
# array of coefficients
array1 = np.array([[1,2,3,4,5],[6,7,8,9,10]])
print(array1)
# shape of the array is
print("Shape of array1 is: ", array1.shape)
# dimension of the array
print("The dimension of array1 is: ", array1.ndim)
# datatype of the array
print("Datatype of Array1 is: ", array1.dtype)
# adding two hermite series
print('Integrating the legendre series : ')
print(L.legint(array1,axis=1))
Output:
[[ 1 2 3 4 5]
[ 6 7 8 9 10]]
Shape of array1 is: (2, 5)
The dimension of array1 is: 2
Datatype of Array1 is: int64
Integrating the legendre series :
[[-0.16666667 0.4 0.0952381 0.04444444 0.57142857 0.55555556]
[ 0.04166667 4.4 1.04761905 0.48888889 1.28571429 1.11111111]]
Similar Reads
Integrate a Hermite_e series Over Axis 0 using Numpy in Python In this article, we will cover how to integrate a Hermite_e series over axis 0 using NumPy in Python. NumPy e.hermeint() method We use the hermite e.hermeint() function present in the NumPy module of python to integrate a Hermite e series. The first parameter 'arr' is an array of coefficients from
2 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
Integrate Legendre series and set the lower bound of the integral using NumPy in Python 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, a
3 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
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