function [ Q, R ] = h_factor ( A )
% [ Q, R ] = h_factor ( A )
% Construct Q and R factors of A, where
% Q is an orthogonal matrix
% R is an upper-triangular matrix
% A need not be a square matrix
% This function calls "householder" to construct Householder
%   matrices.

% $Id: h_factor.m,v 1.1 2013/03/13 15:24:02 mike Exp $
% M. M. Sussman

[m,n] = size(A);

Q = eye(m);
R = A;
for k=1:min(m,n)
  H = householder(R(:,k),k);
  Q = Q*H';
  R = H*R;
end
