import matplotlib.pyplot as plt import matplotlib.patches as patches import numpy as np # Vi ser p? virkningen av en 2x2-matrise A: R^2 --> R^2. # Permutering P = np.array([[0,1], [1,0]]) # Skalering q = 2 S = np.array([[q,0], [0,1]]) # Forskyvning k = 1/2 F = np.array([[1,k], [0,1]]) # Rotasjon om origo theta = -np.pi/6 rho = [[np.cos(theta),-np.sin(theta)], [np.sin(theta),np.cos(theta)]] # Speiling om linje y = c*x c = -1 R = [[(1-np.power(c,2))/(np.power(c,2)+1),2*c/(np.power(c,2)+1)], [2*c/(np.power(c,2)+1),(np.power(c,2)-1)/(np.power(c,2)+1)]] # Velg din matrise A = [[2,-2], [1, 2]] A = R # Setter opp figur for "input" R^2. fig1 = plt.figure() ax1 = fig1.add_subplot(aspect='equal') r = np.sqrt(2) # For ? ha god plass. ax1.set_xlim(-r, r) ax1.set_ylim(-r, r) # Vi deler [-1,1] i fire kvadrater som vi farger bl?, r?d, gul og gr?nn. points = [[0, 0], [0, 1], [1, 1], [1, 0]] ax1.add_patch(plt.Polygon(points, fill=True, color='blue')) points = [[0, 0], [0, 1], [-1, 1], [-1, 0], [0,0]] ax1.add_patch(plt.Polygon(points, fill=True, color='red')) points = [[0, 0], [0, -1], [-1, -1], [-1, 0]] ax1.add_patch(plt.Polygon(points, fill=True, color='green')) points = [[0, 0], [0, -1], [1, -1], [1, 0]] ax1.add_patch(plt.Polygon(points, fill=True, color='yellow')) # Setter opp figur for "output" R^2 fig2 = plt.figure() ax2 = fig2.add_subplot(aspect='equal') rA = np.linalg.norm(A,2) * np.sqrt(2) # For ? ha god plass. ax2.set_xlim(-rA, rA) ax2.set_ylim(-rA, rA) # Vi bruker A p? de fire kvadratene og tegner parallellogrammene i samme farge. points = [np.matmul(A,[0, 0]), np.matmul(A,[0, 1]), np.matmul(A,[1, 1]), np.matmul(A,[1, 0])] ax2.add_patch(plt.Polygon(points, fill=True, color='blue')) points = [np.matmul(A,[0, 0]), np.matmul(A,[0, 1]), np.matmul(A,[-1, 1]), np.matmul(A,[-1, 0]), np.matmul(A,[0,0])] ax2.add_patch(plt.Polygon(points, fill=True, color='red')) points = [np.matmul(A,[0, 0]), np.matmul(A,[0, -1]), np.matmul(A,[-1, -1]), np.matmul(A,[-1, 0])] ax2.add_patch(plt.Polygon(points, fill=True, color='green')) points = [np.matmul(A,[0, 0]), np.matmul(A,[0, -1]), np.matmul(A,[1, -1]), np.matmul(A,[1, 0])] ax2.add_patch(plt.Polygon(points, fill=True, color='yellow'))