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
Selected Reading
Differentiate a Legendre series, set the derivatives and multiply each differentiation by a scalar in Python
To differentiate a Legendre series in Python, use the polynomial.legendre.legder() method. This function returns the Legendre series coefficients differentiated m times along the specified axis, with each differentiation multiplied by a scalar value.
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 to take (must be non-negative, default: 1)
- scl − Scalar multiplier applied to each differentiation (default: 1). Final result is multiplied by scl**m
- axis − Axis along which the derivative is computed (default: 0)
Example
Let's differentiate a Legendre series with custom derivative count and scalar multiplier:
import numpy as np
from numpy.polynomial import legendre as L
# Create an array of coefficients
c = np.array([1, 2, 3, 4])
# 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 twice with scalar multiplier -1
print("\nResult...")
print(L.legder(c, m=2, scl=-1))
Our Array... [1 2 3 4] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (4,) Result... [ 9. 60.]
How It Works
In the example above:
- We start with coefficients
[1, 2, 3, 4]representing a Legendre series - The function differentiates twice (
m=2) - Each differentiation is multiplied by
scl=-1 - The final result is multiplied by
(-1)²=1, but the differentiation process transforms the coefficients
Conclusion
The legder() function provides a convenient way to differentiate Legendre series with custom derivative orders and scalar multipliers. Use the scl parameter for linear variable transformations and m to control the differentiation order.
Advertisements
