x = [-1 2 0 3 1 -2]';
y = [ 3 2 5 4 -1.5 1]';
lambda = [-2:0.1:2];
for i = 1:length(lambda)
     dist(i) = norm(y-lambda(i)*x);
end
figure(1); plot(lambda,dist);
lambda=(x'*y)/(x'*x)

x = [-1 2 0 3 1 -2]';
y = [ 3 2 5 4 -1.5 1]';
u = ((x'*y)/(x'*x))*x

v=y-u

x'*v

x = [5 1]'; y = [1 3]';
u = ((x'*y)/(x'*x))*x; v = y-u;
v1 = [0 x(1)]; w1 = [0 x(2)];
v2 = [0 y(1)]; w2 = [0 y(2)];
v3 = [0 u(1) u(1) + v(1)]; w3 = [0 u(2) u(2) + v(2)];
plot(v1,w1,'r',v2,w2,'b',v3,w3,'g');

P = [1 0 0; 0 1 0; 0 0 0];
y = [2 -1 3]';
x = [4 5 0]';
x'*(y-P*y)

lambda=-2:0.1:6;
mu=-3:0.1:1;
[Lambda,Mu]=meshgrid(lambda,mu);
dist=sqrt((2-Lambda).^2+(1+Mu).^2+9);
figure(2); surf(lambda,mu,dist);

x = [-1 0 2]';
P = (x*x')/(x'*x)

P_perp = eye(3)-P

v1 = [-1 -1 1 1]'; v2 = [-5 -5 7 7]'; v3 = [4 -2 0 6]';
q1 = v1/norm(v1);
q2 = (v2-(v2'*q1)*q1)/norm(v2-(v2'*q1)*q1);
q3 = (v3-(v3'*q1)*q1-(v3'*q2)*q2)/norm(v3-(v3'*q1)*q1-(v3'*q2)*q2);
Q = [q1 q2 q3]

Q'*Q