clear
clc
%% DATA INPUT
filename = input('Enter file name, including its extension: ', 's'); D = load(filename);
%or load('Mphi.out');
%%
%Trendline
%Evaluates the polynomial c at the values in X. c is a vector of
%coefficients in descending powers.
c=polyfit(x,y,1);
yhat=polyval(c,x);
c=polyfit(x,y,2);
yhat=polyval(c,x);
c=polyfit(x,y,3);
yhat=polyval(c,x);
c=polyfit(x,y,4);
yhat=polyval(c,x);
c=polyfit(x,y,5);
yhat=polyval(c,x);
c=polyfit(x,y,6);
yhat=polyval(c,x);
c=polyfit(x,y,7);
yhat=polyval(c,x);
c=polyfit(x,y,8);
yhat=polyval(c,x);
c=polyfit(x,y,9);
yhat=polyval(c,x);
c=polyfit(x,y,10);
yhat=polyval(c,x);
c=polyfit(x,y,11);
yhat=polyval(c,x);
c=polyfit(x,y,12);
yhat=polyval(c,x);
c=polyfit(x,y,13);
yhat=polyval(c,x);
c=polyfit(x,y,14);
yhat=polyval(c,x);
c=polyfit(x,y,15);
yhat=polyval(c,x);
%Correlation coefficient
R=corrcoef(x,y);
R=R(1,2);
%Coefficient of determination
%{
mx=mean(x);
my=mean(y);
syy=sum(y.^2)-length(x)*my^2;
sse=syy-c(1)*(sum(x.*y)-length(x)*mx*my);
R2=1-sse/syy;
%}
%or
R2=R^2;
%%
%PLOT
figure(1)
plot(x,y,'o')
holdon
plot(x,yhat,'k')
title('\fontname{Arial} \bf Performance of racing motorcycles equipped with Tire-X
tires','FontSize', 12);
xlabel('Lap time [s]');
ylabel('Ambient temperature [F]');
axis([65 68 0 100])
text(65.2,90,['Coefficient of determination R^2= ' num2str(R2,3)])
text(65.2,85,['Correlation coefficient R= ' num2str(R,3)] )
legend('Data points',['Trendline y=' num2str(c(1),5) 'x' num2str(c(2),
5)],'location','best')