function [H,V]=Hessenberg1(A)
% HESSENBERG1 similarity transformation to Hessenberg form
%   [H,V]=Hessenberg1(A) transforms the given matrix A into
%   Hessenberg form H using the orthogonal transformations V,
%   such that H=V'*A*V

n=length(A); V=eye(n); 
for p=2:n-1 
  for q=p+1:n 
    [c,s]=GivensRotation(A(p,p-1), A(q,p-1));  % rotate A(q,p-1)=0
    if s~=0                        
      h=A(p,:)*c-A(q,:)*s;                     % A=U^T*A
      A(q,:)=A(p,:)*s+A(q,:)*c;
      A(p,:)=h;
      h =A(:,p)*c-A(:,q)*s;                    % A=A*U
      A(:,q)= A(:,p)*s+A(:,q)*c;
      A(:,p)=h;
      h=V(:,p)*c-V(:,q)*s;                     % V=V*U
      V(:,q)=V(:,p)*s+V(:,q)*c;
      V(:,p)=h;
    end
  end
end
H=A;