T=xlsread('\\bearsrv\Classrooms\Math\blumj\MAT 335\ex 2.xls');
%comment: xlsread reads the designated Excel file
%split into x and y vectors...
y=T(:,2);
%y is second column (T(:,2) is all rows, 2nd col of T)
x=T(:,1);
%semicolons suppress output
n=length(y)
%length(v) number of entries
X=[ones(n,1) x x.^2 x.^3 x.^4];
%ones is a fill matrix/vector of ones
% .op for any operator is element-wise
bhat=inv(X'*X)*X'*y
%bhat will contain my estimates of intercept and slope

%plot(a,b,'options')  plots two vectors, a is on horizontal, b vertical
clf
%clf clears figure(s)
hold on
%hold allows for multiple plots in same figure
plot(x,y,'r*')
%plots original data as red stars
yhat=X*bhat;
plot(x,yhat,'b-')

e=y-yhat;
%error for linear fit

ybar=(1/n)*ones(n,n)*y;
t=y-ybar;
%total error

rsq=1-e'*e/(t'*t)
