clc
clear all
clf
% INPUTS
xd    =[325 265 185 105 25 -55 -70];
yd    =[2.6 3.8 4.8 5.0 5.72 6.4 7.0];
points=[xd;yd]';
xval  =[55 20 -10];
disp('INPUTS')
disp('  Data points:')
disp('      x          y')
disp(points)
disp('  Predict y @ these x values:')
disp(xval)
% CODE
or    =1;                  % linear regression
ce    =polyfit(xd,yd,or);  % fitting the data to a line
ypre  =polyval(ce,xval);  
xp    =[min(xd):0.1:max(xd)];
yp    =polyval(ce,xp);
% plotting
figure(1)
hold on
plot(xd,yd,'ro','MarkerSize',8)
plot(xp,yp,'g-','LineWidth',1)
plot(xval,ypre,'bs','MarkerSize',7)
title('Regression Model for Data Points')
legend('Given Points','Regression Model','Predicted Point',0)
xlabel('x')
ylabel('y')
hold off
% display information
syms x
eqn=ce(1)*x+ce(2);
eqn1=vpa(eqn,6);   % convert the exact model to a decimal
eqn1=char(eqn1);   % convert the symbolic expression to a string
disp('OUTPUTS')
disp(' See figure(3)')
fprintf(' Regression model:\n %s\n\n',eqn1)
disp('  The predicted y values are:')
disp(ypre)