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 and multiply each differentiation by a scalar in Python
To differentiate a Legendre series, use the polynomial.legendre.legder() method in Python. This function returns the Legendre series coefficients differentiated m times along axis, with each differentiation multiplied by a scalar.
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. Each differentiation is multiplied by scl, resulting in multiplication by scl**m (Default: 1)
- axis ? Axis over which the derivative is taken (Default: 0)
Basic Example
Let's start with a simple example to understand the basic functionality ?
import numpy as np
from numpy.polynomial import legendre as L
# Create an array of coefficients
coefficients = np.array([1, 2, 3, 4])
# Display the array
print("Original coefficients:", coefficients)
print("Shape:", coefficients.shape)
# Differentiate the Legendre series
result = L.legder(coefficients)
print("After differentiation:", result)
Original coefficients: [1 2 3 4] Shape: (4,) After differentiation: [ 6. 9. 20.]
Using Scalar Multiplication
Now let's see how the scalar parameter affects the differentiation ?
import numpy as np
from numpy.polynomial import legendre as L
coefficients = np.array([1, 2, 3, 4])
# Differentiate with scalar = -1
result_negative = L.legder(coefficients, scl=-1)
print("With scl = -1:", result_negative)
# Differentiate with scalar = 2
result_double = L.legder(coefficients, scl=2)
print("With scl = 2:", result_double)
# Multiple differentiations with scalar
result_multiple = L.legder(coefficients, m=2, scl=-1)
print("m=2, scl=-1:", result_multiple)
With scl = -1: [ -6. -9. -20.] With scl = 2: [12. 18. 40.] m=2, scl=-1: [18. 80.]
How It Works
The Legendre differentiation follows these rules ?
- Each coefficient is differentiated according to Legendre polynomial rules
- The scalar
sclmultiplies each differentiation step - For
mderivatives, the final result is multiplied byscl**m - This is useful for linear changes of variables
Comparison
| Parameters | Operation | Result |
|---|---|---|
| m=1, scl=1 | Standard differentiation | [ 6. 9. 20.] |
| m=1, scl=-1 | Differentiation × (-1) | [-6. -9. -20.] |
| m=2, scl=-1 | Two derivatives × (-1)² | [18. 80.] |
Conclusion
The legder() function provides flexible Legendre series differentiation with scalar multiplication. Use the scl parameter for linear transformations and m for multiple derivatives.
Advertisements
