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
Evaluate a Chebyshev series at points x when coefficients are multi-dimensional in Python
To evaluate a Chebyshev series at points x with multi-dimensional coefficients, use the chebyshev.chebval() method in NumPy. This method handles coefficient arrays where each column represents a different polynomial series.
Syntax
numpy.polynomial.chebyshev.chebval(x, c, tensor=True)
Parameters
x: Points at which to evaluate the series. Can be scalar, list, or array.
c: Array of coefficients. For multi-dimensional arrays, each column represents a separate polynomial.
tensor: If True (default), evaluates every column of coefficients for every element of x. If False, broadcasts x over the columns.
Example
Let's create a 2D coefficient array and evaluate Chebyshev series at multiple points ?
import numpy as np
from numpy.polynomial import chebyshev as C
# Create a multidimensional array of coefficients
c = np.arange(4).reshape(2,2)
# Display the array
print("Our Array...")
print(c)
# Check the dimensions and shape
print("\nDimensions:", c.ndim)
print("Datatype:", c.dtype)
print("Shape:", c.shape)
# Evaluate Chebyshev series at points [1, 2]
result = C.chebval([1, 2], c, tensor=True)
print("\nResult (chebval)...")
print(result)
Our Array... [[0 1] [2 3]] Dimensions: 2 Datatype: int64 Shape: (2, 2) Result (chebval)... [[2. 4.] [4. 7.]]
How It Works
The coefficient array has shape (2, 2), representing two polynomials:
− First polynomial: coefficients [0, 2]
− Second polynomial: coefficients [1, 3]
For each point x, the Chebyshev series is evaluated as: c[0] + c[1]*T?(x), where T?(x) is the first Chebyshev polynomial.
Different Tensor Values
import numpy as np
from numpy.polynomial import chebyshev as C
c = np.arange(6).reshape(3,2)
x = [1, 2]
print("Coefficients:")
print(c)
print("\nWith tensor=True:")
print(C.chebval(x, c, tensor=True))
print("\nWith tensor=False:")
print(C.chebval(x, c, tensor=False))
Coefficients: [[0 1] [2 3] [4 5]] With tensor=True: [[ 6. 10.] [12. 18.]] With tensor=False: [ 6. 18.]
Conclusion
Use chebval() with multi-dimensional coefficients to evaluate multiple Chebyshev series simultaneously. The tensor parameter controls how the evaluation is broadcast across coefficient columns.
