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
Raise a Chebyshev series to a power in Python
To raise a Chebyshev series to a power, use the chebyshev.chebpow() method in Python NumPy. This function returns the Chebyshev series c raised to the specified power. The argument c is a sequence of coefficients ordered from low to high, where [1,2,3] represents the series T_0 + 2*T_1 + 3*T_2.
Syntax
numpy.polynomial.chebyshev.chebpow(c, pow, maxpower=16)
Parameters
- c − 1-D array of Chebyshev series coefficients ordered from low to high
- pow − Power to which the series will be raised
- maxpower − Maximum power allowed (default is 16) to limit series growth
Example
Let's create a Chebyshev series and raise it to different powers ?
import numpy as np
from numpy.polynomial import chebyshev as C
# Create 1-D array of Chebyshev series coefficients
c = np.array([1, 2, 3])
print("Original coefficient array:", c)
print("Dimensions:", c.ndim)
print("Shape:", c.shape)
print("Datatype:", c.dtype)
# Raise to power 2
result_pow2 = C.chebpow(c, 2)
print("\nRaised to power 2:", result_pow2)
# Raise to power 3
result_pow3 = C.chebpow(c, 3)
print("Raised to power 3:", result_pow3)
Original coefficient array: [1 2 3] Dimensions: 1 Shape: (3,) Datatype: int64 Raised to power 2: [ 7.5 12. 18.5 12. 4.5] Raised to power 3: [ 22. 48. 85.5 78. 58.5 27. 13.5]
Understanding the Result
When a Chebyshev series is raised to a power, the resulting coefficients represent the new series. The number of coefficients increases as the degree of the polynomial increases with the power operation ?
import numpy as np
from numpy.polynomial import chebyshev as C
# Simple example with fewer coefficients
c_simple = np.array([1, 1]) # T_0 + T_1
print("Original series [1, 1] represents: T_0 + T_1")
print("Power 1:", C.chebpow(c_simple, 1))
print("Power 2:", C.chebpow(c_simple, 2))
print("Power 3:", C.chebpow(c_simple, 3))
Original series [1, 1] represents: T_0 + T_1 Power 1: [1. 1.] Power 2: [1.5 2. 0.5] Power 3: [2.5 3. 1.5 0.5]
Using maxpower Parameter
The maxpower parameter limits the maximum power to prevent unmanageable series growth ?
import numpy as np
from numpy.polynomial import chebyshev as C
c = np.array([1, 2])
# Default maxpower (16)
result_default = C.chebpow(c, 5)
print("Power 5 (default maxpower):", len(result_default), "coefficients")
# Custom maxpower
try:
result_custom = C.chebpow(c, 5, maxpower=3)
print("Power 5 (maxpower=3):", result_custom)
except ValueError as e:
print("Error with maxpower=3:", str(e))
Power 5 (default maxpower): 9 coefficients Error with maxpower=3: power too large
Conclusion
The chebpow() function efficiently raises Chebyshev series to any power while maintaining polynomial properties. Use the maxpower parameter to control computational complexity for large powers.
