function [a1,a0]=LinearRegression(x,y)
% Invoke it by something like [a,b]=LinearRegression(x,y)
% This creates the slope and y-axis intercept of the regression
% line of two data vectors where x is assumed to be the explanatory
% variable and y is the response variable. This line is the
% line for which the sum of the squares of the VERTICAL distances
% between data points (x(i),y(i)) and the line is minimized.
nx=length(x);
ny=length(y);
if nx ~= ny
disp('Error: Data vectors must be the same length.')
a1='error';
a0='error';
else
sx=sum(x);
sy=sum(y);
sxy=sum(x.*y);
sxx=sum(x.^2);
a1=(nx*sxy-sx*sy)/(nx*sxx-sx^2);
a0=(sxx*sy-sxy*sx)/(nx*sxx-sx^2);
end