MCPcopy Index your code
hub / github.com/numpy/numpy / hermcompanion

Function hermcompanion

numpy/polynomial/hermite.py:1490–1534  ·  view source on GitHub ↗

Return the scaled companion matrix of c. The basis polynomials are scaled so that the companion matrix is symmetric when `c` is a Hermite basis polynomial. This provides better eigenvalue estimates than the unscaled case and for basis polynomials the eigenvalues are guaranteed to be

(c)

Source from the content-addressed store, hash-verified

1488
1489
1490def hermcompanion(c):
1491 """Return the scaled companion matrix of c.
1492
1493 The basis polynomials are scaled so that the companion matrix is
1494 symmetric when `c` is a Hermite basis polynomial. This provides
1495 better eigenvalue estimates than the unscaled case and for basis
1496 polynomials the eigenvalues are guaranteed to be real if
1497 `numpy.linalg.eigvalsh` is used to obtain them.
1498
1499 Parameters
1500 ----------
1501 c : array_like
1502 1-D array of Hermite series coefficients ordered from low to high
1503 degree.
1504
1505 Returns
1506 -------
1507 mat : ndarray
1508 Scaled companion matrix of dimensions (deg, deg).
1509
1510 Examples
1511 --------
1512 >>> from numpy.polynomial.hermite import hermcompanion
1513 >>> hermcompanion([1, 0, 1])
1514 array([[0. , 0.35355339],
1515 [0.70710678, 0. ]])
1516
1517 """
1518 # c is a trimmed copy
1519 [c] = pu.as_series([c])
1520 if len(c) < 2:
1521 raise ValueError('Series must have maximum degree of at least 1.')
1522 if len(c) == 2:
1523 return np.array([[-.5 * c[0] / c[1]]])
1524
1525 n = len(c) - 1
1526 mat = np.zeros((n, n), dtype=c.dtype)
1527 scl = np.hstack((1., 1. / np.sqrt(2. * np.arange(n - 1, 0, -1))))
1528 scl = np.multiply.accumulate(scl)[::-1]
1529 top = mat.reshape(-1)[1::n + 1]
1530 bot = mat.reshape(-1)[n::n + 1]
1531 top[...] = np.sqrt(.5 * np.arange(1, n))
1532 bot[...] = top
1533 mat[:, -1] -= scl * c[:-1] / (2.0 * c[-1])
1534 return mat
1535
1536
1537def hermroots(c):

Callers 2

hermrootsFunction · 0.85
hermgaussFunction · 0.85

Calls 2

accumulateMethod · 0.80
reshapeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…