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
Compute the roots of a Hermite_e series in Python
To compute the roots of a Hermite_e series, use the hermeroots() method from NumPy's polynomial module. This method returns an array of the roots of the series. If all roots are real, the output is real; otherwise, it's complex. The parameter c is a 1-D array of coefficients representing the Hermite_e series.
The root estimates are obtained as eigenvalues of the companion matrix. Roots far from the origin may have large errors due to numerical instability. Roots with multiplicity greater than 1 also show larger errors since the series value near such points is relatively insensitive to root errors. Isolated roots near the origin can be improved using Newton's method iterations.
Syntax
numpy.polynomial.hermite_e.hermeroots(c)
Parameters
c: 1-D array of Hermite_e series coefficients ordered from low to high degree.
Returns
out: ndarray containing the roots of the series. Real if all roots are real, complex otherwise.
Example
Let's compute the roots of a Hermite_e series with coefficients [-1, 0, 1] ?
import numpy as np
from numpy.polynomial import hermite_e as H
# Compute roots of Hermite_e series with coefficients [-1, 0, 1]
coefficients = (-1, 0, 1)
roots = H.hermeroots(coefficients)
print("Coefficients:", coefficients)
print("Roots:", roots)
print("Data type:", roots.dtype)
print("Shape:", roots.shape)
Coefficients: (-1, 0, 1) Roots: [-1.41421356 1.41421356] Data type: float64 Shape: (2,)
Different Coefficient Examples
Let's explore different coefficient combinations ?
import numpy as np
from numpy.polynomial import hermite_e as H
# Example 1: Linear polynomial [1, -2] represents -2x + 1
linear_roots = H.hermeroots([1, -2])
print("Linear polynomial [-2x + 1] roots:", linear_roots)
# Example 2: Cubic polynomial [1, 0, 0, 1] represents x³ + 1
cubic_roots = H.hermeroots([1, 0, 0, 1])
print("Cubic polynomial [x³ + 1] roots:", cubic_roots)
print("Are roots complex?", np.iscomplexobj(cubic_roots))
Linear polynomial [-2x + 1] roots: [0.5] Cubic polynomial [x³ + 1] roots: [-1.73205081+0.j 0.8660254 +1.5j 0.8660254 -1.5j] Are roots complex? True
Key Points
- Coefficients are ordered from low to high degree (constant term first)
- Real coefficients may produce complex roots
- Numerical precision decreases for roots far from the origin
- Multiple roots may have reduced accuracy
Conclusion
The hermeroots() method efficiently computes roots of Hermite_e series using eigenvalue decomposition. While generally accurate, be aware of potential numerical issues with distant or multiple roots.
