xdata=[400 500 600 700 800]
ydata=[580 1030 1420 1880 2100]
A=[sum(xdata.^2) sum(xdata);
sum(xdata) length(xdata)];
C=[sum(xdata.*ydata);
sum(ydata)];
vec=inv(A)*C;
a=vec(1);
b=vec(2);
x=linspace(350,850);
y=a*x+b;
hold off
plot(xdata,ydata,’ko’,’MarkerSize’,20,’MarkerFaceColor’,’r’)
hold on
plot(x,y,’b-‘,’LineWidth’,2);
xlabel(‘RPM’);
ylabel(‘HP’);
figure(2)
plot(xdata,ydata,’ko’,’MarkerSize’,20,’MarkerFaceColor’,’r’)
axis([350 850 400 2400])
figure(3)
plot(x,y,’b-‘,’LineWidth’,2);
axis([350 850 400 2400])