%MATLAB implementation of the Householder QR Factorization.
%W is a lower-triangular matrix (mxn) whose columns are vectors v_k defining
%the successive Householder reflections, that is W(:,1) is the first orthogonal
%matrix that applies to A to knock down all the elements below a_11.
%R is an upper triangular matrix (nxn).

function [V,R] = house(A);

[m,n] = size(A);

V = zeros(m,n);
R = A;

for k=1:n
	x = R(k:m,k);
	V(k:m,k) = sign(x(1))*norm(x)*eye(m-k+1,1) + x;
	vlth = norm(V(k:m,k));
	V(k:m,k) = V(k:m,k)/vlth;
	R(k:m,k:n) = R(k:m,k:n) - 2*V(k:m,k)*(V(k:m,k)'*R(k:m,k:n));
end
