Raise a Legendre series to a power in Python

To raise a Legendre series to a power, use the polynomial.legendre.legpow() method in Python NumPy. The method returns the Legendre series c raised to the power pow. The argument c is a sequence of coefficients ordered from low to high. For example, [1,2,3] represents the series P? + 2*P? + 3*P?.

Syntax

numpy.polynomial.legendre.legpow(c, pow, maxpower=16)

Parameters

The function accepts the following parameters ?

  • c ? 1-D array of Legendre series coefficients ordered from low to high
  • pow ? Power to which the series will be raised
  • maxpower ? Maximum power allowed (default is 16) to limit growth of the series

Example

Let's create a Legendre series and raise it to a power ?

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

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

# Display the coefficient array
print("Our coefficient Array...\n", c)

# Check the dimensions
print("\nDimensions of our Array...\n", c.ndim)

# Get the datatype
print("\nDatatype of our Array object...\n", c.dtype)

# Get the shape
print("\nShape of our Array object...\n", c.shape)

# Raise the Legendre series to power 3
result = L.legpow(c, 3)
print("\nResult....\n", result)
Our coefficient Array...
 [1 2 3]

Dimensions of our Array...
 1

Datatype of our Array object...
 int64

Shape of our Array object...
 (3,)

Result....
 [16.74285714 42.17142857 55.14285714 46.4        33.8025974
 15.42857143  6.31168831]

Understanding the Result

The original series [1, 2, 3] represents P? + 2*P? + 3*P?. When raised to the power of 3, the resulting coefficients expand to a higher-degree polynomial with 7 terms.

Using Different Powers

Let's see how different powers affect the result ?

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

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

# Raise to different powers
power_2 = L.legpow(c, 2)
power_3 = L.legpow(c, 3)

print("Original coefficients:", c)
print("Power 2 result:", power_2)
print("Power 3 result:", power_3)
Original coefficients: [1 2]
Power 2 result: [1.66666667 5.33333333 2.66666667]
Power 3 result: [3.2        12.8         9.06666667  3.73333333]

Conclusion

The legpow() function efficiently raises Legendre series to specified powers. Higher powers result in expanded coefficient arrays representing higher-degree polynomials.

Updated on: 2026-03-26T20:40:49+05:30

197 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements