  function [Q,R] = QRrot(A)
%
% Pre:
%   A   m-byn with m>=n
%
% Post:
%   Q   m-by-m orthogonal
%   R   m-by-n upper triangular
%       A = QR
%

  [m,n] = size(A);
  Q = eye(m,m);
  for j=1:n
     for i=m:-1:j+1
        %Zero A(i,j)
        [c,s] = Rotate(A(i-1,j),A(i,j));
        A(i-1:i,j:n) = [c s; -s c]*A(i-1:i,j:n);
		Q(:,i-1:i) = Q(:,i-1:i)*[c s; -s c]';
     end
  end
  R = triu(A);
