MCPcopy
hub / github.com/numpy/numpy / polycompanion

Function polycompanion

numpy/polynomial/polynomial.py:1502–1542  ·  view source on GitHub ↗

Return the companion matrix of c. The companion matrix for power series cannot be made symmetric by scaling the basis, so this function differs from those for the orthogonal polynomials. Parameters ---------- c : array_like 1-D array of polynomial coefficients

(c)

Source from the content-addressed store, hash-verified

1500
1501
1502def polycompanion(c):
1503 """
1504 Return the companion matrix of c.
1505
1506 The companion matrix for power series cannot be made symmetric by
1507 scaling the basis, so this function differs from those for the
1508 orthogonal polynomials.
1509
1510 Parameters
1511 ----------
1512 c : array_like
1513 1-D array of polynomial coefficients ordered from low to high
1514 degree.
1515
1516 Returns
1517 -------
1518 mat : ndarray
1519 Companion matrix of dimensions (deg, deg).
1520
1521 Examples
1522 --------
1523 >>> from numpy.polynomial import polynomial as P
1524 >>> c = (1, 2, 3)
1525 >>> P.polycompanion(c)
1526 array([[ 0. , -0.33333333],
1527 [ 1. , -0.66666667]])
1528
1529 """
1530 # c is a trimmed copy
1531 [c] = pu.as_series([c])
1532 if len(c) < 2:
1533 raise ValueError('Series must have maximum degree of at least 1.')
1534 if len(c) == 2:
1535 return np.array([[-c[0] / c[1]]])
1536
1537 n = len(c) - 1
1538 mat = np.zeros((n, n), dtype=c.dtype)
1539 bot = mat.reshape(-1)[n::n + 1]
1540 bot[...] = 1
1541 mat[:, -1] -= c[:-1] / c[-1]
1542 return mat
1543
1544
1545def polyroots(c):

Callers 1

polyrootsFunction · 0.85

Calls 1

reshapeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…