Differentiate a Legendre series with multidimensional coefficients in Python

To differentiate a Legendre series with multidimensional coefficients, use the polynomial.legendre.legder() method in Python. This function returns the Legendre series coefficients differentiated m times along a specified axis.

Syntax

numpy.polynomial.legendre.legder(c, m=1, 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 ? Number of derivatives taken, must be non-negative (Default: 1)
  • scl ? Scalar multiplier for each differentiation. Final result is multiplied by scl**m (Default: 1)
  • axis ? Axis along which the derivative is taken (Default: 0)

Example

Let's differentiate a Legendre series with multidimensional coefficients ?

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

# Create a multidimensional array of coefficients
c = np.arange(4).reshape(2,2)

# Display the array
print("Our Array...")
print(c)

# Check the Dimensions
print("\nDimensions of our Array...")
print(c.ndim)

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

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

# Differentiate the Legendre series
print("\nResult...")
print(L.legder(c))
Our Array...
[[0 1]
 [2 3]]

Dimensions of our Array...
2

Datatype of our Array object...
int64

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

Result...
[[2. 3.]]

How It Works

The differentiation reduces the degree along the specified axis. In our example, the original 2×2 array represents Legendre series coefficients, and after differentiation along axis 0 (default), we get a 1×2 result because the derivative eliminates the constant term and shifts the remaining coefficients.

Different Axis Example

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

# Create a larger multidimensional array
c = np.arange(6).reshape(2,3)
print("Original array:")
print(c)

# Differentiate along axis 0 (default)
print("\nDifferentiation along axis 0:")
print(L.legder(c, axis=0))

# Differentiate along axis 1
print("\nDifferentiation along axis 1:")
print(L.legder(c, axis=1))
Original array:
[[0 1 2]
 [3 4 5]]

Differentiation along axis 0:
[[3. 4. 5.]]

Differentiation along axis 1:
[[1. 4.]
 [4. 10.]]

Conclusion

The legder() function efficiently differentiates Legendre series with multidimensional coefficients. Use the axis parameter to control which dimension to differentiate along, and m to specify the order of differentiation.

Updated on: 2026-03-26T20:50:29+05:30

197 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements