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 Hermite series at points (x,y) with 1D array of coefficient in Python
To evaluate a 2D Hermite series at points (x, y), use the hermite.hermval2d() method in Python NumPy. The method returns the values of the two dimensional polynomial at points formed with pairs of corresponding values from x and y.
The first parameter contains x and y coordinates. 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. The second parameter, c, is an array of coefficients ordered so that the coefficient of the term of multi-degree i,j is contained in c[i,j].
Syntax
numpy.polynomial.hermite.hermval2d(x, y, c)
Parameters
x, y ? Arrays of point coordinates. If arrays, they must have the same shape.
c ? Array of coefficients ordered so that coefficient of term of multi-degree i,j is in c[i,j].
Example
Let's create a simple 1D coefficient array and evaluate the 2D Hermite series ?
import numpy as np
from numpy.polynomial import hermite as H
# Create a 1D array of coefficients
c = np.array([3, 5])
# Display the array
print("Coefficient Array:")
print(c)
# Check the dimensions
print("\nDimensions:", c.ndim)
print("Shape:", c.shape)
print("Datatype:", c.dtype)
# Evaluate 2D Hermite series at points (x, y)
result = H.hermval2d([1, 2], [1, 2], c)
print("\nResult at points (1,1) and (2,2):")
print(result)
Coefficient Array: [3 5] Dimensions: 1 Shape: (2,) Datatype: int64 Result at points (1,1) and (2,2): [ 59. 105.]
Working with 2D Coefficient Array
For a proper 2D Hermite series, we typically use a 2D coefficient array ?
import numpy as np
from numpy.polynomial import hermite as H
# Create a 2D coefficient array
c = np.array([[1, 2], [3, 4]])
print("2D Coefficient Array:")
print(c)
# Evaluate at multiple points
x = [0, 1, 2]
y = [0, 1, 2]
result = H.hermval2d(x, y, c)
print("\nEvaluation at points (0,0), (1,1), (2,2):")
print(result)
2D Coefficient Array: [[1 2] [3 4]] Evaluation at points (0,0), (1,1), (2,2): [ 1. 10. 149.]
How It Works
The hermval2d() function evaluates the 2D Hermite polynomial series using the formula:
P(x,y) = ??? c[i,j] * H?(x) * H?(y)
where H? and H? are Hermite polynomials of degrees i and j respectively.
Conclusion
Use numpy.polynomial.hermite.hermval2d() to evaluate 2D Hermite series at specified coordinate points. The function accepts coordinate arrays and coefficient arrays, returning polynomial values at each point pair.
