function [x,tau]=house(x)
%house generates a Householder transformation
%
% [v,tau]=house(x) computes vector v and scalar tau for vector x such that
%     H=I-tau*v*v'
%   is orthogonal and H*x is a multiple of the first standard basis vector.
%   v is such that v(1)=1.

l=norm(x,2);
if l==0,%x is zero vector
    x(1)=1;
    tau=0;
    return;
end
%x is non-zero
n=length(x);
if x(1)>0,
    x(1)=x(1)+l;
else
    x(1)=x(1)-l;
end
%scale x, such that x(1)=1
x(2:n)=x(2:n)/x(1);
x(1)=1;
tau=2/(x'*x);