ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 25 Feb 2016 08:47:49 -0600How do I enter an imaginary number into a matrixhttp://ask.sagemath.org/question/32665/how-do-i-enter-an-imaginary-number-into-a-matrix/ In a very simple example, I am created a 2 by 2 matrix like this
var('i')
ran40 = matrix(QQ,2,2,[[2*i,-2],[3,4]])
show(ran40)
I need to eventually call `show(ran40.rref())` so that I can see the reduced row echelon form of the above matrix. But I get syntax errors in the creation of the matrix above.
How do I simply put the imaginary letter *i* into a matrix and then it actually be computed on. That is, the imaginart "part" is actually used in the RREF computation.Wed, 24 Feb 2016 22:43:08 -0600http://ask.sagemath.org/question/32665/how-do-i-enter-an-imaginary-number-into-a-matrix/Comment by kcrisman for <p>In a very simple example, I am created a 2 by 2 matrix like this</p>
<pre><code>var('i')
ran40 = matrix(QQ,2,2,[[2*i,-2],[3,4]])
show(ran40)
</code></pre>
<p>I need to eventually call <code>show(ran40.rref())</code> so that I can see the reduced row echelon form of the above matrix. But I get syntax errors in the creation of the matrix above. </p>
<p>How do I simply put the imaginary letter <em>i</em> into a matrix and then it actually be computed on. That is, the imaginart "part" is actually used in the RREF computation.</p>
http://ask.sagemath.org/question/32665/how-do-i-enter-an-imaginary-number-into-a-matrix/?comment=32670#post-id-32670See also the question (and answer) at http://stackoverflow.com/questions/35618283/cant-enter-imaginary-numbers-in-sagemathcloud/Thu, 25 Feb 2016 08:47:49 -0600http://ask.sagemath.org/question/32665/how-do-i-enter-an-imaginary-number-into-a-matrix/?comment=32670#post-id-32670Answer by tmonteil for <p>In a very simple example, I am created a 2 by 2 matrix like this</p>
<pre><code>var('i')
ran40 = matrix(QQ,2,2,[[2*i,-2],[3,4]])
show(ran40)
</code></pre>
<p>I need to eventually call <code>show(ran40.rref())</code> so that I can see the reduced row echelon form of the above matrix. But I get syntax errors in the creation of the matrix above. </p>
<p>How do I simply put the imaginary letter <em>i</em> into a matrix and then it actually be computed on. That is, the imaginart "part" is actually used in the RREF computation.</p>
http://ask.sagemath.org/question/32665/how-do-i-enter-an-imaginary-number-into-a-matrix/?answer=32668#post-id-32668When you write `var('i')`, you define `i` as a symbol. In particular, `2*i` is an element of the symbolic ring, not the rationals, but you ask that `2*i` be an entry of a matrix whose coefficients are rationals (because of the `QQ` at the beginnig).
If you want the imaginary number, you should use the already defined `I`, if you want a matrix over, say the algabraic numbers `QQbar` (so that `I` in an element), you should write:
sage: matrix(QQbar,2,2,[[2*I,-2],[3,4]])
[2*I -2]
[ 3 4]
Thu, 25 Feb 2016 05:14:21 -0600http://ask.sagemath.org/question/32665/how-do-i-enter-an-imaginary-number-into-a-matrix/?answer=32668#post-id-32668