%
% Script file:  plotGPA.m
% A Linear Least Square Fit for (GPA_hight school, GPA_university)
%
fin=fopen('dataGPA.txt','r'); 
fgetl(fin);
m=2;  n=20;
T=fscanf(fin,'%f',[m n]);
fclose(fin);
X=T(1,:);
Y=T(2,:);
ux=mean(X);  uy=mean(Y);
sx2=var(X);  sy2=var(Y);
r=(X-ux)*(Y-uy)'/(n-1)/sqrt(sx2*sy2);
W=[ux, uy, sx2, sy2, r]
[P S]=polyfit(X,Y,1);
Yh=P(1)*X+P(2);
top=norm(Yh-uy,2);
bot=norm(Y-uy,2);
R2=(top*top)/(bot*bot); R2
plot(X,Y,'ro',X,Yh,'b-'); axis([2 4  2 4]); % grid;
legend('R^2 Statistics = 0.8479','\itY=0.8822\itX+0.0298',2)
title('University GPA vs. High School GPA')
ylabel('University GPA')
xlabel('High School GPA')