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 Chebyshev series with multidimensional coefficients in Python
To differentiate a Chebyshev series with multidimensional coefficients, use the polynomial.chebder() method in NumPy. The method returns the Chebyshev series coefficients of the derivative, differentiated m times along a specified axis.
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*T_0 + 2*T_1 + 3*T_2 while [[1,2],[1,2]] represents 1*T_0(x)*T_0(y) + 1*T_1(x)*T_0(y) + 2*T_0(x)*T_1(y) + 2*T_1(x)*T_1(y) if axis=0 is x and axis=1 is y.
Syntax
numpy.polynomial.chebyshev.chebder(c, m=1, scl=1, axis=0)
Parameters
- c − Array of Chebyshev series coefficients. If multidimensional, different axes correspond to different variables
- m − Number of derivatives taken, must be non-negative (Default: 1)
- scl − Each differentiation is multiplied by scl. Final result is multiplied by scl**m (Default: 1)
- axis − Axis over which the derivative is taken (Default: 0)
Example
Let's differentiate a 2D Chebyshev series along different axes ?
import numpy as np
from numpy.polynomial import chebyshev as C
# Create a multidimensional array of Chebyshev series coefficients
c = np.arange(4).reshape(2,2)
# Display the coefficient array
print("Our coefficient Array...\n",c)
# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)
# Get the Shape
print("\nShape of our Array object...\n",c.shape)
# Differentiate along axis 0 (default)
print("\nDerivative along axis 0...\n",C.chebder(c))
# Differentiate along axis 1
print("\nDerivative along axis 1...\n",C.chebder(c, axis=1))
Our coefficient Array... [[0 1] [2 3]] Dimensions of our Array... 2 Shape of our Array object... (2, 2) Derivative along axis 0... [[2. 3.]] Derivative along axis 1... [[1.] [3.]]
Multiple Derivatives
You can take higher-order derivatives by specifying the m parameter ?
import numpy as np
from numpy.polynomial import chebyshev as C
# Create coefficients for a higher degree polynomial
c = np.arange(9).reshape(3,3)
print("Original coefficients...\n", c)
# First derivative
print("\nFirst derivative...\n", C.chebder(c, m=1))
# Second derivative
print("\nSecond derivative...\n", C.chebder(c, m=2))
Original coefficients... [[0 1 2] [3 4 5] [6 7 8]] First derivative... [[ 3. 4. 5.] [12. 14. 16.]] Second derivative... [[12. 14. 16.]]
Using Scale Factor
The scl parameter multiplies each differentiation step ?
import numpy as np
from numpy.polynomial import chebyshev as C
c = np.arange(6).reshape(2,3)
print("Original coefficients...\n", c)
# Differentiate with scale factor
print("\nWith scl=2...\n", C.chebder(c, scl=2))
# Compare with default scale
print("\nWith scl=1 (default)...\n", C.chebder(c, scl=1))
Original coefficients... [[0 1 2] [3 4 5]] With scl=2... [[6. 8.]] With scl=1 (default)... [[3. 4.]]
Conclusion
Use chebder() to differentiate multidimensional Chebyshev series along any axis. The m parameter controls derivative order, while scl applies scaling for variable transformations.
