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

Function polycompanion

numpy/polynomial/polynomial.py:1365–1402  ·  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

1363
1364
1365def polycompanion(c):
1366 """
1367 Return the companion matrix of c.
1368
1369 The companion matrix for power series cannot be made symmetric by
1370 scaling the basis, so this function differs from those for the
1371 orthogonal polynomials.
1372
1373 Parameters
1374 ----------
1375 c : array_like
1376 1-D array of polynomial coefficients ordered from low to high
1377 degree.
1378
1379 Returns
1380 -------
1381 mat : ndarray
1382 Companion matrix of dimensions (deg, deg).
1383
1384 Notes
1385 -----
1386
1387 .. versionadded:: 1.7.0
1388
1389 """
1390 # c is a trimmed copy
1391 [c] = pu.as_series([c])
1392 if len(c) < 2:
1393 raise ValueError('Series must have maximum degree of at least 1.')
1394 if len(c) == 2:
1395 return np.array([[-c[0]/c[1]]])
1396
1397 n = len(c) - 1
1398 mat = np.zeros((n, n), dtype=c.dtype)
1399 bot = mat.reshape(-1)[n::n+1]
1400 bot[...] = 1
1401 mat[:, -1] -= c[:-1]/c[-1]
1402 return mat
1403
1404
1405def polyroots(c):

Callers 1

polyrootsFunction · 0.85

Calls 1

reshapeMethod · 0.80

Tested by

no test coverage detected