Performs QR algorithm to deflate matrix A, QR factorization is performed with Householder Reflections Input arguments: A, square matrix tol, tolerance Output arguments: D, deflated matrix k, number of iterations
0001 function [ D,k ] = QRalg_Householder( A,tol ) 0002 % Performs QR algorithm to deflate matrix A, 0003 % QR factorization is performed with Householder Reflections 0004 % Input arguments: 0005 % A, square matrix 0006 % tol, tolerance 0007 % Output arguments: 0008 % D, deflated matrix 0009 % k, number of iterations 0010 0011 [n,m]=size(A); % finding the size of A 0012 if n~= m; 0013 error('input is not a square matrix'); 0014 end 0015 0016 U=A; % initialize U to be A 0017 [Q,R]=QR_Householder_2(U); % this function computes the QR factorization 0018 % of U using Householder reflections 0019 U=R*Q; % compute R*Q 0020 % check whether an entry on the first subdiagonal is close to zero 0021 [m,i] = min(abs(diag(U,-1))); 0022 if m<tol % check whether the (n-i)x(i) bottom left block is 0023 % close to zero 0024 m = min(U(i+1:n,1:i)); 0025 end 0026 k=1; % initialize counter 0027 0028 while m>tol; 0029 [Q,R]=QR_Householder_2(U); % this function computes the QR factorization 0030 % of A using Householder reflections 0031 U=R*Q; % compute R*Q 0032 % check whether an entry on the first subdiagonal is close to zero 0033 [m,i] = min(abs(diag(U,-1))); 0034 if m<tol % check whether the (n-i)x(i) bottom left block is 0035 % close to zero 0036 m = min(U(i+1:n,1:i)); 0037 end 0038 k=k+1; % increment counter 0039 end 0040 D=U; % output deflated matrix 0041 end