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.Tue, 06 May 2014 04:58:37 -0500- Linear Transformation Matrix is Transposedhttp://ask.sagemath.org/question/11088/linear-transformation-matrix-is-transposed/I define a linear transformation object using the following syntax:
def f(v):
l1 = [2*v[0]+3*v[1], 5*v[0]-v[1]]
v1 = vector(l1)
return(v1)
lf = linear_transformation(RR^2, RR^2, f)
lf
The output includes the matrix [[2, 5], [3,-1]] instead of [[2,3], [5,-1]]. Is this a bug or am I doing something wrong?
EDIT: Specifying side="right" doesn't help.
Mon, 05 May 2014 06:53:17 -0500http://ask.sagemath.org/question/11088/linear-transformation-matrix-is-transposed/
- Answer by tmonteil for <p>I define a linear transformation object using the following syntax:</p>
<pre><code>def f(v):
l1 = [2*v[0]+3*v[1], 5*v[0]-v[1]]
v1 = vector(l1)
return(v1)
lf = linear_transformation(RR^2, RR^2, f)
lf
</code></pre>
<p>The output includes the matrix [[2, 5], [3,-1]] instead of [[2,3], [5,-1]]. Is this a bug or am I doing something wrong?</p>
<p>EDIT: Specifying side="right" doesn't help.</p>
http://ask.sagemath.org/question/11088/linear-transformation-matrix-is-transposed/?answer=16126#post-id-16126Both `f` and `lf` are maps, not matrices. Ther is no ambiguity on the side of the action. The `side` option only applies on `linear_transformation()` when it is built from a matrix (there is an ambiguity since a matrix creates two linear maps depending on whether one consider the action on the left or on the right). In Sage, the matrix are by default acting on the right (i mean vectors are on the left, see for example the `.kernel()` method), which is what you see in the *representation* of `lf`. There is no problem here:
sage: f([0,1])
(3, -1)
sage: lf([0,1])
(3.00000000000000, -1.00000000000000)
sage: f([1,0])
(2, 5)
sage: lf([1,0])
(2.00000000000000, 5.00000000000000)
Now, if you want the matrix associated to the linear map `lf` with respect to the canonical basis, you can ask:
sage: lf.matrix(side='right')
[ 2.00000000000000 3.00000000000000]
[ 5.00000000000000 -1.00000000000000]
or
sage: lf.matrix(side='left')
[ 2.00000000000000 5.00000000000000]
[ 3.00000000000000 -1.00000000000000]
depending on whether you want the matrix to act on the left or on the right.
Mon, 05 May 2014 10:10:47 -0500http://ask.sagemath.org/question/11088/linear-transformation-matrix-is-transposed/?answer=16126#post-id-16126
- Comment by kcrisman for <p>Both <code>f</code> and <code>lf</code> are maps, not matrices. Ther is no ambiguity on the side of the action. The <code>side</code> option only applies on <code>linear_transformation()</code> when it is built from a matrix (there is an ambiguity since a matrix creates two linear maps depending on whether one consider the action on the left or on the right). In Sage, the matrix are by default acting on the right (i mean vectors are on the left, see for example the <code>.kernel()</code> method), which is what you see in the <em>representation</em> of <code>lf</code>. There is no problem here:</p>
<pre><code>sage: f([0,1])
(3, -1)
sage: lf([0,1])
(3.00000000000000, -1.00000000000000)
sage: f([1,0])
(2, 5)
sage: lf([1,0])
(2.00000000000000, 5.00000000000000)
</code></pre>
<p>Now, if you want the matrix associated to the linear map <code>lf</code> with respect to the canonical basis, you can ask:</p>
<pre><code>sage: lf.matrix(side='right')
[ 2.00000000000000 3.00000000000000]
[ 5.00000000000000 -1.00000000000000]
</code></pre>
<p>or</p>
<pre><code>sage: lf.matrix(side='left')
[ 2.00000000000000 5.00000000000000]
[ 3.00000000000000 -1.00000000000000]
</code></pre>
<p>depending on whether you want the matrix to act on the left or on the right.</p>
http://ask.sagemath.org/question/11088/linear-transformation-matrix-is-transposed/?comment=16176#post-id-16176Okay, now I see why I was on the 'right' track but it didn't help. Nice exposÃ© of this!Tue, 06 May 2014 04:58:37 -0500http://ask.sagemath.org/question/11088/linear-transformation-matrix-is-transposed/?comment=16176#post-id-16176
- Answer by kcrisman for <p>I define a linear transformation object using the following syntax:</p>
<pre><code>def f(v):
l1 = [2*v[0]+3*v[1], 5*v[0]-v[1]]
v1 = vector(l1)
return(v1)
lf = linear_transformation(RR^2, RR^2, f)
lf
</code></pre>
<p>The output includes the matrix [[2, 5], [3,-1]] instead of [[2,3], [5,-1]]. Is this a bug or am I doing something wrong?</p>
<p>EDIT: Specifying side="right" doesn't help.</p>
http://ask.sagemath.org/question/11088/linear-transformation-matrix-is-transposed/?answer=16125#post-id-16125Note this is the transpose of the matrix you wanted. You may want to read [the documentation](http://www.sagemath.org/doc/reference/modules/sage/modules/vector_space_morphism.html#sage.modules.vector_space_morphism.linear_transformation) carefully - you may want `side='right'`, I suppose.Mon, 05 May 2014 07:15:52 -0500http://ask.sagemath.org/question/11088/linear-transformation-matrix-is-transposed/?answer=16125#post-id-16125
- Comment by jaia for <p>Note this is the transpose of the matrix you wanted. You may want to read <a href="http://www.sagemath.org/doc/reference/modules/sage/modules/vector_space_morphism.html#sage.modules.vector_space_morphism.linear_transformation">the documentation</a> carefully - you may want <code>side='right'</code>, I suppose.</p>
http://ask.sagemath.org/question/11088/linear-transformation-matrix-is-transposed/?comment=16178#post-id-16178Tried that. It doesn't work.Mon, 05 May 2014 07:17:17 -0500http://ask.sagemath.org/question/11088/linear-transformation-matrix-is-transposed/?comment=16178#post-id-16178