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
Convert a polynomial to a Chebyshev series in Python
To convert a polynomial to a Chebyshev series, use the chebyshev.poly2cheb() method in Python NumPy. This method converts an array representing polynomial coefficients (ordered from lowest degree to highest) to an array of coefficients for the equivalent Chebyshev series.
Syntax
numpy.polynomial.chebyshev.poly2cheb(pol)
Parameters
pol ? A 1-D array containing polynomial coefficients ordered from lowest to highest degree.
Return Value
Returns a 1-D array containing the coefficients of the equivalent Chebyshev series, ordered from lowest to highest degree.
Example
Let's convert a polynomial with coefficients [1, 2, 3, 4, 5] to its Chebyshev series representation ?
import numpy as np
from numpy import polynomial as P
# Create polynomial coefficients array
coefficients = np.array([1, 2, 3, 4, 5])
# Display the original polynomial coefficients
print("Original polynomial coefficients:")
print(coefficients)
# Check array properties
print("\nArray dimensions:", coefficients.ndim)
print("Array datatype:", coefficients.dtype)
print("Array shape:", coefficients.shape)
# Convert polynomial to Chebyshev series
chebyshev_coeffs = P.chebyshev.poly2cheb(coefficients)
print("\nChebyshev series coefficients:")
print(chebyshev_coeffs)
Original polynomial coefficients: [1 2 3 4 5] Array dimensions: 1 Array datatype: int64 Array shape: (5,) Chebyshev series coefficients: [4.375 5. 4. 1. 0.625]
Understanding the Conversion
The polynomial p(x) = 1 + 2x + 3x² + 4x³ + 5x? is converted to a Chebyshev series T(x) = 4.375T?(x) + 5T?(x) + 4T?(x) + 1T?(x) + 0.625T?(x), where T?(x) are Chebyshev polynomials of the first kind.
Example with Simple Polynomial
Let's see the conversion for a simpler quadratic polynomial ?
import numpy as np
from numpy import polynomial as P
# Simple quadratic: 1 + x + x²
simple_poly = np.array([1, 1, 1])
print("Polynomial coefficients [1, 1, 1] represents: 1 + x + x²")
print("Chebyshev series coefficients:")
print(P.chebyshev.poly2cheb(simple_poly))
Polynomial coefficients [1, 1, 1] represents: 1 + x + x² Chebyshev series coefficients: [1.5 1. 0.5]
Conclusion
The poly2cheb() function efficiently converts standard polynomial coefficients to Chebyshev series representation. This is useful in numerical analysis where Chebyshev polynomials provide better approximation properties and numerical stability.
