Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Differentiate a Legendre series with multidimensional coefficients over axis 1 in Python
To differentiate a Legendre series with multidimensional coefficients, use the polynomial.legendre.legder() method in Python. This method returns the Legendre series coefficients differentiated m times along the 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. For multidimensional arrays, 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 over which the derivative is taken (Default: 0)
Example: Differentiating over Axis 1
Let's create a multidimensional array and differentiate along axis 1 ?
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...\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)
# Differentiate the Legendre series along axis 1
print("\nResult (differentiated along axis 1)...\n",L.legder(c, axis=1))
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 (differentiated along axis 1)... [[1.] [3.]]
How It Works
When differentiating along axis 1, the function treats each row as a separate Legendre series. For a 2D array with shape (2,2), each row represents coefficients of a Legendre polynomial. The derivative of a Legendre series [a?, a?] along axis 1 gives [a?] scaled appropriately.
Example with Multiple Derivatives
You can also take multiple derivatives by specifying the m parameter ?
import numpy as np
from numpy.polynomial import legendre as L
# Create a larger coefficient array
c = np.arange(6).reshape(2,3)
print("Original array:\n", c)
# First derivative along axis 1
print("\nFirst derivative (m=1):\n", L.legder(c, m=1, axis=1))
# Second derivative along axis 1
print("\nSecond derivative (m=2):\n", L.legder(c, m=2, axis=1))
Original array: [[0 1 2] [3 4 5]] First derivative (m=1): [[1. 4.] [4. 10.]] Second derivative (m=2): [[4.] [10.]]
Conclusion
The legder() method efficiently differentiates Legendre series along any specified axis. Use axis=1 to differentiate each row independently, which is useful for handling multiple polynomial series simultaneously.
