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

Function hermcompanion

numpy/polynomial/hermite.py:1407–1449  ·  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 an Hermite basis polynomial. This provides better eigenvalue estimates than the unscaled case and for basis polynomials the eigenvalues are guaranteed to b

(c)

Source from the content-addressed store, hash-verified

1405
1406
1407def hermcompanion(c):
1408 """Return the scaled companion matrix of c.
1409
1410 The basis polynomials are scaled so that the companion matrix is
1411 symmetric when `c` is an Hermite basis polynomial. This provides
1412 better eigenvalue estimates than the unscaled case and for basis
1413 polynomials the eigenvalues are guaranteed to be real if
1414 `numpy.linalg.eigvalsh` is used to obtain them.
1415
1416 Parameters
1417 ----------
1418 c : array_like
1419 1-D array of Hermite series coefficients ordered from low to high
1420 degree.
1421
1422 Returns
1423 -------
1424 mat : ndarray
1425 Scaled companion matrix of dimensions (deg, deg).
1426
1427 Notes
1428 -----
1429
1430 .. versionadded:: 1.7.0
1431
1432 """
1433 # c is a trimmed copy
1434 [c] = pu.as_series([c])
1435 if len(c) < 2:
1436 raise ValueError('Series must have maximum degree of at least 1.')
1437 if len(c) == 2:
1438 return np.array([[-.5*c[0]/c[1]]])
1439
1440 n = len(c) - 1
1441 mat = np.zeros((n, n), dtype=c.dtype)
1442 scl = np.hstack((1., 1./np.sqrt(2.*np.arange(n - 1, 0, -1))))
1443 scl = np.multiply.accumulate(scl)[::-1]
1444 top = mat.reshape(-1)[1::n+1]
1445 bot = mat.reshape(-1)[n::n+1]
1446 top[...] = np.sqrt(.5*np.arange(1, n))
1447 bot[...] = top
1448 mat[:, -1] -= scl*c[:-1]/(2.0*c[-1])
1449 return mat
1450
1451
1452def hermroots(c):

Callers 2

hermrootsFunction · 0.85
hermgaussFunction · 0.85

Calls 2

accumulateMethod · 0.80
reshapeMethod · 0.80

Tested by

no test coverage detected