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