ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 01 Aug 2019 02:37:13 -0500can't display the inverse of complex matrixhttps://ask.sagemath.org/question/47326/cant-display-the-inverse-of-complex-matrix/ Hi
it seems that Sagemath is able to calculate this matrix inverse, but it is unable to display it.
Maybe someone will explain me why ? it is not easy to find what I do wrong because there is no error message for n=8
an it's ok for n=4
#FFT
w=var('w')
n=8
FFT=matrix(SR,n,n)
#show (FFT)
for i in (0..n-1):
for j in (0..n-1):
FFT[i,j]=w^(i*j)
FFTc=1/sqrt(n) *FFT.subs(w=e^(2*I*pi/n))
#show(" FFTc : ",FFTc)
FFTc.change_ring(CC)
show(" FFTc.right_kernel().matrix() : ",FFTc.right_kernel().matrix())
show (" FFTc.determinant() for n =",str(n),": ",FFTc.determinant())
FFTcI=copy(FFTc).inverse()
#show (" FFT w :",FFT)
show (" FFTc with w=e^(2*I*pi/",str(n),") : ",FFTc)
show (" FFTc inverse with w=e^(2*I*pi/",str(n),") : ",FFTcI)
Wed, 31 Jul 2019 11:19:16 -0500https://ask.sagemath.org/question/47326/cant-display-the-inverse-of-complex-matrix/Answer by Emmanuel Charpentier for <p>Hi</p>
<p>it seems that Sagemath is able to calculate this matrix inverse, but it is unable to display it.</p>
<p>Maybe someone will explain me why ? it is not easy to find what I do wrong because there is no error message for n=8
an it's ok for n=4</p>
<pre><code>#FFT
w=var('w')
n=8
FFT=matrix(SR,n,n)
#show (FFT)
for i in (0..n-1):
for j in (0..n-1):
FFT[i,j]=w^(i*j)
FFTc=1/sqrt(n) *FFT.subs(w=e^(2*I*pi/n))
#show(" FFTc : ",FFTc)
FFTc.change_ring(CC)
show(" FFTc.right_kernel().matrix() : ",FFTc.right_kernel().matrix())
show (" FFTc.determinant() for n =",str(n),": ",FFTc.determinant())
FFTcI=copy(FFTc).inverse()
#show (" FFT w :",FFT)
show (" FFTc with w=e^(2*I*pi/",str(n),") : ",FFTc)
show (" FFTc inverse with w=e^(2*I*pi/",str(n),") : ",FFTcI)
</code></pre>
https://ask.sagemath.org/question/47326/cant-display-the-inverse-of-complex-matrix/?answer=47330#post-id-47330AFAICT, the computations go just fine. One can print any element of the inverse matrix (a very large SR expression).
However, the resultant expressions are way to large for Mathjax (or even for \LaTeX) to cope. Therefore, `show` (or `view`) fails spectacularly.
One possible solution is to change ring to QQbar (which is still an exact field). That way, you still can do exact computations *and* print your results.
Another could be to change ring to a suitably choose cyclotomic field (left as an exercise to the reader...).
HTH,
Thu, 01 Aug 2019 01:47:31 -0500https://ask.sagemath.org/question/47326/cant-display-the-inverse-of-complex-matrix/?answer=47330#post-id-47330Comment by ortollj for <p>AFAICT, the computations go just fine. One can print any element of the inverse matrix (a very large SR expression).</p>
<p>However, the resultant expressions are way to large for Mathjax (or even for \LaTeX) to cope. Therefore, <code>show</code> (or <code>view</code>) fails spectacularly.</p>
<p>One possible solution is to change ring to QQbar (which is still an exact field). That way, you still can do exact computations <em>and</em> print your results.</p>
<p>Another could be to change ring to a suitably choose cyclotomic field (left as an exercise to the reader...).</p>
<p>HTH,</p>
https://ask.sagemath.org/question/47326/cant-display-the-inverse-of-complex-matrix/?comment=47332#post-id-47332But it is also ok when changing ring in QQbar, thank Emmanuel.
[reference doc](http://doc.sagemath.org/html/en/reference/matrices/sage/matrix/matrix2.html)
[Gilbert Strang on MIT ocw](https://ocw.mit.edu/courses/mathematics/18-06-linear-algebra-spring-2010/video-lectures/lecture-26-complex-matrices-fast-fourier-transform/)Thu, 01 Aug 2019 02:37:13 -0500https://ask.sagemath.org/question/47326/cant-display-the-inverse-of-complex-matrix/?comment=47332#post-id-47332Comment by ortollj for <p>AFAICT, the computations go just fine. One can print any element of the inverse matrix (a very large SR expression).</p>
<p>However, the resultant expressions are way to large for Mathjax (or even for \LaTeX) to cope. Therefore, <code>show</code> (or <code>view</code>) fails spectacularly.</p>
<p>One possible solution is to change ring to QQbar (which is still an exact field). That way, you still can do exact computations <em>and</em> print your results.</p>
<p>Another could be to change ring to a suitably choose cyclotomic field (left as an exercise to the reader...).</p>
<p>HTH,</p>
https://ask.sagemath.org/question/47326/cant-display-the-inverse-of-complex-matrix/?comment=47331#post-id-47331but the simplest way is : as FFTc is orthogonal , I just have to get Hermitian FFTc for the inverse !
[sage Cell](https://sagecell.sagemath.org/?z=eJyNUz1v2zAQ3fkrrvIQUmGVJlMRgOhgIIgGLW63IAlYmZbOiE8OSVtNf335ISU2spSDwLvH9-7xTlybDdjhQOtGe4t_eCOduGUQVuFURpA6cPjXFCm9kkvVVGvcGXI4kOMipRur2mH_xpscbgYLFpCAf6uq1ddrAVl0xtoZWwbsA8pKD1a2jyrV5tCkqLJGv3ABwd3lOYA73WWgrM90UmCNP1gKmowt7u5-sVEdteUX44VgpL6zkFK7fPGfK0mSBFu4fhiBB0Sw6BRnp_TuNKa3n9NxBdoDyu2jGp84llsRK7Tq-sq9Ws9JQBniyh1-Oz4q88Rvyrrc4xUJwVisy4uo0MItFDJuJn78VG2vqTPPNoyDL5eBsA9bD0Ui3Bu7Q4-a4EciJ5kK3XM_A3wqAVONam18xEiTD_0jVUjnbfAoi7n6-RGROtjWec7JXYV0NNaZoL0A7SCbRweD9f3QDaRfQEIN24Pz0OujAT9AZ_yJ3cSIDfW9gUkOvrBPle7ZPJmpRSP6Hk6b-OFfnPTvjDPr_xe3jpcK53HzFgzl6aQQW-3Dnw9FVuenzycR45BbeSPEP_oe9ZY=&lang=sage&interacts=eJyLjgUAARUAuQ==)Thu, 01 Aug 2019 02:28:12 -0500https://ask.sagemath.org/question/47326/cant-display-the-inverse-of-complex-matrix/?comment=47331#post-id-47331Answer by nbruin for <p>Hi</p>
<p>it seems that Sagemath is able to calculate this matrix inverse, but it is unable to display it.</p>
<p>Maybe someone will explain me why ? it is not easy to find what I do wrong because there is no error message for n=8
an it's ok for n=4</p>
<pre><code>#FFT
w=var('w')
n=8
FFT=matrix(SR,n,n)
#show (FFT)
for i in (0..n-1):
for j in (0..n-1):
FFT[i,j]=w^(i*j)
FFTc=1/sqrt(n) *FFT.subs(w=e^(2*I*pi/n))
#show(" FFTc : ",FFTc)
FFTc.change_ring(CC)
show(" FFTc.right_kernel().matrix() : ",FFTc.right_kernel().matrix())
show (" FFTc.determinant() for n =",str(n),": ",FFTc.determinant())
FFTcI=copy(FFTc).inverse()
#show (" FFT w :",FFT)
show (" FFTc with w=e^(2*I*pi/",str(n),") : ",FFTc)
show (" FFTc inverse with w=e^(2*I*pi/",str(n),") : ",FFTcI)
</code></pre>
https://ask.sagemath.org/question/47326/cant-display-the-inverse-of-complex-matrix/?answer=47327#post-id-47327I think the problem is that you compute with symbolic matrices. Computations there can easily blow up horribly and I expect that is what's happening. The line:
FFTc.change_ring(CC)
produces a new matrix with complex-float entries, but since you don't assign it to anything, the resulting matrix just gets lost. You continue working with the symbolic matrix after that, and I think that just grinds to a halt due to explosion of intermediate expressions. Perhaps you meant to compute with a float approximation to the matrix instead?
Note that computing a "kernel" of a float matrix generally doesn't work, because numerically matrices of non-maximal rank aren't really distinguishable from maximal rank ones. Also computing the "inverse" numerically is generally tricky and requires special measures to get a bit of numerical stability. Sage unfortunately doesn't do that by default (in part because you're probably doing something wrong if you're computing an inverse numerically).Wed, 31 Jul 2019 11:47:21 -0500https://ask.sagemath.org/question/47326/cant-display-the-inverse-of-complex-matrix/?answer=47327#post-id-47327Comment by ortollj for <p>I think the problem is that you compute with symbolic matrices. Computations there can easily blow up horribly and I expect that is what's happening. The line:</p>
<pre><code>FFTc.change_ring(CC)
</code></pre>
<p>produces a new matrix with complex-float entries, but since you don't assign it to anything, the resulting matrix just gets lost. You continue working with the symbolic matrix after that, and I think that just grinds to a halt due to explosion of intermediate expressions. Perhaps you meant to compute with a float approximation to the matrix instead?</p>
<p>Note that computing a "kernel" of a float matrix generally doesn't work, because numerically matrices of non-maximal rank aren't really distinguishable from maximal rank ones. Also computing the "inverse" numerically is generally tricky and requires special measures to get a bit of numerical stability. Sage unfortunately doesn't do that by default (in part because you're probably doing something wrong if you're computing an inverse numerically).</p>
https://ask.sagemath.org/question/47326/cant-display-the-inverse-of-complex-matrix/?comment=47328#post-id-47328ok, thank you nbruinWed, 31 Jul 2019 13:15:34 -0500https://ask.sagemath.org/question/47326/cant-display-the-inverse-of-complex-matrix/?comment=47328#post-id-47328