ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 05 Feb 2024 18:38:05 +0100How to take inverse of matrix with complex entrieshttps://ask.sagemath.org/question/75698/how-to-take-inverse-of-matrix-with-complex-entries/I am trying to find the similarity matrix between two 18 by 18 matrices `K_1` and `K_2` which are cospectral. The `is_similar()` function takes too long to run. We can compute the similarity matrix by finding the transition matrices `S` and Q which diagonalize both `K_1` and `K_2`. In other words, `S^(-1)*K_1*S = H = Q^(-1)*K_2*Q`, where `H` is a diagonal matrix. We then know that `Q*S^(-1)*K_1*S*Q^(-1) = K_2`. My problem now though is that we can't compute `Q^(-1)` or `S^(-1)` since both `Q` and `S` have nasty complex numbers and the inverse method in Sage doesn't run fast enough. Any thoughts on how to quickly compute these inverses?
fyi, I did try using the left and right eigenmatrices to find the similarity matrix, but the eigenvectors didn't line up.Mon, 29 Jan 2024 19:11:05 +0100https://ask.sagemath.org/question/75698/how-to-take-inverse-of-matrix-with-complex-entries/Comment by dan_fulea for <p>I am trying to find the similarity matrix between two 18 by 18 matrices <code>K_1</code> and <code>K_2</code> which are cospectral. The <code>is_similar()</code> function takes too long to run. We can compute the similarity matrix by finding the transition matrices <code>S</code> and Q which diagonalize both <code>K_1</code> and <code>K_2</code>. In other words, <code>S^(-1)*K_1*S = H = Q^(-1)*K_2*Q</code>, where <code>H</code> is a diagonal matrix. We then know that <code>Q*S^(-1)*K_1*S*Q^(-1) = K_2</code>. My problem now though is that we can't compute <code>Q^(-1)</code> or <code>S^(-1)</code> since both <code>Q</code> and <code>S</code> have nasty complex numbers and the inverse method in Sage doesn't run fast enough. Any thoughts on how to quickly compute these inverses?</p>
<p>fyi, I did try using the left and right eigenmatrices to find the similarity matrix, but the eigenvectors didn't line up.</p>
https://ask.sagemath.org/question/75698/how-to-take-inverse-of-matrix-with-complex-entries/?comment=75827#post-id-75827.... continued:
But Jordan form will require that the
eigenvalues of the matrix can be represented within Sage, requiring
the existence of the appropriate extension field. When this is not
possible, a "RuntimeError" is raised, as demonstrated in an example
below.
This information can be obtained via `A.is_similar?` for an already defined matrix `A`.
If the domain for the entries is not exact, then there are usual determinant instability issues. If there is a special form for `A, B` that may be used, some better field to work in... this may make a special specific solution possible. We do not have the two $18\times 18$ matrices, so it is hard to give a general advice to work for all general cases.Mon, 05 Feb 2024 18:38:05 +0100https://ask.sagemath.org/question/75698/how-to-take-inverse-of-matrix-with-complex-entries/?comment=75827#post-id-75827Comment by dan_fulea for <p>I am trying to find the similarity matrix between two 18 by 18 matrices <code>K_1</code> and <code>K_2</code> which are cospectral. The <code>is_similar()</code> function takes too long to run. We can compute the similarity matrix by finding the transition matrices <code>S</code> and Q which diagonalize both <code>K_1</code> and <code>K_2</code>. In other words, <code>S^(-1)*K_1*S = H = Q^(-1)*K_2*Q</code>, where <code>H</code> is a diagonal matrix. We then know that <code>Q*S^(-1)*K_1*S*Q^(-1) = K_2</code>. My problem now though is that we can't compute <code>Q^(-1)</code> or <code>S^(-1)</code> since both <code>Q</code> and <code>S</code> have nasty complex numbers and the inverse method in Sage doesn't run fast enough. Any thoughts on how to quickly compute these inverses?</p>
<p>fyi, I did try using the left and right eigenmatrices to find the similarity matrix, but the eigenvectors didn't line up.</p>
https://ask.sagemath.org/question/75698/how-to-take-inverse-of-matrix-with-complex-entries/?comment=75826#post-id-75826Which is the field / domain of definition for the entries of the two matrices `K_1` and `K_2` - that i will denote by `A` and `B` below? If this is the *inexact* complex field `CC` taken with some precision, well some in between steps are failing. Here is the reason for `is_similar` as documented:
Warning:
When the two matrices are similar, this routine may fail to find
the similarity transformation. A technical explanation follows.
The similarity check is accomplished with rational form, which will
be successful for any pair of matrices over the same field.
However, the computation of rational form does not provide a
transformation. So we instead compute Jordan form, which does
provide a transformation.Mon, 05 Feb 2024 18:33:19 +0100https://ask.sagemath.org/question/75698/how-to-take-inverse-of-matrix-with-complex-entries/?comment=75826#post-id-75826