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 2-D Chebyshev series at points (x, y) in Python
To evaluate a 2-D Chebyshev series at points (x, y), use the polynomial.chebval2d() method in Python NumPy. The method returns the values of the two-dimensional Chebyshev series at points formed from pairs of corresponding values from x and y. The two-dimensional series is evaluated at the points (x, y), where x and y must have the same shape. If x or y is a list or tuple, it is first converted to an ndarray, otherwise it is left unchanged.
The parameter c is an array of coefficients ordered so that the coefficient of the term of multidegree i,j is contained in c[i,j]. If c has dimension greater than 2, the remaining indices enumerate multiple sets of coefficients.
Syntax
numpy.polynomial.chebyshev.chebval2d(x, y, c)
Parameters
- x, y ? Points at which to evaluate the series. Must have the same shape.
- c ? Array of coefficients ordered so that c[i,j] is the coefficient of the term of multidegree i,j.
Example
Let's create a 2D coefficient matrix and evaluate the Chebyshev series at specific 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("Coefficient matrix:")
print(c)
# Check the properties
print("\nDimensions:", c.ndim)
print("Datatype:", c.dtype)
print("Shape:", c.shape)
# Evaluate 2-D Chebyshev series at points (x, y)
result = C.chebval2d([1, 2], [1, 2], c)
print("\nEvaluating at points (1,1) and (2,2):")
print(result)
Coefficient matrix: [[0 1] [2 3]] Dimensions: 2 Datatype: int64 Shape: (2, 2) Evaluating at points (1,1) and (2,2): [ 6. 18.]
How It Works
The Chebyshev series evaluation uses the coefficient matrix where c[i,j] represents the coefficient for the term T_i(x) * T_j(y), where T_i and T_j are Chebyshev polynomials of the first kind.
import numpy as np
from numpy.polynomial import chebyshev as C
# Different coefficient matrix
c = np.array([[1, 0], [0, 2]])
print("Coefficient matrix:")
print(c)
# Evaluate at multiple points
x_points = [0, 0.5, 1]
y_points = [0, 0.5, 1]
result = C.chebval2d(x_points, y_points, c)
print(f"\nEvaluating at points: {list(zip(x_points, y_points))}")
print("Results:", result)
Coefficient matrix: [[1 0] [0 2]] Evaluating at points: [(0, 0), (0.5, 0.5), (1, 1)] Results: [1. 1.5 3. ]
Conclusion
The chebval2d() function efficiently evaluates 2D Chebyshev series using coefficient matrices. It's particularly useful in numerical analysis and approximation theory for evaluating polynomial surfaces at multiple coordinate pairs.
