## modelled after xLARFG function [x, tau, alpha] = make_house(x) ## usage: [h, tau, alpha] = make_house(x) ## ## Returns the Householder reflection that eliminates input vector x. ## So x - tau*h*h'*x == [alpha; 0; 0; ...]. ## if nargin != 1, usage ("make_house (vector)"); endif if !isvector(x), error ("make_house: expecting vector argument."); endif sg = -sign(x(1)); if (sg == 0), sg = 1; endif alpha = sg * norm(x,2); safmin = realmin(1.0)/eps; cnt = 0; if abs(alpha) < safmin, while abs(alpha) < safmin, x /= safmin; alpha /= safmin; ++cnt; endwhile alpha = sg * norm(x, 2); endif tau = (alpha - x(1)) / alpha; x(2:size(x,1)) /= (x(1) - alpha); x(1) = 1; if cnt > 0, for j=1:cnt, alpha *= safmin; endfor endif endfunction