def qr_demo ( ): ## qr_demo() suggests how the QR algorithm from scipy.linalg import qr import numpy as np # # Set up an array of 5 vectors. # A = np.array ( [ \ [ 3, 2, 6, 16, 7 ], \ [ 4, 1, 8, 18, 2 ], \ [ 5,-2, 10, 16, 9 ] ] ) # # Add one vector at a time to A. # for i in range ( 1, 6 ): Q, R = qr ( A[:,0:i] ) QR = np.matmul ( Q, R ) print ( '' ) print ( ' Compute QR factorization A = Q * R.' ) print ( '' ) print ( ' A:' ) print ( A[:,0:i] ) print ( '' ) print ( ' Q:' ) print ( Q ) print ( ' R:' ) print ( R ) print ( ' Q * R = A?:' ) print ( QR ) wait = input ( 'Pause' ) return if ( __name__ == "__main__" ): qr_demo ( )