function [R1] = update_QR_delete_pair(Psi,R1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Updates the R part of the QR decomposition of Psi
% after a pair has been deleted.
%
% "On efficiently computing the eigenvalues of limited-memory
% quasi-Newton matrices"
% by Jennifer Erway and Roummel Marcia
%
% Copyright (2015): Jennifer Erway and Roummel Marcia
%
% The technical report and software are available at
% www.wfu.edu/~erwayjb/publications.html
% www.wfu.edu/~erwayjb/software.html
%
%
% This code is distributed under the terms of the GNU General Public
% License
% 2.0.
%
% Permission to use, copy, modify, and distribute this software for
% any purpose without fee is hereby granted, provided that this entire
% notice is included in all copies of any software which is or includes
% a copy or modification of this software and in all copies of the
% supporting documentation for such software.
% This software is being provided "as is", without any express or
% implied warranty. In particular, the authors do not make any
% representation or warranty of any kind concerning the merchantability
% of this software or its fitness for any particular purpose.
%---------------------------------------------------------------------------
%
% Inputs: Psi=Psi(2:k) (with the first column deleted)
% R1, the leading kxk upper triangular matrix of the QR decomposition
% of Psi before the deletion
%
% Output: R1, the (k-1)x(k-1) upper triangular matrix of the QR
% decomposition of Psi after the deletion
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[m,kminus] = size(Psi);
k = kminus+1;
R1 = R1(:,2:k);
%givens rotations
for j=1:k-1
[sG, sy] = planerot(R1(j:j+1,j));
sGG = [eye(j-1) zeros(j-1,k-(j-1)); zeros(2,j-1) sG zeros(2,k-(j+1)); zeros(k-(j+1),2) zeros(k-(j+1),j-1) eye(k-(j+1))];
R1 = sGG*R1;
end
R1 = triu(R1(1:kminus,1:kminus)); %kill off rounding errors--maybe unnecessary