%Data
x=[1,2,6];
y=[2,6,1];
%Total MNS
velkost=length(x);
a=sum(x)/velkost;
b=sum(y)/velkost;
M=[x-a;y-b];
A=M*transpose(M);
[v,e]=eig(A);
c=min(min(x),min(y))-1:0.01:max(max(x),max(y))+1;
d= b - v(1)*(c-a)./v(3);
hlines(3)=plot(x,y,'blue*');
hold on;
hlines(1)=plot(c,d,'black');
%MNS
M1=[velkost,sum(x);sum(x),sum(x.*x)];
f=[sum(y);sum(x.*y)];
h=linsolve(M1,f);
i=h(1)+ h(2)*c;
hlines(2)=plot(c,i,'red');
set(hlines(1),'Displayname','Total MNS')
set(hlines(2),'Displayname','MNS')
set(hlines(3),'Displayname','Data')
legend('Location','north');
hold off;