Skip to content

Commit

Permalink
Trac #12595: Add doctest for eigenmatrix of complex floating-point ma…
Browse files Browse the repository at this point in the history
…trix

{{{
sage: m = Matrix(CDF, 8, [[-1, -1, -1, -1, 1, -3, -1, -1], [1, 1, 1, 1,
-1, -1, 1, -3], [-1, 3, -1, -1, 1, 1, -1, -1], [-1, -1, -1, 3, 1, 1, -1,
-1], [1, 1, -3, 1, -1, -1, 1, 1], [1, 1, 1, 1, -1, -1, -3, 1], [3, -1,
-1, -1, 1, 1, -1, -1], [1, 1, 1, 1, 3, -1, 1, 1]])
sage: d, p = m.eigenmatrix_left()
sage: (p[1] * m)[0] / p[1][0]
1.2360679775 - 3.80422606518*I
sage: d[1][1]
1.2360679775 + 3.80422606518*I
}}}
Sage seems to return the complex conjugate of {{{d}}} or something of
the sort. Perhaps {{{d}}} is simply wrongly permuted (but real
eigenvalues seem to be correct).

{{{p.inverse() * d * p}}} should be at least approximately equal to
{{{m}}}.

This was reported on
[https://spreadsheets.google.com/pub?key=pCwvGVwSMxTzT6E2xNdo5fA the
public bug reports from the notebook interface] by
<[email protected]> on 1/24/2012.

URL: https://trac.sagemath.org/12595
Reported by: dkrenn
Ticket author(s): Shashwat Singh
Reviewer(s): Samuel Lelièvre
  • Loading branch information
Release Manager committed Feb 16, 2022
2 parents e4f9347 + c7e4e78 commit ff40ba0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7000,6 +7000,21 @@ cdef class Matrix(Matrix1):
Traceback (most recent call last):
...
RuntimeError: failed to compute eigenvectors for eigenvalue ..., check eigenvectors_left() for partial results

The following example shows that :trac:`12595` has been resolved::

sage: m = Matrix(CDF, 8, [[-1, -1, -1, -1, 1, -3, -1, -1],
....: [1, 1, 1, 1, -1, -1, 1, -3],
....: [-1, 3, -1, -1, 1, 1, -1, -1],
....: [-1, -1, -1, 3, 1, 1, -1, -1],
....: [1, 1, -3, 1, -1, -1, 1, 1],
....: [1, 1, 1, 1, -1, -1, -3, 1],
....: [3, -1, -1, -1, 1, 1, -1, -1],
....: [1, 1, 1, 1, 3, -1, 1, 1]])
sage: d, p = m.eigenmatrix_left()
sage: mm = p.inverse() * d * p # This should be equal to m up to numerical noise
sage: norm(mm - m) < 1e-12
True
"""
from sage.misc.flatten import flatten
from sage.matrix.constructor import diagonal_matrix, matrix
Expand Down

0 comments on commit ff40ba0

Please sign in to comment.