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 Vandermonde matrix of the Hermite polynomial with float array of points in Python
To generate a Vandermonde matrix of the Hermite polynomial, use the hermvander() function from NumPy's polynomial module. The method returns the pseudo-Vandermonde matrix where each row contains the Hermite polynomial basis functions evaluated at the corresponding point.
The shape of the returned matrix is x.shape + (deg + 1,), where the last index corresponds to the degree of the Hermite polynomial. The x parameter is an array of points (converted to float64 or complex128), and deg is the degree of the resulting matrix.
Syntax
numpy.polynomial.hermite.hermvander(x, deg)
Parameters
x: Array of points. If scalar, converted to 1-D array
deg: Degree of the resulting Vandermonde matrix
Example
Here's how to generate a Vandermonde matrix of Hermite polynomials with degree 2 ?
import numpy as np
from numpy.polynomial import hermite as H
# Create an array of points
x = np.array([0, 3.5, -1.4, 2.5])
# Display the array
print("Our Array...")
print(x)
# Check array properties
print("\nDimensions of our Array...")
print(x.ndim)
print("\nDatatype of our Array object...")
print(x.dtype)
print("\nShape of our Array object...")
print(x.shape)
# Generate Vandermonde matrix of Hermite polynomial with degree 2
print("\nVandermonde matrix (degree 2)...")
result = H.hermvander(x, 2)
print(result)
Our Array... [ 0. 3.5 -1.4 2.5] Dimensions of our Array... 1 Datatype of our Array object... float64 Shape of our Array object... (4,) Vandermonde matrix (degree 2)... [[ 1. 0. -2. ] [ 1. 7. 47. ] [ 1. -2.8 5.84] [ 1. 5. 23. ]]
How It Works
Each column represents Hermite polynomials of increasing degree:
- Column 0: H?(x) = 1 (degree 0)
- Column 1: H?(x) = 2x (degree 1)
- Column 2: H?(x) = 4x² - 2 (degree 2)
For example, at point x = 3.5: H?(3.5) = 1, H?(3.5) = 7, H?(3.5) = 47
Conclusion
The hermvander() function efficiently creates Vandermonde matrices for Hermite polynomial fitting and interpolation. Each row contains polynomial basis functions evaluated at the corresponding input point, making it useful for polynomial regression and numerical analysis.
