Integrate a Legendre series and set the order of integration in Python

To integrate a Legendre series, use the polynomial.legendre.legint() method in Python. The method returns the Legendre series coefficients integrated m times from lbnd along axis. At each iteration the resulting series is multiplied by scl and an integration constant k is added.

Syntax

numpy.polynomial.legendre.legint(c, m=1, k=[], lbnd=0, scl=1, axis=0)

Parameters

The parameters for legint() method are ?

  • c ? 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). The value of the first integral at lbnd is the first value in the list (Default: [])
  • lbnd ? Lower bound of the integral (Default: 0)
  • scl ? Scalar multiplied after each integration before adding the integration constant (Default: 1)
  • axis ? Axis over which the integral is taken (Default: 0)

Basic Integration Example

Let's start with a simple integration of a Legendre series ?

import numpy as np
from numpy.polynomial import legendre as L

# Create an array of coefficients
c = np.array([1, 2, 3])
print("Original coefficients:", c)

# Basic integration (m=1)
result = L.legint(c)
print("Integrated once:", result)
Original coefficients: [1 2 3]
Integrated once: [0.         1.         0.66666667 1.        ]

Setting Integration Order

Use the parameter m to specify the order of integration ?

import numpy as np
from numpy.polynomial import legendre as L

# Create an array of coefficients
c = np.array([1, 2, 3])
print("Original coefficients:", c)

# Display array properties
print("Dimensions:", c.ndim)
print("Datatype:", c.dtype)
print("Shape:", c.shape)

# Integrate with different orders
print("\nIntegration order m=1:")
print(L.legint(c, m=1))

print("\nIntegration order m=2:")
print(L.legint(c, m=2))

print("\nIntegration order m=3:")
print(L.legint(c, m=3))
Original coefficients: [1 2 3]
Dimensions: 1
Datatype: int64
Shape: (3,)

Integration order m=1:
[0.         1.         0.66666667 1.        ]

Integration order m=2:
[0.         0.         0.5        0.22222222 0.25      ]

Integration order m=3:
[ 1.66666667e-02 -1.78571429e-02  4.76190476e-02 -1.73472348e-18
  1.90476190e-02  9.52380952e-03]

Using Integration Constants

Specify integration constants with the k parameter ?

import numpy as np
from numpy.polynomial import legendre as L

c = np.array([1, 2, 3])

# Integration with constant
result_with_k = L.legint(c, m=1, k=[5])
print("With integration constant k=5:")
print(result_with_k)

# Integration with multiple constants for higher order
result_multi_k = L.legint(c, m=2, k=[1, 2])
print("\nWith constants k=[1, 2] for m=2:")
print(result_multi_k)
With integration constant k=5:
[5.         1.         0.66666667 1.        ]

With constants k=[1, 2] for m=2:
[1.         2.         0.5        0.22222222 0.25      ]

Comparison

Parameter Purpose Default
m Integration order 1
k Integration constants [] (zeros)
lbnd Lower bound 0
scl Scaling factor 1

Conclusion

Use numpy.polynomial.legendre.legint() to integrate Legendre series with customizable order and constants. The m parameter controls integration order, while k sets integration constants for more precise control over the result.

Updated on: 2026-03-26T21:09:35+05:30

224 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements