function A = hessenberg(A)

% function B = hessenberg(A)
% similarity transformation to Hessenberg form

n = size(A,1);
for k=1:n-2;
  ind = [k+1:n];
  c = A(ind,k);
  A(ind,k:end) = h_trf(A(ind,k:end),c)
  A(:,ind) = (h_trf(A(:,ind)',c))';
end;


function B = h_trf(A,c) 

% function B = h_trf(A,c) 
% Householder transformation of A, 
% based on the vector c 

s = sign(c(1)); 
if s == 0; s = 1; end; 
r = norm(c);
d = c; d(1) = d(1) + s*r; 
r = r * abs(d(1));
B = A - (d/r) * (d'*A);
