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.Fri, 01 Sep 2023 00:17:42 +0200Diagonalisability check Malfunctioninghttps://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/I ran the following code:
```
A = matrix(QQbar, [[2,-1,0],[-1,2,1],[0,-1,2]]);
D, P = A.diagonalization()
```
This generated a value error saying that A is not diagonalisable. To see if there are workarounds, I replaced the `diagonalization` method by `eigenmatrix_right()`, and the results were weird.
`D` was twice the identity matrix, and `P` had zero vectors in its creation. I think writing `QQbar` to make the thing work in algebraic numbers is not proving fruitful at all, because replacing it with `QQ` yields exactly the same result.
UPD1: I thought that the issue might lie with the implementation of `QQbar`, so I tried it `Q[sqrt(2)]` instead, which does indeed contain the eigenvalues of my matrix: `2, 2 + \sqrt(2), 2 - \sqrt(2)`, and the entries of the corresponding eigenvectors as well, but to no avail. I think it's the matrix construction mechanism itself which is faulty here. Unless addressed soon, I suppose I would remove the `QQbar` tag from the question then.
UPD2: Closed, A wasn't entered correctly, was the issue.Thu, 31 Aug 2023 03:45:54 +0200https://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/Comment by John Palmieri for <p>I ran the following code:</p>
<p><code>
A = matrix(QQbar, [[2,-1,0],[-1,2,1],[0,-1,2]]);
D, P = A.diagonalization()
</code></p>
<p>This generated a value error saying that A is not diagonalisable. To see if there are workarounds, I replaced the <code>diagonalization</code> method by <code>eigenmatrix_right()</code>, and the results were weird.</p>
<p><code>D</code> was twice the identity matrix, and <code>P</code> had zero vectors in its creation. I think writing <code>QQbar</code> to make the thing work in algebraic numbers is not proving fruitful at all, because replacing it with <code>QQ</code> yields exactly the same result.</p>
<p>UPD1: I thought that the issue might lie with the implementation of <code>QQbar</code>, so I tried it <code>Q[sqrt(2)]</code> instead, which does indeed contain the eigenvalues of my matrix: <code>2, 2 + \sqrt(2), 2 - \sqrt(2)</code>, and the entries of the corresponding eigenvectors as well, but to no avail. I think it's the matrix construction mechanism itself which is faulty here. Unless addressed soon, I suppose I would remove the <code>QQbar</code> tag from the question then.</p>
<p>UPD2: Closed, A wasn't entered correctly, was the issue.</p>
https://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/?comment=73086#post-id-73086I will continue to take Sage's word for it, since your matrix is not in fact symmetric. (It would be if you changed the last `-1` to `1`, though.) As the documentation for `eigenmatrix_right` says, "The matrix P may contain zero columns corresponding to eigenvalues for which the algebraic multiplicity is greater than the geometric multiplicity. In these cases, the matrix is not diagonalizable."Thu, 31 Aug 2023 17:21:07 +0200https://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/?comment=73086#post-id-73086Comment by yeetcode for <p>I ran the following code:</p>
<p><code>
A = matrix(QQbar, [[2,-1,0],[-1,2,1],[0,-1,2]]);
D, P = A.diagonalization()
</code></p>
<p>This generated a value error saying that A is not diagonalisable. To see if there are workarounds, I replaced the <code>diagonalization</code> method by <code>eigenmatrix_right()</code>, and the results were weird.</p>
<p><code>D</code> was twice the identity matrix, and <code>P</code> had zero vectors in its creation. I think writing <code>QQbar</code> to make the thing work in algebraic numbers is not proving fruitful at all, because replacing it with <code>QQ</code> yields exactly the same result.</p>
<p>UPD1: I thought that the issue might lie with the implementation of <code>QQbar</code>, so I tried it <code>Q[sqrt(2)]</code> instead, which does indeed contain the eigenvalues of my matrix: <code>2, 2 + \sqrt(2), 2 - \sqrt(2)</code>, and the entries of the corresponding eigenvectors as well, but to no avail. I think it's the matrix construction mechanism itself which is faulty here. Unless addressed soon, I suppose I would remove the <code>QQbar</code> tag from the question then.</p>
<p>UPD2: Closed, A wasn't entered correctly, was the issue.</p>
https://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/?comment=73074#post-id-73074As for what `D` and `P` are, I clearly stated that I only got outputs on replacing `diagonalization()` by `eigenvalues_right()`. You're right in saying that without that change, you get a value error, which I have reported already in this same post.Thu, 31 Aug 2023 09:11:50 +0200https://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/?comment=73074#post-id-73074Comment by yeetcode for <p>I ran the following code:</p>
<p><code>
A = matrix(QQbar, [[2,-1,0],[-1,2,1],[0,-1,2]]);
D, P = A.diagonalization()
</code></p>
<p>This generated a value error saying that A is not diagonalisable. To see if there are workarounds, I replaced the <code>diagonalization</code> method by <code>eigenmatrix_right()</code>, and the results were weird.</p>
<p><code>D</code> was twice the identity matrix, and <code>P</code> had zero vectors in its creation. I think writing <code>QQbar</code> to make the thing work in algebraic numbers is not proving fruitful at all, because replacing it with <code>QQ</code> yields exactly the same result.</p>
<p>UPD1: I thought that the issue might lie with the implementation of <code>QQbar</code>, so I tried it <code>Q[sqrt(2)]</code> instead, which does indeed contain the eigenvalues of my matrix: <code>2, 2 + \sqrt(2), 2 - \sqrt(2)</code>, and the entries of the corresponding eigenvectors as well, but to no avail. I think it's the matrix construction mechanism itself which is faulty here. Unless addressed soon, I suppose I would remove the <code>QQbar</code> tag from the question then.</p>
<p>UPD2: Closed, A wasn't entered correctly, was the issue.</p>
https://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/?comment=73073#post-id-73073I am assuming you took Sage's word for it. It is not returning correct values though, which is my complaint to begin with. Please note that the matrix in question is a symmetric real matrix, and is thus certainly diagonalisable. And Sage is failing to report to you the eigenvalues `2+sqrt(2)` and `2-sqrt(2)`. It is because of the fact that there are 3 distinct eigenvalues to begin with, that you see that there is a one-dimensional subspace for 2. Please check that the vectors `[1, sqrt(2), 1]` and `[1, -sqrt(2), 1]` are also eigenvectors.
I highly suspect that for whatever reason, Sage is just implementing my matrix as if it was in `QQ` all along while disregarding the input field. I will now update a new bit of experimentation I did in my question.Thu, 31 Aug 2023 09:07:20 +0200https://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/?comment=73073#post-id-73073Comment by John Palmieri for <p>I ran the following code:</p>
<p><code>
A = matrix(QQbar, [[2,-1,0],[-1,2,1],[0,-1,2]]);
D, P = A.diagonalization()
</code></p>
<p>This generated a value error saying that A is not diagonalisable. To see if there are workarounds, I replaced the <code>diagonalization</code> method by <code>eigenmatrix_right()</code>, and the results were weird.</p>
<p><code>D</code> was twice the identity matrix, and <code>P</code> had zero vectors in its creation. I think writing <code>QQbar</code> to make the thing work in algebraic numbers is not proving fruitful at all, because replacing it with <code>QQ</code> yields exactly the same result.</p>
<p>UPD1: I thought that the issue might lie with the implementation of <code>QQbar</code>, so I tried it <code>Q[sqrt(2)]</code> instead, which does indeed contain the eigenvalues of my matrix: <code>2, 2 + \sqrt(2), 2 - \sqrt(2)</code>, and the entries of the corresponding eigenvectors as well, but to no avail. I think it's the matrix construction mechanism itself which is faulty here. Unless addressed soon, I suppose I would remove the <code>QQbar</code> tag from the question then.</p>
<p>UPD2: Closed, A wasn't entered correctly, was the issue.</p>
https://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/?comment=73067#post-id-73067In the last paragraph, what do you mean by `D` and `P`? They can't have been the values returned by `A.diagonalization()`, since that fails.Thu, 31 Aug 2023 04:14:36 +0200https://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/?comment=73067#post-id-73067Comment by John Palmieri for <p>I ran the following code:</p>
<p><code>
A = matrix(QQbar, [[2,-1,0],[-1,2,1],[0,-1,2]]);
D, P = A.diagonalization()
</code></p>
<p>This generated a value error saying that A is not diagonalisable. To see if there are workarounds, I replaced the <code>diagonalization</code> method by <code>eigenmatrix_right()</code>, and the results were weird.</p>
<p><code>D</code> was twice the identity matrix, and <code>P</code> had zero vectors in its creation. I think writing <code>QQbar</code> to make the thing work in algebraic numbers is not proving fruitful at all, because replacing it with <code>QQ</code> yields exactly the same result.</p>
<p>UPD1: I thought that the issue might lie with the implementation of <code>QQbar</code>, so I tried it <code>Q[sqrt(2)]</code> instead, which does indeed contain the eigenvalues of my matrix: <code>2, 2 + \sqrt(2), 2 - \sqrt(2)</code>, and the entries of the corresponding eigenvectors as well, but to no avail. I think it's the matrix construction mechanism itself which is faulty here. Unless addressed soon, I suppose I would remove the <code>QQbar</code> tag from the question then.</p>
<p>UPD2: Closed, A wasn't entered correctly, was the issue.</p>
https://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/?comment=73066#post-id-73066Maybe this is a silly question, but why do you think that this matrix is diagonalizable? All of its eigenvalues are 2, and it only seems to have a one-dimensional subspace of eigenvectors.Thu, 31 Aug 2023 04:14:03 +0200https://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/?comment=73066#post-id-73066Answer by JTS for <p>I ran the following code:</p>
<p><code>
A = matrix(QQbar, [[2,-1,0],[-1,2,1],[0,-1,2]]);
D, P = A.diagonalization()
</code></p>
<p>This generated a value error saying that A is not diagonalisable. To see if there are workarounds, I replaced the <code>diagonalization</code> method by <code>eigenmatrix_right()</code>, and the results were weird.</p>
<p><code>D</code> was twice the identity matrix, and <code>P</code> had zero vectors in its creation. I think writing <code>QQbar</code> to make the thing work in algebraic numbers is not proving fruitful at all, because replacing it with <code>QQ</code> yields exactly the same result.</p>
<p>UPD1: I thought that the issue might lie with the implementation of <code>QQbar</code>, so I tried it <code>Q[sqrt(2)]</code> instead, which does indeed contain the eigenvalues of my matrix: <code>2, 2 + \sqrt(2), 2 - \sqrt(2)</code>, and the entries of the corresponding eigenvectors as well, but to no avail. I think it's the matrix construction mechanism itself which is faulty here. Unless addressed soon, I suppose I would remove the <code>QQbar</code> tag from the question then.</p>
<p>UPD2: Closed, A wasn't entered correctly, was the issue.</p>
https://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/?answer=73079#post-id-73079Your matrix is not symmetric:
A = matrix(QQbar, [[2,-1,0],[-1,2,1],[0,-1,2]])
A.is_symmetric()Thu, 31 Aug 2023 12:50:40 +0200https://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/?answer=73079#post-id-73079Comment by yeetcode for <p>Your matrix is not symmetric:</p>
<pre><code>A = matrix(QQbar, [[2,-1,0],[-1,2,1],[0,-1,2]])
A.is_symmetric()
</code></pre>
https://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/?comment=73099#post-id-73099My bad. I wished to work with `A[1,2] = -1` instead. There are still issues, but nothing like whatever I wrote here. Thanks to you and John for this!Fri, 01 Sep 2023 00:17:42 +0200https://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/?comment=73099#post-id-73099