Convert a Legendre series to a polynomial in Python

In Python, you can convert a Legendre series to a polynomial using NumPy's polynomial.legendre.leg2poly() method. This function transforms Legendre series coefficients into standard polynomial coefficients.

Syntax

numpy.polynomial.legendre.leg2poly(c)

Parameters:

  • c: 1-D array containing Legendre series coefficients, ordered from lowest to highest degree

Returns: 1-D array of equivalent polynomial coefficients ordered from lowest to highest degree.

Example

Let's convert a Legendre series with coefficients [1, 2, 3, 4, 5] to its polynomial form ?

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

# Create Legendre series coefficients
coefficients = np.array([1, 2, 3, 4, 5])
print("Legendre series coefficients:", coefficients)

# Convert to polynomial
polynomial_coeffs = L.leg2poly(coefficients)
print("Polynomial coefficients:", polynomial_coeffs)

# Display array properties
print("\nArray dimensions:", coefficients.ndim)
print("Data type:", coefficients.dtype)
print("Shape:", coefficients.shape)
Legendre series coefficients: [1 2 3 4 5]
Polynomial coefficients: [ 1.375 -4.   -14.25  10.    21.875]

Array dimensions: 1
Data type: int64
Shape: (5,)

How It Works

The leg2poly() method converts Legendre polynomial coefficients to standard monomial basis. Each Legendre polynomial has a specific relationship to powers of x, so the conversion involves mathematical transformations based on Legendre polynomial properties.

Another Example

Converting a simple Legendre series with three coefficients ?

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

# Simple Legendre series: 1 + 2*P1(x) + 3*P2(x)
legendre_coeffs = [1, 2, 3]
print("Original Legendre coefficients:", legendre_coeffs)

# Convert to standard polynomial
poly_coeffs = L.leg2poly(legendre_coeffs)
print("Standard polynomial coefficients:", poly_coeffs)

# This represents: poly_coeffs[0] + poly_coeffs[1]*x + poly_coeffs[2]*x^2
Original Legendre coefficients: [1, 2, 3]
Standard polynomial coefficients: [-2.5  2.   4.5]

Conclusion

Use numpy.polynomial.legendre.leg2poly() to convert Legendre series coefficients to standard polynomial form. This is useful when you need to work with polynomials in their conventional representation after performing calculations in Legendre basis.

Updated on: 2026-03-26T20:44:04+05:30

307 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements