@@ -0,0 +1,2167 @@
+# coding: utf-8%0A%0Aimport numpy as np%0Afrom numpy import linalg as la%0Aimport math %0A%0Aclass QR():%0A    def __init__(self, matrix):%0A        self.matrix  = matrix%0A        self.N = len(self.matrix)%0A        %0A    def hessenberg_matrix(self):%0A        A = self.matrix%0A        N = len(A)%0A        I = np.identity((N), dtype = float)  %0A        %0A        for i in range(N-2):%0A            A_t = np.transpose(A)%0A            sum_x_j = 0%0A            x_t = A_t%5Bi%5D          %0A            for k in range(i+1, N):%0A                sum_x_j += pow(x_t%5B0,k%5D, 2)                %0A            y_t = np.matrix(np.zeros(N))%0A            for n in range(i+1):%0A                y_t%5B0, n%5D = x_t%5B0, n%5D%0A            y_t%5B0, i+1%5D = (-np.sign(x_t%5B0, i+1%5D))*math.sqrt(sum_x_j)%0A            u_t = x_t - y_t%0A            u = np.transpose(u_t)%0A            H = I - 2*u*u_t/(pow(np.linalg.norm(u_t%5B0%5D),2))                             %0A            A = H*A%0A            A = A*H%0A            %0A        return A%0A        %0A%0A    def qr(self, A=None):%0A        if A is None:%0A            A = self.hessenberg_matrix()%0A        N = len(A)%0A        I = np.identity((N), dtype = float)%0A        %0A        for i in range(N-1):%0A            A_t = np.transpose(A)%0A            sum_x_j = 0%0A            x_t = A_t%5Bi%5D%0A            for k in range(i, N):%0A                sum_x_j += pow(x_t%5B0,k%5D, 2)%0A            y_t = np.matrix(np.zeros(N))              %0A            for n in range(i):%0A                y_t%5B0, n%5D = x_t%5B0, n%5D%0A            y_t%5B0, i%5D = (-np.sign(x_t%5B0, i%5D))*math.sqrt(sum_x_j)%0A            u_t = x_t - y_t%0A            u = np.transpose(u_t)%0A            H = I - 2*u*u_t/(pow(np.linalg.norm(u_t%5B0%5D),2))                    %0A            A = H*A%0A            if i == 0:%0A                H_p = H%0A            else: %0A                H_p = H * H_p%0A            qr =%5B%5B%5D,%5B%5D%5D%0A            qr%5B0%5D = H_p%0A            qr%5B1%5D = A               %0A        return qr%0A                %0A    def qr_method(self, A=1, t=10):%0A        if A == 0:%0A            A = self.matrix%0A        elif A == 1:%0A            A = self.hessenberg_matrix()%0A        for i in range(t):%0A            qr = self.qr(A)%0A            Q = qr%5B0%5D%0A            R = qr%5B1%5D%0A            A = R*Q         %0A        return A%0A

Create qr.py