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 Hermite series at points (x,y,z) in Python
To evaluate a 3D Hermite series at points (x, y, z), use the hermite.hermval3d() method in NumPy. This method returns the values of the multidimensional polynomial on points formed with triples of corresponding values from x, y, and z coordinates.
Syntax
The basic syntax is ?
numpy.polynomial.hermite.hermval3d(x, y, z, c)
Parameters
The parameters are ?
- 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, otherwise it is left unchanged.
- c ? An array of coefficients ordered so that the coefficient of the term of multi-degree 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
Let's create a 3D coefficient array and evaluate the Hermite series at specific points ?
import numpy as np
from numpy.polynomial import hermite as H
# Create a 3d array of coefficients
c = np.arange(24).reshape(2, 2, 6)
# Display the coefficient array
print("Coefficient Array:")
print(c)
# Check the dimensions and shape
print(f"\nDimensions: {c.ndim}")
print(f"Shape: {c.shape}")
print(f"Datatype: {c.dtype}")
# Evaluate the 3D Hermite series at points (1,1,1) and (2,2,2)
result = H.hermval3d([1, 2], [1, 2], [1, 2], c)
print(f"\nEvaluating at points (1,1,1) and (2,2,2):")
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]]] Dimensions: 3 Shape: (2, 2, 6) Datatype: int64 Evaluating at points (1,1,1) and (2,2,2): [-4050. 52240.]
Different Point Combinations
You can evaluate the series at different combinations of x, y, z coordinates ?
import numpy as np
from numpy.polynomial import hermite as H
# Create coefficient array
c = np.arange(8).reshape(2, 2, 2)
print("Coefficient Array:")
print(c)
# Evaluate at single point
single_point = H.hermval3d(1, 1, 1, c)
print(f"\nAt point (1,1,1): {single_point}")
# Evaluate at multiple points
x_vals = [0, 1]
y_vals = [0, 1]
z_vals = [0, 1]
multiple_points = H.hermval3d(x_vals, y_vals, z_vals, c)
print(f"\nAt points (0,0,0) and (1,1,1): {multiple_points}")
Coefficient Array: [[[0 1] [2 3]] [[4 5] [6 7]]] At point (1,1,1): 28.0 At points (0,0,0) and (1,1,1): [ 0. 28.]
How It Works
The 3D Hermite series evaluation computes the polynomial value using the formula:
P(x,y,z) = ? ? ? c[i,j,k] * Hi(x) * Hj(y) * Hk(z)
Where Hn represents the nth Hermite polynomial. The coefficient array structure determines which terms are included in the series.
Conclusion
The hermval3d() function provides an efficient way to evaluate 3D Hermite series at specified coordinate points. It handles both single points and arrays of points, making it useful for mathematical modeling and polynomial approximations in three dimensions.
