x1=[3 4 2 2 4 4 5 3 6 5];
x2=[2 1 2 3 5 4 8 6 7 4];
A=[x1(:)-mean(x1) x2(:)-mean(x2)];
tt=0:0.01:(2*pi);
xx=[sin(tt);cos(tt)];
b=A'*A/(10-1)*xx; %ビジュアライズするため分散に単位円xxを入力した
figure(1)
plot(x1,x2,'x',b(1,:)+mean(x1),b(2,:)+mean(x2));axis equal;
[V,D]=eig (A'*A/(10-1));% A'*A*V=V*D  
% x1*V(1,1)+x2*V(2,1) or x1*V(1,2)+x2*V(2,2)
% V(1,1):V(2,1)=x1:x2 -> 0= x1*V(1,1)+x2*V(2,1) sum([x1;x2]'*V(:,1))が最小になるV
% V(1,2):V(2,2)=x1:x2 -> 0= x1*V(1,2)+x2*V(2,2) sum([x1;x2]'*V(:,1))が最小になるV
hold on
plot(x1,x2,'p'); axis equal
plot(V(1,1)*[0 max(D(:,1))]+mean(x1),V(2,1)*[0 max(D(:,1))]+mean(x2),'linewidth',3);
plot(V(1,2)*[0 max(D(:,2))]+mean(x1),V(2,2)*[0 max(D(:,2))]+mean(x2),'r','linewidth',3);
hold off

