function [U,T] = qrswap(U,T,j,i)
%
%  Function QRSWAP swaps the diagonal entries T(k,k) and
%  T(k+1,k+1) for k = j-1,j-2,...,i assuming j>i. 
%  It also updates the other entries of T and U accordingly. 
%  The resulting T contains at position (i,i) the value of 
%  T(j,j) of the original matrix, while the values to the left 
%  (i-1) X (i-1) upper block are unchanged.
%
%  Written by: Kjetil Havre 18/9-1996.
%
   for k=j-1:-1:i,
      x = [T(k,k+1),T(k,k)-T(k+1,k+1)];
      G([2,1],[2,1]) = planerot(x')';
      T(:,[k,k+1])   = T(:,[k,k+1])*G;
      T([k,k+1],:)   = G'*T([k,k+1],:);
      U(:,[k,k+1])   = U(:,[k,k+1])*G;
   end
end
