function [A V] = Hessred(A)
% Reducción de A a Hessenberg con Householder
% En V vectores de transf. sucesivas de Householder
%
 [m,~] =size(A);
 if A == triu(A,-1), V = eye(m); return, end
 V = [];
 for k=1:m-2
    x = A(k+1:m,k); v = Housv(x);
    A(k+1:m,k:m)=A(k+1:m,k:m)-2*v*(v’*A(k+1:m,k:m));
    A(1:m,k+1:m)=A(1:m,k+1:m)-2*(A(1:m,k+1:m)*v)*v’;
    v = [zeros(k,1);v]; V = [V v];
 end
end

function u = Housv(x)
% Transf. Householder del x; vector en u.
%
 m = max(abs(x));u = x/m;
 if u(1) == 0, su = 1; else su = sign(u(1)); end
 u(1) = u(1)+su*norm(u);
 u = u/norm(u); u = u(:);
end