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.Sat, 13 Dec 2014 12:12:36 -0600Plotting the effects of a linear transformation on a gridhttp://ask.sagemath.org/question/10691/plotting-the-effects-of-a-linear-transformation-on-a-grid/I am a student taking a first undergraduate course in linear algebra, and I would like to play around with plots of transformations of the type $T:\mathbb{R}^2\rightarrow\mathbb{R}^2$. I already know a bit of python, so I'm not looking for anyone to write a program for me, but I would really appreciate some tips/general outline of how to do things.
1) First I want to make a grid that I can plot, and then transform by multiplying it with a matrix. Where's the best way to start? Should I use parametric_plot, or maybe it can be done with just a list of **vector([x,y])**'s?
2) Second I want to run the grid through a linear transformation. If I could just plot vectors and offset them (not having them start at the origin), I would only only have to iterate over a list of vectors to get the transformed vectors, but I'm not sure if this is a smart way to do it.
Basically, is there a straight forward way to do this? It doesn't seem like it should be very difficult, if someone could give a rough outline of how to do this it would be greatly appreciated.
Thanks.
Sun, 03 Nov 2013 02:13:24 -0600http://ask.sagemath.org/question/10691/plotting-the-effects-of-a-linear-transformation-on-a-grid/Answer by tmonteil for <p>I am a student taking a first undergraduate course in linear algebra, and I would like to play around with plots of transformations of the type $T:\mathbb{R}^2\rightarrow\mathbb{R}^2$. I already know a bit of python, so I'm not looking for anyone to write a program for me, but I would really appreciate some tips/general outline of how to do things.</p>
<p>1) First I want to make a grid that I can plot, and then transform by multiplying it with a matrix. Where's the best way to start? Should I use parametric_plot, or maybe it can be done with just a list of <strong>vector([x,y])</strong>'s?</p>
<p>2) Second I want to run the grid through a linear transformation. If I could just plot vectors and offset them (not having them start at the origin), I would only only have to iterate over a list of vectors to get the transformed vectors, but I'm not sure if this is a smart way to do it.</p>
<p>Basically, is there a straight forward way to do this? It doesn't seem like it should be very difficult, if someone could give a rough outline of how to do this it would be greatly appreciated. </p>
<p>Thanks.</p>
http://ask.sagemath.org/question/10691/plotting-the-effects-of-a-linear-transformation-on-a-grid/?answer=15646#post-id-15646I would advise to work with a list of vectors and make loops as you suggested, this is a smart way. You can write a function `grid(v1, v2)` (plus fancy parameters) and apply it to `grid(M*v1, M*v2)` for some matrix `M`.
About Sage, i would start by:
sage: M = matrix(QQ, [[1,1],[1,0]])
sage: V = VectorSpace(QQ, 2)
sage: v1, v2 = V.basis()
So that my vectors live in a safe place (you can of course replace `QQ` with another field if needed, typically if you want to draw rotations using sinus and cosinus). Then, after defining a `grid()` function that returns a `Graphics()` object built as a sum of `lines()`, i would write:
sage: grid(v1, v2, color='blue') + grid(M*v1, M*v2, color='red')
To get something like that picture:
![grids](http://ask.sagemath.org/upfiles/13834909894465627.png)
Do not hesitate to ask for details about the `grid()` function if needed.
Sun, 03 Nov 2013 02:45:59 -0600http://ask.sagemath.org/question/10691/plotting-the-effects-of-a-linear-transformation-on-a-grid/?answer=15646#post-id-15646Comment by tmonteil for <p>I would advise to work with a list of vectors and make loops as you suggested, this is a smart way. You can write a function <code>grid(v1, v2)</code> (plus fancy parameters) and apply it to <code>grid(M*v1, M*v2)</code> for some matrix <code>M</code>.</p>
<p>About Sage, i would start by:</p>
<pre><code>sage: M = matrix(QQ, [[1,1],[1,0]])
sage: V = VectorSpace(QQ, 2)
sage: v1, v2 = V.basis()
</code></pre>
<p>So that my vectors live in a safe place (you can of course replace <code>QQ</code> with another field if needed, typically if you want to draw rotations using sinus and cosinus). Then, after defining a <code>grid()</code> function that returns a <code>Graphics()</code> object built as a sum of <code>lines()</code>, i would write:</p>
<pre><code>sage: grid(v1, v2, color='blue') + grid(M*v1, M*v2, color='red')
</code></pre>
<p>To get something like that picture:</p>
<p><img alt="grids" src="http://ask.sagemath.org/upfiles/13834909894465627.png"/></p>
<p>Do not hesitate to ask for details about the <code>grid()</code> function if needed.</p>
http://ask.sagemath.org/question/10691/plotting-the-effects-of-a-linear-transformation-on-a-grid/?comment=25249#post-id-25249You can try something like:
def grid(v1,v2,endpoints=[-5,5,-5,5], color='blue'):
G = Graphics()
for i in range(endpoints[0], endpoints[1]):
for j in range(endpoints[2], endpoints[3]):
G += line([i*v1 + j*v2, (i+1)*v1 + j*v2], color=color, aspect_ratio=1)
G += line([i*v1 + j*v2, i*v1 + (j+1)*v2], color=color, aspect_ratio=1)
return G
and then use as:
grid(vector([0,1]),vector([1,0]))Sat, 13 Dec 2014 12:12:36 -0600http://ask.sagemath.org/question/10691/plotting-the-effects-of-a-linear-transformation-on-a-grid/?comment=25249#post-id-25249Comment by sairahul for <p>I would advise to work with a list of vectors and make loops as you suggested, this is a smart way. You can write a function <code>grid(v1, v2)</code> (plus fancy parameters) and apply it to <code>grid(M*v1, M*v2)</code> for some matrix <code>M</code>.</p>
<p>About Sage, i would start by:</p>
<pre><code>sage: M = matrix(QQ, [[1,1],[1,0]])
sage: V = VectorSpace(QQ, 2)
sage: v1, v2 = V.basis()
</code></pre>
<p>So that my vectors live in a safe place (you can of course replace <code>QQ</code> with another field if needed, typically if you want to draw rotations using sinus and cosinus). Then, after defining a <code>grid()</code> function that returns a <code>Graphics()</code> object built as a sum of <code>lines()</code>, i would write:</p>
<pre><code>sage: grid(v1, v2, color='blue') + grid(M*v1, M*v2, color='red')
</code></pre>
<p>To get something like that picture:</p>
<p><img alt="grids" src="http://ask.sagemath.org/upfiles/13834909894465627.png"/></p>
<p>Do not hesitate to ask for details about the <code>grid()</code> function if needed.</p>
http://ask.sagemath.org/question/10691/plotting-the-effects-of-a-linear-transformation-on-a-grid/?comment=16406#post-id-16406I am new to sage, Can you share details about how can i implement grid function ?. Wed, 22 Jan 2014 20:15:48 -0600http://ask.sagemath.org/question/10691/plotting-the-effects-of-a-linear-transformation-on-a-grid/?comment=16406#post-id-16406