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
Generate a Pseudo Vandermonde matrix of the Hermite polynomial with float array of points coordinates in Python
To generate a pseudo Vandermonde matrix of the Hermite polynomial, use the hermite.hermvander2d() method in Python NumPy. This method creates a 2D Vandermonde matrix where each row corresponds to a point coordinate and columns represent polynomial basis functions of varying degrees.
Syntax
numpy.polynomial.hermite.hermvander2d(x, y, deg)
Parameters
- x, y − Arrays of point coordinates with the same shape
- deg − List of maximum degrees [x_deg, y_deg]
Example
Let's create a pseudo Vandermonde matrix using float coordinate arrays ?
import numpy as np
from numpy.polynomial import hermite as H
# Create arrays of point coordinates
x = np.array([0.1, 1.4])
y = np.array([1.7, 2.8])
# Display the arrays
print("Array1...")
print(x)
print("\nArray2...")
print(y)
# Display the datatype
print("\nArray1 datatype:", x.dtype)
print("Array2 datatype:", y.dtype)
# Check the dimensions and shape
print("\nDimensions of Array1:", x.ndim)
print("Dimensions of Array2:", y.ndim)
print("\nShape of Array1:", x.shape)
print("Shape of Array2:", y.shape)
Array1... [0.1 1.4] Array2... [1.7 2.8] Array1 datatype: float64 Array2 datatype: float64 Dimensions of Array1: 1 Dimensions of Array2: 1 Shape of Array1: (2,) Shape of Array2: (2,)
Generate Pseudo Vandermonde Matrix
Now generate the matrix with degree [2, 3] for x and y respectively ?
import numpy as np
from numpy.polynomial import hermite as H
x = np.array([0.1, 1.4])
y = np.array([1.7, 2.8])
# Set degrees for x and y
x_deg, y_deg = 2, 3
# Generate pseudo Vandermonde matrix
result = H.hermvander2d(x, y, [x_deg, y_deg])
print("Pseudo Vandermonde Matrix:")
print(result)
print("\nMatrix shape:", result.shape)
Pseudo Vandermonde Matrix: [[ 1.0000000e+00 3.4000000e+00 9.5600000e+00 1.8904000e+01 2.0000000e-01 6.8000000e-01 1.9120000e+00 3.7808000e+00 -1.9600000e+00 -6.6640000e+00 -1.8737600e+01 -3.7051840e+01] [ 1.0000000e+00 5.6000000e+00 2.9360000e+01 1.4201600e+02 2.8000000e+00 1.5680000e+01 8.2208000e+01 3.9764480e+02 5.8400000e+00 3.2704000e+01 1.7146240e+02 8.2937344e+02]] Matrix shape: (2, 12)
How It Works
The matrix has dimensions (N, (x_deg+1)×(y_deg+1)) where N is the number of coordinate points. Each element represents the evaluation of Hermite polynomial basis functions at the given coordinates. The columns correspond to different polynomial terms of the form Hi(x) × Hj(y) where i ranges from 0 to x_deg and j ranges from 0 to y_deg.
Conclusion
The hermvander2d() function efficiently generates pseudo Vandermonde matrices for 2D Hermite polynomials. This is useful for polynomial fitting and interpolation in scientific computing applications.
