MCPcopy Create free account
hub / github.com/numpy/numpy / hermroots

Function hermroots

numpy/polynomial/hermite.py:1452–1513  ·  view source on GitHub ↗

Compute the roots of a Hermite series. Return the roots (a.k.a. "zeros") of the polynomial .. math:: p(x) = \\sum_i c[i] * H_i(x). Parameters ---------- c : 1-D array_like 1-D array of coefficients. Returns ------- out : ndarray Array of the r

(c)

Source from the content-addressed store, hash-verified

1450
1451
1452def hermroots(c):
1453 """
1454 Compute the roots of a Hermite series.
1455
1456 Return the roots (a.k.a. "zeros") of the polynomial
1457
1458 .. math:: p(x) = \\sum_i c[i] * H_i(x).
1459
1460 Parameters
1461 ----------
1462 c : 1-D array_like
1463 1-D array of coefficients.
1464
1465 Returns
1466 -------
1467 out : ndarray
1468 Array of the roots of the series. If all the roots are real,
1469 then `out` is also real, otherwise it is complex.
1470
1471 See Also
1472 --------
1473 numpy.polynomial.polynomial.polyroots
1474 numpy.polynomial.legendre.legroots
1475 numpy.polynomial.laguerre.lagroots
1476 numpy.polynomial.chebyshev.chebroots
1477 numpy.polynomial.hermite_e.hermeroots
1478
1479 Notes
1480 -----
1481 The root estimates are obtained as the eigenvalues of the companion
1482 matrix, Roots far from the origin of the complex plane may have large
1483 errors due to the numerical instability of the series for such
1484 values. Roots with multiplicity greater than 1 will also show larger
1485 errors as the value of the series near such points is relatively
1486 insensitive to errors in the roots. Isolated roots near the origin can
1487 be improved by a few iterations of Newton's method.
1488
1489 The Hermite series basis polynomials aren't powers of `x` so the
1490 results of this function may seem unintuitive.
1491
1492 Examples
1493 --------
1494 >>> from numpy.polynomial.hermite import hermroots, hermfromroots
1495 >>> coef = hermfromroots([-1, 0, 1])
1496 >>> coef
1497 array([0. , 0.25 , 0. , 0.125])
1498 >>> hermroots(coef)
1499 array([-1.00000000e+00, -1.38777878e-17, 1.00000000e+00])
1500
1501 """
1502 # c is a trimmed copy
1503 [c] = pu.as_series([c])
1504 if len(c) <= 1:
1505 return np.array([], dtype=c.dtype)
1506 if len(c) == 2:
1507 return np.array([-.5*c[0]/c[1]])
1508
1509 # rotated companion matrix reduces error

Callers

nothing calls this directly

Calls 2

hermcompanionFunction · 0.85
sortMethod · 0.80

Tested by

no test coverage detected