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 3-D Chebyshev series at points (x, y, z) with 4D array of coefficient in Python
To evaluate a 3-D Chebyshev series at points (x, y, z), use the polynomial.chebval3d() method in Python NumPy. The method returns the values of the multidimensional polynomial on points formed with triples of corresponding values from x, y, and z.
Syntax
numpy.polynomial.chebyshev.chebval3d(x, y, z, c)
Parameters
The function accepts the following parameters ?
- x, y, z ? The three dimensional series is evaluated at the points (x, y, z), where x, y, and z must have the same shape. If any of x, y, or z is a list or tuple, it is first converted to an ndarray.
- c ? Array of coefficients ordered so that the coefficient of the term of multidegree i,j,k is contained in c[i,j,k]. If c has dimension greater than 3, the remaining indices enumerate multiple sets of coefficients.
Example with 4D Coefficient Array
Let's create a 4D array of coefficients and evaluate the Chebyshev series at specific points ?
import numpy as np
from numpy.polynomial import chebyshev as C
# Create a 4D array of coefficients
c = np.arange(48).reshape(2, 2, 6, 2)
# Display the array
print("Coefficient Array:")
print(c)
# Check array properties
print("\nDimensions:", c.ndim)
print("Datatype:", c.dtype)
print("Shape:", c.shape)
# Evaluate 3-D Chebyshev series at points (x, y, z)
result = C.chebval3d([1, 2], [1, 2], [1, 2], c)
print("\nEvaluation Result:")
print(result)
Coefficient Array: [[[[ 0 1] [ 2 3] [ 4 5] [ 6 7] [ 8 9] [10 11]] [[12 13] [14 15] [16 17] [18 19] [20 21] [22 23]]] [[[24 25] [26 27] [28 29] [30 31] [32 33] [34 35]] [[36 37] [38 39] [40 41] [42 43] [44 45] [46 47]]]] Dimensions: 4 Datatype: int64 Shape: (2, 2, 6, 2) Evaluation Result: [[ 552. 148176.] [ 576. 152631.]]
Understanding the Output
The result is a 2×2 array because:
- We evaluated at 2 points: (1,1,1) and (2,2,2)
- The 4D coefficient array has 2 sets of coefficients in its last dimension
- Each evaluation point produces 2 values corresponding to the 2 coefficient sets
Simple Example
Here's a simpler example with a 3D coefficient array ?
import numpy as np
from numpy.polynomial import chebyshev as C
# Create a simple 3D coefficient array
coeff = np.array([[[1, 2], [3, 4]],
[[5, 6], [7, 8]]])
print("3D Coefficient Array Shape:", coeff.shape)
# Evaluate at a single point
result = C.chebval3d(0.5, 0.5, 0.5, coeff)
print("Result at point (0.5, 0.5, 0.5):", result)
# Evaluate at multiple points
x_vals = [0, 1]
y_vals = [0, 1]
z_vals = [0, 1]
result_multi = C.chebval3d(x_vals, y_vals, z_vals, coeff)
print("Results at multiple points:")
print(result_multi)
3D Coefficient Array Shape: (2, 2, 2) Result at point (0.5, 0.5, 0.5): 4.5 Results at multiple points: [1. 8.]
Conclusion
The chebval3d() function efficiently evaluates 3D Chebyshev series at specified points using coefficient arrays. When using 4D coefficient arrays, the extra dimension allows for multiple polynomial evaluations simultaneously.
