%
% Script file: plotQ.m
% A Quadratic Least Squares Fit for Data from Heath's book
%
fin=fopen('dataQua.txt','r');
fgetL(fin);
m=2;  n=21;
T=fscanf(fin,'%f',[m n]);
fclose(fin);
T=T';
X=T(:,1);
Y=T(:,2);
[P S]=polyfit(X,Y,2);
ymu=mean(Y);
Yh=P(1)*X.^2 + P(2)*X + P(3); 
top=norm(Yh-ymu,2);
bot=norm(Y-ymu,2);
R2=(top*top)/(bot*bot);
plot(X,Y,'ro',X,Yh,'b-');
legend('R^2 Statistics = 0.9335','\itY=-0.2384\itX^2+2.6704\itX+2.1757',4);
title('Quadratic Curve Fitting')
