%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 3.19 a,b  Elementary elimination matrix, Householder Transformation
% a

% the matrix must be non-singular
EE=[ 1 0 0; 
     0 1 0; 
     0 -4/3 1]
determinant=det(EE)

a= [ 2 3 4 ]'

EE*a


% b
I=eye(2);	% Identity matrix

% take just the 2'ed and 3'rd component of a
a1=[3; 4]
alpha= norm( a1 )
%v=[3 4]' -[-5 0]'

if (a1(1)<0) sign=-1;
else sign=+1; end

v = a1 + sign* alpha* [1 0]'
H1= I - 2 * (v*v')/(v'*v)
H1*a1

H1=I-2*v*v'/(v'*v)	% The elementary elimination matrix H1

% or 
H = [1 0 0;
     0 -.6 -.8; 
     0 -.8 .6 ]
H*a

% result vector: [ 2; 5; 0 ] with 2-norm = sqrt(29)



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 3.19 c Givens Rotation

c = a(1)/ sqrt(a(1)^2+a(3)^2)
s = a(3)/ sqrt(a(1)^2+a(3)^2)
G = [c 0 s;
     0 1 0;
     -s 0 c]
G*a
