from playLA.Matrix import Matrix from playLA.LU import lu if __name__ == "__main__": A = Matrix([[1, 2, 3], [4, 5, 6], [3, -3, 5]]) L, U = lu(A) print(L) print(U) print(L.dot(U))
from playLA.Matrix import Matrix from playLA.Vector import Vector from playLA.LinearSystem import LinearSystem from playLA.LinearSystem import inv, rank if __name__ == "__main__": A = Matrix([[1, 2, 4], [3, 7, 2], [2, 3, 3]]) b = Vector([7, -11, 1]) ls = LinearSystem(A, b) ls.gauss_jordan_elimination() ls.fancy_print() print() # [-1, -2, 3] A2 = Matrix([[1, -3, 5], [2, -1, -3], [3, 1, 4]]) b2 = Vector([-9, 19, -13]) ls2 = LinearSystem(A2, b2) ls2.gauss_jordan_elimination() ls2.fancy_print() print() # [2, -3, -4] A3 = Matrix([[1, 2, -2], [2, -3, 1], [3, -1, 3]]) b3 = Vector([6, -10, -16]) ls3 = LinearSystem(A3, b3) ls3.gauss_jordan_elimination() ls3.fancy_print() print() # [-2, 1, -3]
import matplotlib.pyplot as plt from playLA.Matrix import Matrix from playLA.Vector import Vector if __name__ == "__main__": points = [[0, 0], [0, 5], [3, 5], [3, 4], [1, 4], [1, 3], [2, 3], [2, 2], [1, 2], [1, 0]] x = [e[0] for e in points] y = [e[1] for e in points] plt.figure(figsize=(5, 5)) plt.xlim(-10, 10) plt.ylim(-10, 10) plt.plot(x, y) # plt.show() P = Matrix(points) # print(P.shape()) # T = Matrix([[2, 0], [0, 1.5]]) T = Matrix([[1, 0], [0, -1]]) P2 = T.dot(P.T()) # plt.plot(P2.row_vector(0), P2.row_vector(1)) plt.plot([P2.col_vector(i)[0] for i in range(P2.col_num())], [P2.col_vector(i)[1] for i in range(P2.col_num())]) plt.show()
from playLA.Matrix import Matrix from playLA.Vector import Vector if __name__ == "__main__": matrix = Matrix([[1, 2], [3, 4]]) print(matrix) print("matrix.shape = {}".format(matrix.shape())) print("matrix.size = {}".format(matrix.size())) print("len(matrix) = {}".format(len(matrix))) print("matrix[0][0] = {}".format(matrix[0, 0])) print("matrix's row[0] vector = {}".format(matrix.row_vector(0))) print("matrix's col[0] vector = {}".format(matrix.col_vector(0))) matrix2 = Matrix([[5, 6], [7, 8]]) print(matrix2) print("add: {}".format(matrix + matrix2)) print("subtract: {}".format(matrix - matrix2)) print("scalar-mul: {}".format(matrix * 2)) print("re-scalar-mul: {}".format(2 * matrix)) print("zero_2_3: {}".format(Matrix.zero(2, 3))) T = Matrix([[1.5, 0], [0, 2]]) p = Vector([5, 3]) print("T.dot(p) = {}".format(T.dot(p))) P = Matrix([[0, 4, 5], [0, 0, 3]]) print("T.dot(P) = {}".format(T.dot(P))) print("A.dot(B) = {}".format(matrix.dot(matrix2))) print("B.dot(A) = {}".format(matrix2.dot(matrix)))
from playLA.Matrix import Matrix from playLA.Vector import Vector if __name__ == "__main__": matrix = Matrix([[1, 2], [3, 4]]) print(matrix) print(matrix.row_vector(0)) matrix2 = Matrix([[5, 6], [7, 8]]) print("add: {}".format(matrix + matrix2)) print("sub: {}".format(matrix - matrix2)) print("zero_2_3: {}".format(Matrix.zero(2, 3))) T = Matrix([[1.5, 0], [0, 2]]) p = Vector([5, 3]) print("T.dot(p) = {}".format(T.dot(p))) P = Matrix([[0, 4, 5], [0, 0, 3]]) print("T.dot(P) = {}".format(T.dot(P))) print("A.dot(B) = {}".format(matrix.dot(matrix2))) print("B.dot(A) = {}".format(matrix2.dot(matrix))) print("P.T = {} ".format(P.T()))
import math if __name__ == "__main__": points = [[0, 0], [0, 5], [3, 5], [3, 4], [1, 4], [1, 3], [2, 3], [2, 2], [1, 2], [1, 0]] x = [point[0] for point in points] y = [point[1] for point in points] plt.figure(figsize=(5, 5)) plt.xlim(-10, 10) plt.ylim(-10, 10) plt.plot(x, y) # plt.show() P = Matrix(points) # print(P) # T = Matrix([[2, 0], [0, 1.5]]) # T: 2 * 2 P: 10 * 2 # T = Matrix([[1, 0], [0, -1]]) # T = Matrix([[-1, 0], [0, 1]]) # T = Matrix([[-1, 0], [0, -1]]) # T = Matrix([[1, 1], [0, 1]]) # T = Matrix([[1, 0], [1, 1]]) # T = Matrix([[1, 0.5], [1, 1]]) # T = Matrix([[1, 0.5], [1, 1]]) theta = math.pi / 3 T = Matrix([[math.cos(theta), math.sin(theta)], [-math.sin(theta), math.cos(theta)]]) P2 = T.dot(P.T()) # P2: 2 * 10
from playLA.Matrix import Matrix from playLA.LU import lu if __name__ == "__main__": A1 = Matrix([[1, 2, 3], [4, 5, 6], [3, -3, 5]]) L1, U1 = lu(A1) print(L1) print(U1) print(L1.dot(U1)) print() A2 = Matrix([[1, 4, 5, 3], [5, 22, 27, 11], [6, 19, 27, 31], [5, 28, 35, -8]]) L2, U2 = lu(A2) print(L2) print(U2) print(L2.dot(U2)) print() A3 = Matrix([[1, 2, 3], [3, 7, 14], [4, 13, 38]]) L3, U3 = lu(A3) print(L3) print(U3) print(L3.dot(U3)) print()
from playLA.Matrix import Matrix if __name__ == "__main__": matrix = Matrix([[1, 2], [3, 4]]) print(matrix) print("matrix.shape = {}".format(matrix.shape())) print("matrix.size = {}".format(matrix.size())) print("len(matrix) = {}".format(len(matrix))) print("matrix[0][0] = {}".format(matrix[0, 0]))
import matplotlib.pyplot as plt from playLA.Matrix import Matrix from playLA.Vector import Vector import math if __name__ == "__main__": points = [[0, 0], [0, 5], [3, 5], [3, 4], [1, 4], [1, 3], [2, 3], [2, 2], [1, 2], [1, 0]] x = [point[0] for point in points] y = [point[1] for point in points] plt.figure(figsize=(5, 5)) plt.xlim(-10, 10) plt.ylim(-10, 10) plt.plot(x, y) P = Matrix(points) T = Matrix([[2, 0], [0, 1.5]]) P2 = T.dot(P.T()) plt.plot([P2.col_vector(i)[0] for i in range(P2.col_num())], [P2.col_vector(i)[1] for i in range(P2.col_num())]) plt.show()
from playLA.Matrix import Matrix from playLA.GramSchmidtProcess import qr if __name__ == "__main__": A1 = Matrix([[1, 1, 2], [1, 1, 0], [1, 0, 0]]) Q1, R1 = qr(A1) print(Q1) print(R1) print(Q1.dot(R1))