infile='data.matrix';
bfile='B.matrix';
outfile='out.matrix';

data=load(infile);
x1=data(:,1:size(data,2)-1);
Y=data(:,size(data,2):size(data,2));
X=ones(size(x1,1),2);
X(:,2)=x1;
B=(X'*X)^(-1)*X'*Y
save('-ascii',bfile,'B');
gridX=linspace(min(x1),max(x1),100)';
gridY=linspace(B(1,1),B(1,1),100)' + gridX .* B(2,1);
out=zeros(size(gridX,1),2);
out(:,1)=gridX;
out(:,2)=gridY;
save('-ascii',outfile,'out');
