function [Q,R]=RemoveColumnQR(Q,R,k);
% REMOVECOLUMNQR updating QR when a column is removed 
%   [Q,R]=RemoveColumnQR(Q,R,k); finds a QR decomposition for the
%   matrix [A(:,1),...,A(:,k-1),A(:,k+1),..A(:,n)] where
%   [Q,R]=qr(A). Uses Matlab's function PLANEROT.

[m,n]=size(R);
R=R(:,[1:k-1,k+1:n]);
for j=k:n-1,
  G=planerot(R(j:j+1,j));
  R(j:j+1,j:n-1)=G*R(j:j+1,j:n-1);
  Q(:,j:j+1)=Q(:,j:j+1)*G';
end