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
Convert a Hermite series to a polynomial in Python
To convert a Hermite series to a polynomial, use the hermite.herm2poly() method in Python NumPy. This method converts an array representing the coefficients of a Hermite series, ordered from lowest degree to highest, to an array of the coefficients of the equivalent polynomial (relative to the "standard" basis) ordered from lowest to highest degree.
The method returns a 1-D array containing the coefficients of the equivalent polynomial (relative to the "standard" basis) ordered from lowest order term to highest. The parameter c is a 1-D array containing the Hermite series coefficients, ordered from lowest order term to highest.
Syntax
numpy.polynomial.hermite.herm2poly(c)
Parameters
c − 1-D array containing the Hermite series coefficients, ordered from lowest order term to highest.
Example
Let's convert a simple Hermite series to polynomial coefficients ?
import numpy as np
from numpy.polynomial import hermite as H
# Create an array of Hermite series coefficients
c = np.array([1, 2, 3, 4, 5])
# Display the array
print("Hermite series coefficients:")
print(c)
# Check the dimensions and shape
print("\nDimensions:", c.ndim)
print("Shape:", c.shape)
print("Datatype:", c.dtype)
# Convert Hermite series to polynomial
result = H.herm2poly(c)
print("\nPolynomial coefficients:")
print(result)
Hermite series coefficients: [1 2 3 4 5] Dimensions: 1 Shape: (5,) Datatype: int64 Polynomial coefficients: [ 55. -44. -228. 32. 80.]
How It Works
The Hermite series with coefficients [1, 2, 3, 4, 5] represents:
1×H?(x) + 2×H?(x) + 3×H?(x) + 4×H?(x) + 5×H?(x)
Where H?, H?, H?, H?, H? are Hermite polynomials. The herm2poly() method converts this to standard polynomial form with coefficients [55, -44, -228, 32, 80].
Another Example
Let's see the conversion with a simpler coefficient array ?
import numpy as np
from numpy.polynomial import hermite as H
# Simple Hermite series: 1 + 2*H?(x)
coeffs = np.array([1, 2])
print("Hermite coefficients:", coeffs)
# Convert to polynomial
poly_coeffs = H.herm2poly(coeffs)
print("Polynomial coefficients:", poly_coeffs)
# Another example: 3*H?(x)
coeffs2 = np.array([0, 0, 3])
print("\nHermite coefficients:", coeffs2)
poly_coeffs2 = H.herm2poly(coeffs2)
print("Polynomial coefficients:", poly_coeffs2)
Hermite coefficients: [1 2] Polynomial coefficients: [1. 4.] Hermite coefficients: [0 0 3] Polynomial coefficients: [-6. 0. 12.]
Conclusion
The hermite.herm2poly() method efficiently converts Hermite series coefficients to standard polynomial coefficients. This is useful for mathematical computations where you need to work with polynomials in their standard form rather than Hermite basis representation.
