function Q = formq(W) % FUNCTION Q = formq(W) % takes the matrix W produced by house.m as input, % and generates a corresponding m x m orthogonal % matrix Q. Note, most people normally don't % construct Q explicitly because it is expensive % and redundant. % % INPUT: W -- an m x n lower triangular matrix % containing the vectors of successive % Householder reflections % OUTPUT: Q -- corresponding orthogonal matrix [m,n] = size(W); Q = eye(m); for k = 1:m for j = n:-1:1 Q(j:m,k) = Q(j:m,k) - 2*W(j:m,j)*(W(j:m,j)'*Q(j:m,k)); end end