hpwr=autos(:,4);
mpg=autos(:,1);
disp=autos(:,3);
wt=autos(:,5);
row=391;

% 1/mpg=alpha*hpwr+beta
A1=[hpwr ones(row,1)];
b=1./mpg;
xLS1=A1\b;
sum1=0;
alpha1=xLS1(1)
beta1=xLS1(2)
for i=1:row,
  sum1=sum1+((A1(i,1)*alpha1+beta1)-b(i))^2;
end
error1=sqrt(sum1)

% 1/mpg=alpha*hpwr+beta*disp+gamma*wt+delta
A2=[hpwr disp wt ones(391,1)];
b=1./mpg;
xLS2=A2\b;
sum2=0;
alpha2=xLS2(1)
beta2=xLS2(2)
gamma2=xLS2(3)
delta2=xLS2(4)
for i=1:row,
  sum2=sum2+((A2(i,1)*alpha2+A2(i,2)*beta2+A2(i,3)*gamma2+delta2)-b(i))^2;
end
error2=sqrt(sum2)

% extra credit
% 1/mpg=alpha*hpwr+beta*disp+gamma*wt+accel*delta+theta
accel=autos(:,6);
A3=[hpwr disp wt accel ones(391,1)];
b=1./mpg;
xLS3=A3\b;
sum3=0;
alpha3=xLS3(1)
beta3=xLS3(2)
gamma3=xLS3(3)
delta3=xLS3(4)
theta3=xLS3(5)
for i=1:row,
  sum3=sum3+((A3(i,1)*alpha3+A3(i,2)*beta3+A3(i,3)*gamma3+A3(i,4)*delta3+theta3)-b(i))^2;
end
error3=sqrt(sum3)
