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 in Python
To differentiate a Chebyshev series, use the polynomial.chebder() method in NumPy. This method returns the Chebyshev series coefficients of the derivative. The coefficients are differentiated m times along the specified axis, with each iteration multiplied by a scale factor.
The argument c is an array of coefficients from low to high degree. For example, [1,2,3] represents the series 1*T_0 + 2*T_1 + 3*T_2, where T_n are Chebyshev polynomials.
Syntax
numpy.polynomial.chebyshev.chebder(c, m=1, scl=1, axis=0)
Parameters
The method accepts four parameters ?
- c ? Array of Chebyshev series coefficients
- m ? Number of derivatives taken, must be non-negative (Default: 1)
- scl ? Scale factor multiplied at each differentiation (Default: 1)
- axis ? Axis over which the derivative is taken (Default: 0)
Basic Example
Let's start with a simple example to differentiate a Chebyshev series ?
import numpy as np
from numpy.polynomial import chebyshev as C
# Create an array of Chebyshev series coefficients
c = np.array([1, 2, 3, 4])
print("Original coefficients:", c)
print("First derivative:", C.chebder(c))
print("Second derivative:", C.chebder(c, m=2))
Original coefficients: [1 2 3 4] First derivative: [14. 12. 24.] Second derivative: [24. 72.]
Using Scale Factor
The scale factor scl multiplies each differentiation, useful for variable transformations ?
import numpy as np
from numpy.polynomial import chebyshev as C
c = np.array([1, 2, 3, 4])
# Differentiate with scale factor of 2
result_scaled = C.chebder(c, scl=2)
print("With scale factor 2:", result_scaled)
# Compare with normal differentiation
result_normal = C.chebder(c)
print("Normal differentiation:", result_normal)
With scale factor 2: [28. 24. 48.] Normal differentiation: [14. 12. 24.]
Multidimensional Arrays
For multidimensional coefficients, you can specify which axis to differentiate along ?
import numpy as np
from numpy.polynomial import chebyshev as C
# 2D coefficient array
c_2d = np.array([[1, 2], [3, 4], [5, 6]])
print("Original 2D coefficients:")
print(c_2d)
# Differentiate along axis 0 (default)
result_axis0 = C.chebder(c_2d, axis=0)
print("\nDerivative along axis 0:")
print(result_axis0)
# Differentiate along axis 1
result_axis1 = C.chebder(c_2d, axis=1)
print("\nDerivative along axis 1:")
print(result_axis1)
Original 2D coefficients: [[1 2] [3 4] [5 6]] Derivative along axis 0: [[ 6. 8.] [20. 24.]] Derivative along axis 1: [[2.] [4.] [6.]]
Complete Example
Here's a comprehensive example showing array properties and differentiation ?
import numpy as np
from numpy.polynomial import chebyshev as C
# Create an array of Chebyshev series coefficients
c = np.array([1, 2, 3, 4])
# Display the coefficient array
print("Our coefficient 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 Chebyshev series
print("\nResult...")
print(C.chebder(c))
Our coefficient Array... [1 2 3 4] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (4,) Result... [14. 12. 24.]
Conclusion
The chebder() method efficiently computes derivatives of Chebyshev series by returning the differentiated coefficients. Use the m parameter for higher-order derivatives and scl for variable transformations.
