8000 Merge pull request #13202 from mtmoncur/rotated-companion-matrix · numpy/numpy@167a31b · GitHub
[go: up one dir, main page]

Skip to content

Commit 167a31b

Browse files
authored
Merge pull request #13202 from mtmoncur/rotated-companion-matrix
ENH: use rotated companion matrix to reduce error
2 parents 5c3cb43 + 732d52a commit 167a31b

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

numpy/polynomial/chebyshev.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,8 @@ def chebroots(c):
17431743
if len(c) == 2:
17441744
return np.array([-c[0]/c[1]])
17451745

1746-
m = chebcompanion(c)
1746+
# rotated companion matrix reduces error
1747+
m = chebcompanion(c)[::-1,::-1]
17471748
r = la.eigvals(m)
17481749
r.sort()
17491750
return r

numpy/polynomial/hermite.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,8 @@ def hermroots(c):
14761476
if len(c) == 2:
14771477
return np.array([-.5*c[0]/c[1]])
14781478

1479-
m = hermcompanion(c)
1479+
# rotated companion matrix reduces error
1480+
m = hermcompanion(c)[::-1,::-1]
14801481
r = la.eigvals(m)
14811482
r.sort()
14821483
return r

numpy/polynomial/hermite_e.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,8 @@ def hermeroots(c):
14711471
if len(c) == 2:
14721472
return np.array([-c[0]/c[1]])
14731473

1474-
m = hermecompanion(c)
1474+
# rotated companion matrix reduces error
1475+
m = hermecompanion(c)[::-1,::-1]
14751476
r = la.eigvals(m)
14761477
r.sort()
14771478
return r

numpy/polynomial/laguerre.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,8 @@ def lagroots(c):
14751475
if len(c) == 2:
14761476
return np.array([1 + c[0]/c[1]])
14771477

1478-
m = lagcompanion(c)
1478+
# rotated companion matrix reduces error
1479+
m = lagcompanion(c)[::-1,::-1]
14791480
r = la.eigvals(m)
14801481
r.sort()
14811482
return r

numpy/polynomial/legendre.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,8 @@ def legroots(c):
15051505
if len(c) == 2:
15061506
return np.array([-c[0]/c[1]])
15071507

1508-
m = legcompanion(c)
1508+
# rotated companion matrix reduces error
1509+
m = legcompanion(c)[::-1,::-1]
15091510
r = la.eigvals(m)
15101511
r.sort()
15111512
return r

numpy/polynomial/polynomial.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,8 @@ def polyroots(c):
14281428
if len(c) == 2:
14291429
return np.array([-c[0]/c[1]])
14301430

1431-
m = polycompanion(c)
1431+
# rotated companion matrix reduces error
1432+
m = polycompanion(c)[::-1,::-1]
14321433
r = la.eigvals(m)
14331434
r.sort()
14341435
return r

0 commit comments

Comments
 (0)
0