Generate a Hermite series with given complex roots in Python

To generate a Hermite series with given complex 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

roots ? A sequence containing the roots of the Hermite polynomial.

Example with Complex Roots

Let's create a Hermite series with complex roots using imaginary unit j ?

from numpy.polynomial import hermite as H

# Define complex roots using imaginary unit
j = complex(0, 1)
roots = (-j, j)

# Generate Hermite series from complex roots
result = H.hermfromroots(roots)
print("Result:")
print(result)

print("\nDatatype:")
print(result.dtype)

print("\nShape:")
print(result.shape)
Result:
[1.5 +0.j 0. +0.j 0.25+0.j]

Datatype:
complex128

Shape:
(3,)

Example with Real Roots

When all roots are real, the output coefficients are also real ?

from numpy.polynomial import hermite as H

# Generate Hermite series with real roots
real_roots = [-2, 1, 3]
result = H.hermfromroots(real_roots)

print("Result with real roots:")
print(result)

print("\nDatatype:")
print(result.dtype)
Result with real roots:
[-3.    3.   -0.75  0.125]

Datatype:
float64

How It Works

The hermfromroots() method constructs a Hermite polynomial whose roots are the specified values. For complex roots, the resulting coefficients maintain complex data type even if they are mathematically real values.

Conclusion

Use hermite.hermfromroots() to generate Hermite series from given roots. The method handles both real and complex roots, returning appropriate coefficient arrays with proper data types.

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

202 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements