Introduces zeros to the column vector v below the kth element using a Householder reflection Input arguments: v, colummn vector k, index Output arguments: x, transformed vector
0001 function [ x ] = Householder( v,k ) 0002 % Introduces zeros to the column vector v below the kth element 0003 % using a Householder reflection 0004 % Input arguments: 0005 % v, colummn vector 0006 % k, index 0007 % Output arguments: 0008 % x, transformed vector 0009 0010 [n,m]=size(v); % check the size of v 0011 if m~=1; 0012 error('input is not a column vector'); 0013 elseif k>n || k<1; % check that k is a valid index of v 0014 error('input is not a valid index'); 0015 end 0016 0017 u=v; % initialize vector u to be v 0018 for i=1:k-1; % set first k-1 entries of u to zero 0019 u(i)=0; 0020 end 0021 if u(k) == 0 0022 u(k) = u(k)+norm(u); 0023 else 0024 u(k)=u(k)+sign(u(k))*norm(u); % set kth entry of u avoiding loss of 0025 % significance 0026 end 0027 if norm(u) == 0 0028 x = v; 0029 else 0030 y=u'*v; % form vector product 0031 x=v-(2/norm(u)^2)*u*y; % form x 0032 end 0033 0034 end 0035