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 Laguerre series and set the derivatives in Python
To differentiate a Laguerre series, use the laguerre.lagder() method in Python. The method returns the Laguerre series coefficients differentiated m times along the specified axis. At each iteration, the result is multiplied by a scaling factor.
The argument c is an array of coefficients from low to high degree along each axis. For example, [1,2,3] represents the series 1*L? + 2*L? + 3*L?, while [[1,2],[1,2]] represents a two-dimensional series if axis=0 is x and axis=1 is y.
Syntax
numpy.polynomial.laguerre.lagder(c, m=1, scl=1, axis=0)
Parameters
| Parameter | Description | Default |
|---|---|---|
c |
Array of Laguerre series coefficients | Required |
m |
Number of derivatives taken (non-negative) | 1 |
scl |
Scalar multiplier for each differentiation | 1 |
axis |
Axis over which derivative is taken | 0 |
Basic Differentiation Example
Let's start with a simple example of differentiating a Laguerre series ?
import numpy as np
from numpy.polynomial import laguerre as L
# Create coefficients for series: 1*L_0 + 2*L_1 + 3*L_2 + 4*L_3
c = np.array([1, 2, 3, 4])
print("Original coefficients:", c)
# First derivative
result1 = L.lagder(c, m=1)
print("First derivative:", result1)
# Second derivative
result2 = L.lagder(c, m=2)
print("Second derivative:", result2)
# Third derivative
result3 = L.lagder(c, m=3)
print("Third derivative:", result3)
Original coefficients: [1 2 3 4] First derivative: [ 1. 1. 1.] Second derivative: [ 0. -2.] Third derivative: [-4.]
Using Scaling Factor
The scl parameter multiplies each differentiation by a scalar value ?
import numpy as np
from numpy.polynomial import laguerre as L
c = np.array([1, 2, 3, 4])
# Differentiate with scaling factor of 2
result_scaled = L.lagder(c, m=1, scl=2)
print("With scl=2:", result_scaled)
# Compare with normal differentiation
result_normal = L.lagder(c, m=1)
print("Normal:", result_normal)
print("Manual scaling:", result_normal * 2)
With scl=2: [2. 2. 2.] Normal: [1. 1. 1.] Manual scaling: [2. 2. 2.]
Multidimensional Arrays
For multidimensional coefficient arrays, specify the axis for differentiation ?
import numpy as np
from numpy.polynomial import laguerre as L
# Create a 2D array of coefficients
c_2d = np.array([[1, 2], [3, 4], [5, 6]])
print("2D coefficients:")
print(c_2d)
# Differentiate along axis 0 (rows)
result_axis0 = L.lagder(c_2d, axis=0)
print("\nDifferentiate along axis 0:")
print(result_axis0)
# Differentiate along axis 1 (columns)
result_axis1 = L.lagder(c_2d, axis=1)
print("\nDifferentiate along axis 1:")
print(result_axis1)
2D coefficients: [[1 2] [3 4] [5 6]] Differentiate along axis 0: [[ 2. 2.] [ 2. 2.]] Differentiate along axis 1: [[1.] [1.] [1.]]
Complete Example
Here's a comprehensive example showing array properties and differentiation ?
import numpy as np
from numpy.polynomial import laguerre as L
# Create an array of coefficients
c = np.array([1, 2, 3, 4])
print("Our Array...\n", c)
print("\nDimensions of our Array...\n", c.ndim)
print("\nDatatype of our Array object...\n", c.dtype)
print("\nShape of our Array object...\n", c.shape)
# Differentiate the Laguerre series three times
print("\nThird derivative result...\n", L.lagder(c, 3))
Our Array... [1 2 3 4] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (4,) Third derivative result... [-4.]
Conclusion
The laguerre.lagder() method efficiently differentiates Laguerre series with customizable order, scaling, and axis selection. Use the m parameter to control derivative order and scl for linear transformations.
