function Q = formQ(W) % FORMQ forms the matrix Q in the QR factorization % % see also HOUSEHOLDER % % tire de: LN Trefethen & D Bau III, Numerical Linear Algebra, 1997 SIAM Philadelphia [m,n]=size(W); Q=zeros(m,m); % compute the product QI = Q, column by column for i=1:m Q(i,i)=1; for k=n:-1:1 Q(k:m,i)=Q(k:m,i)-2*W(k:m,k)*W(k:m,k)'*Q(k:m,i); end end