Compute the roots of a Hermite series in Python

To compute the roots of a Hermite series, use the hermite.hermroots() method in Python NumPy. The method returns an array of the roots of the series. If all the roots are real, then the output is also real, otherwise it is complex. The parameter c is a 1-D array of coefficients.

The root estimates are obtained as the eigenvalues of the companion matrix. Roots far from the origin of the complex plane may have large errors due to the numerical instability of the series for such values. Roots with multiplicity greater than 1 will also show larger errors as the value of the series near such points is relatively insensitive to errors in the roots. Isolated roots near the origin can be improved by a few iterations of Newton's method.

Syntax

numpy.polynomial.hermite.hermroots(c)

Parameters:

  • c: 1-D array of coefficients

Returns: Array of roots of the Hermite series

Example

First, import the required library ?

from numpy.polynomial import hermite as H

# Compute the roots of a Hermite series
# For polynomial: -1 + 0*x + 1*x^2 = x^2 - 1
roots = H.hermroots((-1, 0, 1))
print("Result...")
print(roots)

# Get the datatype
print("\nType...")
print(roots.dtype)

# Get the shape
print("\nShape...")
print(roots.shape)
Result...
[-0.8660254  0.8660254]

Type...
float64

Shape...
(2,)

Finding Roots of Different Hermite Polynomials

Let's explore different coefficient arrays to see how the roots change ?

from numpy.polynomial import hermite as H

# Simple linear Hermite polynomial: 1 + 2*x
linear_roots = H.hermroots([1, 2])
print("Linear polynomial roots:", linear_roots)

# Quadratic Hermite polynomial: 1 + 0*x + 1*x^2  
quadratic_roots = H.hermroots([1, 0, 1])
print("Quadratic polynomial roots:", quadratic_roots)

# Cubic Hermite polynomial: 0 + 0*x + 0*x^2 + 1*x^3
cubic_roots = H.hermroots([0, 0, 0, 1])
print("Cubic polynomial roots:", cubic_roots)
Linear polynomial roots: [-0.25]
Quadratic polynomial roots: [-0.8660254+0.j  0.8660254+0.j]
Cubic polynomial roots: [-1.2247449   0.         1.2247449 ]

Key Points

  • The coefficients represent the Hermite polynomial in ascending powers of x
  • Real coefficients may produce complex roots depending on the polynomial
  • The method uses eigenvalue computation for numerical root finding
  • Accuracy may decrease for roots far from the origin

Conclusion

The hermite.hermroots() method efficiently computes roots of Hermite series using eigenvalue decomposition. It handles both real and complex roots automatically, making it useful for polynomial analysis in scientific computing.

Updated on: 2026-03-26T20:32:32+05:30

237 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements