function y=GivensQTy(A,y);
% GIVENSQTY applies Givens rotations transposed
%   y=GivensQTyqrgiv(A,y) computes  y=Q'*y; using the Givens
%   rotations Q stored in the matrix A computed by A=GivensQR(A).
%   For y=Q*y the for loops must be processed in reverse order.

[m,n]=size(A);
for i=1:n,                           % for i=n:-1:1,   for y=Q*y
  for k=i+1:m,                       % for k=m:-1:i+1, for y=Q*y
    if A(k,i)==1,                    % reconstruct co and si from A(k,i)
      co=0; si=1;
    else 
      if abs(A(k,i))<1,
        si=A(k,i); co=sqrt(1-si*si);
      else
        co=1/A(k,i); si=sqrt(1-co*co);
      end;
    end;
    if si~=0,                        % Apply Givens reflector
      y(i:k-i:k)=[co,si;si,-co]*y(i:k-i:k);
    end
  end
end
