plotting matrix transformations of unit ball in the p-norm

507 views
Skip to first unread message

martyall

unread,
Mar 2, 2014, 10:52:32 AM3/2/14
to sage-s...@googlegroups.com
I would like to plot the "effects" of an 2 by 2 matrix over the reals on the unit sphere in the p-norm. By effects I mean I would like to plot the unit sphere and it's image under a given matrix. In clearest case when p=2 I found the following code from trac #9728 which does exactly what I want.

@interact
def linear_transformation(
theta = slider(0, 2*pi, .1),
r = slider(0.1, 2, .1, default=1),
A = input_grid(2, 2, default = [[1,2],[0,2]],
to_value=matrix)):
"""An interact which illustrates ...
"""
v=vector([r*cos(theta), r*sin(theta)])
w = A*v

unit_sphere = circle((0,0), radius = 1, rgbcolor = (1,0,0))
var('t')
image_of_sphere = parametric_plot(A*vector([sin(t),cos(t)]),
(t, 0, 2*pi), rgbcolor=(0,0,1))

html("$v = %s,; %s w=%s$"%(v.n(4),latex(A),w.n(4)))
show(v.plot(rgbcolor=(1,0,0)) +
w.plot(rgbcolor=(0,0,1)) +
unit_sphere + image_of_sphere,
aspect_ratio=1)

I'm a total newb when it comes to plotting in sage, so I would very much appreciate the help.

Jason Grout

unread,
Mar 3, 2014, 2:08:29 PM3/3/14
to sage-s...@googlegroups.com
On 3/2/14, 9:52, martyall wrote:
> I would like to plot the "effects" of an 2 by 2 matrix over the reals
> on the unit sphere in the p-norm. By effects I mean I would like to
> plot the unit sphere and it's image under a given matrix. In clearest
> case when p=2 I found the following code from trac #9728 which does
> exactly what I want.


Like this (for 2x2 matrices)?

http://interact.sagemath.org/node/27

Thanks,

Jason

P Purkayastha

unread,
Mar 3, 2014, 9:27:18 PM3/3/14
to sage-s...@googlegroups.com

We used something like this for a class once. You can follow which point is transformed where


def vector_plotter(vec_list, points=False, **kwds):
    pic
= Graphics()
   
for c, v in zip(rainbow(len(vec_list), 'rgbtuple'), vec_list):
       
if points:
            pic
+= point(v, rgbcolor=c, **kwds)
       
else:
            pic
+= plot(v, rgbcolor=c, **kwds)
   
return pic

You can give it a list of points, and in another plot look at the list of transfrmed points.

#V is a list of vectuors
vector_plotter
(V)

vector_plotter
([M*v for v in V])
Reply all
Reply to author
Forward
0 new messages