Generate a Hermite_e series with given roots using NumPy in Python

Hermite polynomials are orthogonal polynomials used in differential equations, probability theory, and quantum mechanics. The Hermite_e series represents functions using their roots. This article demonstrates how to generate Hermite_e series with given roots using NumPy in Python.

Installation and Import

NumPy provides support for Hermite_e polynomial operations ?

pip install numpy matplotlib
import numpy as np
import matplotlib.pyplot as plt

Syntax

NumPy provides functions to work with Hermite_e polynomials ?

# Generate polynomial from roots
numpy.polynomial.hermite_e.hermefromroots(roots)

# Gauss-Hermite quadrature
numpy.polynomial.hermite_e.hermegauss(deg)

roots ? Array containing the roots of the polynomial

deg ? Degree for Gauss-Hermite quadrature

Generating Hermite_e Polynomial from Roots

The most direct way to create a Hermite_e series with given roots is using hermefromroots() ?

import numpy as np

# Define roots
roots = np.array([-1, 0, 1])

# Generate Hermite_e polynomial coefficients from roots
coefficients = np.polynomial.hermite_e.hermefromroots(roots)
print("Coefficients:", coefficients)

# Create polynomial object
poly = np.polynomial.hermite_e.HermiteE(coefficients)
print("Polynomial:", poly)
Coefficients: [ 0.  0. -2.  0.  1.]
Polynomial: HermiteE([ 0.  0. -2.  0.  1.], domain=[-1,  1], window=[-1,  1])

Evaluating the Polynomial

Evaluate the generated polynomial at specific points ?

import numpy as np

roots = np.array([-2, -1, 1, 2])
coefficients = np.polynomial.hermite_e.hermefromroots(roots)

# Evaluate at the roots (should be close to zero)
x_values = np.array([-2, -1, 0, 1, 2])
y_values = np.polynomial.hermite_e.hermeval(x_values, coefficients)

print("x values:", x_values)
print("y values:", y_values)
x values: [-2 -1  0  1  2]
y values: [ 2.77555756e-17 -1.66533454e-16  2.40000000e+01  1.11022302e-16
  1.11022302e-16]

Visualization Example

Plot the Hermite_e polynomial with given roots ?

import numpy as np
import matplotlib.pyplot as plt

# Define roots
roots = np.array([-2, -1, 1, 2])

# Generate coefficients
coefficients = np.polynomial.hermite_e.hermefromroots(roots)

# Create x values for plotting
x = np.linspace(-3, 3, 1000)

# Evaluate polynomial
y = np.polynomial.hermite_e.hermeval(x, coefficients)

# Plot
plt.figure(figsize=(10, 6))
plt.plot(x, y, 'b-', linewidth=2, label='Hermite_e polynomial')
plt.scatter(roots, np.zeros_like(roots), color='red', s=100, zorder=5, label='Roots')
plt.axhline(y=0, color='k', linestyle='--', alpha=0.3)
plt.grid(True, alpha=0.3)
plt.xlabel('x')
plt.ylabel('y')
plt.title('Hermite_e Polynomial with Given Roots')
plt.legend()
plt.show()

print("Roots used:", roots)
print("Polynomial coefficients:", coefficients)
Roots used: [-2 -1  1  2]
Polynomial coefficients: [  0.  12.   0. -12.   0.   1.]

Gauss-Hermite Quadrature

Generate nodes and weights for numerical integration ?

import numpy as np

# Generate Gauss-Hermite quadrature points and weights
degree = 4
nodes, weights = np.polynomial.hermite_e.hermegauss(degree)

print("Nodes:", nodes)
print("Weights:", weights)
print("Sum of weights:", np.sum(weights))
Nodes: [-2.02018287 -0.95857246  0.95857246  2.02018287]
Weights: [0.19953242 0.39361932 0.39361932 0.19953242]
Sum of weights: 1.1863634685506233

Applications

Hermite_e polynomials are used in ?

  • Quantum mechanics ? Wave functions of quantum harmonic oscillators

  • Probability theory ? Approximating normal distributions

  • Numerical integration ? Gauss-Hermite quadrature for integrals with Gaussian weights

  • Signal processing ? Function approximation and filtering

Conclusion

NumPy's hermefromroots() function easily generates Hermite_e polynomials from given roots. These polynomials are valuable in quantum mechanics, probability theory, and numerical analysis for high-accuracy function approximation.

Updated on: 2026-03-27T13:16:34+05:30

355 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements