function [R1] = update_QR_delete_pair_convex(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: 
%         R1, the leading kxk upper triangular matrix of the QR decomposition
%             of Psi before the deletion
%
% Output: R1, the (k-2)x(k-2) upper triangular matrix of the QR
%         decomposition of Psi after the deletion
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[k] = size(R1,1);
R1  = R1(:,3:end);


%givens rotations
for j=1:k-2
  [sG, sy] = planerot(R1(j+1:j+2,j));
  sGG      = [eye(j) zeros(j,k-j); zeros(2,j) sG zeros(2,k-j-2); zeros(k-j-2,j+2)  eye(k-j-2)];
  R1       = sGG*R1;
  
  [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:k-2,1:k-2)); %kill off rounding errors--maybe unnecessary

