%autosave 0 %matplotlib inline from sglib import * input_vector = col(5,2) # Put your vector here. #matrix = Matrix([(2,0),(0,2)]) # Put your matrix here. # # Or, uncomment one of the matrices below # #matrix = Matrix([(-1,0),(0,-1)]) # Minus Operator #matrix = Matrix([(1,0),(0,-1)]) # X Reflect Operator #matrix = Matrix([(-1,0),(0,1)]) # Y Reflect Operator matrix = Matrix([(0,1),(1,0)]) # Not Operator # For the rotation operation, note that theta is in # radians, not degrees. So, for example, pi/2 would # give you 90 degrees, pi/4 would give you 45 degrees. from sympy import pi, sin, cos theta=pi/6 a = cos(theta); b=-sin(theta); c=sin(theta); d=cos(theta) #matrix = Matrix([(a,b),(c,d)]) # Rotation Operator # # You probably won't want to change anything below here. # (Unless you want to change the colors below) # # In the next line, the matrix "operates" on the vector output_vector = matrix * input_vector # This line contains special code to print the math nicely Print(r'$%s%s=%s$' %( myltx(matrix), myltx(input_vector), myltx(output_vector) )) # The variable "D" results from a calculation that tells how # "big" we need to draw the plane and the vectors that go on it. D = max(1,abs(input_vector[0]), abs(input_vector[1]), abs(output_vector[0]), abs(output_vector[1])) D = float(D)*1.3 # Draw a 2D plane and then draw the input and out vectors. # Here you can change the colors if you want to (but be sure # to change the colors in the "title" also). draw_plane(domain=[-D, D, -D, D]) pylab.title('input vector blue\n ouput vector green', fontsize=16) draw_vector(input_vector, color='blue', scale=D) draw_vector(output_vector, color='green', scale=D)