Generate a Hermite series with given roots in Python

To generate a Hermite series with given roots, use the hermite.hermfromroots() method in Python NumPy. The method returns a 1-D array of coefficients. If all roots are real then out is a real array, if some of the roots are complex, then out is complex even if all the coefficients in the result are real.

Syntax

numpy.polynomial.hermite.hermfromroots(roots)

Parameters

The parameter roots is the sequence containing the roots of the Hermite polynomial.

Example

Let's generate a Hermite series with roots (-1, 0, 1) −

import numpy as np
from numpy.polynomial import hermite as H

# Generate a Hermite series with given roots
result = H.hermfromroots((-1, 0, 1))
print("Hermite coefficients:")
print(result)

# Get the datatype
print("\nDatatype:")
print(result.dtype)

# Get the shape
print("\nShape:")
print(result.shape)
Hermite coefficients:
[0.    0.25  0.    0.125]

Datatype:
float64

Shape:
(4,)

Complex Roots Example

When roots contain complex numbers, the output array becomes complex −

import numpy as np
from numpy.polynomial import hermite as H

# Generate Hermite series with complex roots
complex_roots = [1, -1, 1j]
result = H.hermfromroots(complex_roots)

print("Hermite coefficients with complex roots:")
print(result)
print("\nDatatype:")
print(result.dtype)
Hermite coefficients with complex roots:
[-0.25+0.j   0.  +0.j   0.25+0.125j  0.  +0.j    0.  +0.125j]

Datatype:
complex128

How It Works

The hermfromroots() method constructs a Hermite polynomial that has the specified roots. For roots r?, r?, ..., r?, it creates a polynomial of the form:

H(x) = c? + c?H?(x) + c?H?(x) + ... + c?H?(x)

where H?(x) are the Hermite basis polynomials and the coefficients are chosen so that the polynomial has the given roots.

Conclusion

The hermite.hermfromroots() method efficiently generates Hermite series coefficients from specified roots. The output datatype automatically adjusts based on whether the roots are real or complex.

Updated on: 2026-03-26T20:21:09+05:30

186 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements