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 and set the lower bound of the integral in Python
To integrate a Legendre series, use the polynomial.legendre.legint() method in Python. This method returns the Legendre series coefficients integrated m times from the lower bound (lbnd) along the specified axis. At each iteration, the resulting series is multiplied by a scaling factor and an integration constant is added.
Syntax
numpy.polynomial.legendre.legint(c, m=1, k=[], lbnd=0, scl=1, axis=0)
Parameters
| Parameter | Description | Default |
|---|---|---|
c |
Array of Legendre series coefficients | Required |
m |
Order of integration (must be positive) | 1 |
k |
Integration constant(s) | [] |
lbnd |
Lower bound of the integral | 0 |
scl |
Scaling factor | 1 |
axis |
Axis over which integration is taken | 0 |
Example
Let's integrate a Legendre series with coefficients [1, 2, 3] and set the lower bound to -2 ?
import numpy as np
from numpy.polynomial import legendre as L
# Create an array of coefficients
c = np.array([1, 2, 3])
# 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 with lower bound = -2
result = L.legint(c, lbnd=-2)
print("\nResult...")
print(result)
Our Array... [1 2 3] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (3,) Result... [7.33333333 0.4 0.66666667 0.6 ]
How It Works
When integrating a Legendre series with lbnd=-2:
- The original series has coefficients [1, 2, 3] representing: 1 + 2P?(x) + 3P?(x)
- Integration increases the degree by 1, resulting in 4 coefficients
- The lower bound
lbnd=-2determines the constant of integration - Each coefficient is adjusted based on the integration rules for Legendre polynomials
Different Lower Bounds
Let's see how different lower bounds affect the result ?
import numpy as np
from numpy.polynomial import legendre as L
c = np.array([1, 2, 3])
# Different lower bounds
bounds = [0, -1, -2, 1]
for bound in bounds:
result = L.legint(c, lbnd=bound)
print(f"lbnd = {bound}: {result}")
lbnd = 0: [-1.33333333 0.4 0.66666667 0.6 ] lbnd = -1: [ 3. 0.4 0.66666667 0.6 ] lbnd = -2: [7.33333333 0.4 0.66666667 0.6 ] lbnd = 1: [-5.66666667 0.4 0.66666667 0.6 ]
Conclusion
The legint() method integrates Legendre series coefficients, with the lbnd parameter controlling the lower bound of integration. Different lower bounds produce different constant terms while preserving the higher-order coefficients.
