Multiply one Legendre series to another in Python

To multiply one Legendre series with another, use the polynomial.legendre.legmul() method in NumPy. The method returns an array representing the Legendre series of their product. The arguments are sequences of coefficients ordered from lowest order term to highest, i.e., [1,2,3] represents the series P_0 + 2*P_1 + 3*P_2.

Syntax

numpy.polynomial.legendre.legmul(c1, c2)

Parameters

The parameters c1 and c2 are 1-D arrays of Legendre series coefficients ordered from low to high degree.

Example

Let's multiply two Legendre series using coefficient arrays ?

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

# Create 1-D arrays of Legendre series coefficients
c1 = np.array([2, 3, 4])
c2 = np.array([4, 3, 2])

# Display the arrays of coefficients
print("Array1:")
print(c1)
print("\nArray2:")
print(c2)

# Display the datatype
print("\nArray1 datatype:", c1.dtype)
print("Array2 datatype:", c2.dtype)

# Check the dimensions and shape
print("\nArray1 dimensions:", c1.ndim)
print("Array1 shape:", c1.shape)

print("\nArray2 dimensions:", c2.ndim)
print("Array2 shape:", c2.shape)

# Multiply the Legendre series
result = L.legmul(c1, c2)
print("\nResult (product):")
print(result)
Array1:
[2 3 4]

Array2:
[4 3 2]

Array1 datatype: int64
Array2 datatype: int64

Array1 dimensions: 1
Array1 shape: (3,)

Array2 dimensions: 1
Array2 shape: (3,)

Result (product):
[12.6        25.2        28.28571429 10.8         4.11428571]

How It Works

The legmul() function multiplies two Legendre series by convolving their coefficients according to the multiplication rules of Legendre polynomials. The resulting array has more coefficients than the input arrays because polynomial multiplication increases the degree.

In our example:

  • First series: 2*P_0 + 3*P_1 + 4*P_2
  • Second series: 4*P_0 + 3*P_1 + 2*P_2
  • Product: Results in a degree-4 polynomial with 5 coefficients

Conclusion

Use numpy.polynomial.legendre.legmul() to multiply Legendre series represented as coefficient arrays. The function handles the complex mathematics of Legendre polynomial multiplication and returns the product as a new coefficient array.

Updated on: 2026-03-26T20:39:31+05:30

189 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements