clc;clear
n=4;

% householder matrix example
x=randn(n,1); x=x/norm(x)
y=randn(n,1); y=y/norm(y)
w=x-y; u=w/norm(w)
h=eye(n)-2*u*u'

% checking the properties
format short g
h'*h
h*h'-eye(n)

h*x-y


%now take y=e_1
idn=eye(n)
x=randn(n,1)
y=norm(x)*idn(:,1)
w=x-y; u=w/norm(w);
h=idn-2*u*u';
h*x
h*x-y


% and now

n=5
idn=eye(n)
a=randn(n)
x=a(:,1)
y=norm(x)*idn(:,1)
w=x-y; u=w/norm(w);
h1=idn-2*u*u';
r=h1*a

id4=eye(4)
x=r(2:n,2)
y=norm(x)*id4(:,1)
w=x-y; u=w/norm(w);
h=id4-2*u*u'
h*r(2:n,:)

h2=[zeros(1,4);h]
h2=[idn(:,1) h2]
h2*r
