Integrate a Legendre series 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.

Syntax

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

Parameters

The function accepts the following parameters:

  • c: Array of Legendre series coefficients. If multidimensional, different axes correspond to different variables
  • m: Order of integration, must be positive (Default: 1)
  • k: Integration constant(s). If empty list (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)

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
coefficients = np.array([1, 2, 3])
print("Original coefficients:", coefficients)

# Integrate once
result = L.legint(coefficients)
print("Integrated once:", result)
Original coefficients: [1 2 3]
Integrated once: [0.         0.33333333 0.4        0.42857143]

Multiple Integration with Scaling

Here's an example with multiple integration and scaling factor ?

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

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

# Integrate twice with scaling factor -1
result = L.legint(coefficients, m=2, scl=-1)
print("Integrated twice with scl=-1:", result)
print("Result shape:", result.shape)
Original coefficients: [1 2 3]
Integrated twice with scl=-1: [-0.00833333  0.2         0.04761905  0.13333333  0.08571429]
Result shape: (5,)

Integration with Constants

You can specify integration constants using the k parameter ?

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

coefficients = np.array([1, 2, 3])
print("Original coefficients:", coefficients)

# Integration with constant
result_with_constant = L.legint(coefficients, k=1.5)
print("With integration constant k=1.5:", result_with_constant)

# Multiple integration with constants
result_multiple = L.legint(coefficients, m=2, k=[1, 2])
print("Two integrations with k=[1,2]:", result_multiple)
Original coefficients: [1 2 3]
With integration constant k=1.5: [1.5        0.33333333 0.4        0.42857143]
Two integrations with k=[1,2]: [1.00833333 2.2        0.04761905 0.13333333 0.08571429]

How It Works

The Legendre integration process works by:

  • Converting each Legendre polynomial coefficient to its antiderivative
  • Applying the scaling factor scl after each integration
  • Adding integration constants at the specified lower bound lbnd
  • Repeating the process m times for multiple integration

Conclusion

The legint() method provides flexible integration of Legendre series with support for multiple integration, scaling factors, and integration constants. Use appropriate parameters based on your mathematical requirements for Legendre polynomial integration.

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

372 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements