Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Integrate a Legendre series over axis 0 in Python
To integrate a Legendre series, use the polynomial.legendre.legint() method in Python. The method returns the Legendre series coefficients c integrated m times from lbnd along axis. At each iteration the resulting series is multiplied by scl and an integration constant, k, is added. The scaling factor is for use in a linear change of variable.
Syntax
numpy.polynomial.legendre.legint(c, m=1, k=[], lbnd=0, scl=1, axis=0)
Parameters
The function accepts the following parameters ?
- c ? An array of Legendre series coefficients. If c is multidimensional, different axes correspond to different variables.
- m ? Order of integration, must be positive (Default: 1).
- k ? Integration constant(s). If k == [] (default), all constants are set to zero.
- lbnd ? Lower bound of the integral (Default: 0).
- scl ? Scalar multiplier applied after each integration (Default: 1).
- axis ? Axis over which the integral is taken (Default: 0).
Example
Let's create a multidimensional array and integrate along axis 0 ?
import numpy as np
from numpy.polynomial import legendre as L
# Create a multidimensional array of coefficients
c = np.arange(4).reshape(2,2)
# Display the array
print("Our Array...")
print(c)
# Check the Dimensions
print("\nDimensions of our Array...")
print(c.ndim)
# Get the Datatype
print("\nDatatype of our Array object...")
print(c.dtype)
# Get the Shape
print("\nShape of our Array object...")
print(c.shape)
# Integrate the Legendre series along axis 0
print("\nResult...")
print(L.legint(c, axis=0))
Our Array... [[0 1] [2 3]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (2, 2) Result... [[0.33333333 0.5 ] [0. 1. ] [0.66666667 1. ]]
How It Works
When integrating a Legendre series along axis 0, the function increases the degree of the polynomial by 1. The original 2×2 array becomes a 3×2 array, where each column represents the integrated coefficients of the corresponding Legendre series.
Integration with Custom Parameters
You can specify integration order and bounds ?
import numpy as np
from numpy.polynomial import legendre as L
# Create coefficients
c = np.array([[1, 2], [3, 4]])
print("Original coefficients:")
print(c)
# Integrate twice with integration constant
result = L.legint(c, m=2, k=[1, 0.5], axis=0)
print("\nIntegrated twice with constants:")
print(result)
Original coefficients: [[1 2] [3 4]] Integrated twice with constants: [[1. 0.5 ] [0.33333333 0.66666667] [0. 1. ] [0.33333333 0.44444444] [0.2 0.26666667]]
Conclusion
The legint() function integrates Legendre series along specified axes, increasing polynomial degree by the integration order. Use the axis parameter to control which dimension to integrate over in multidimensional arrays.
