% Example 7.1
% Interpolating Polynomial

clear all
close all
clc

points = [1,1.1;2,2.1;3,5;3.4,7];
[n,cp]=size(points);
xs=ones(n);
for i=1:n
    xs(:,i) = points(:,1).^(i-1);
end
vals = points(:,2);
a = xs\vals;

xplot = linspace(0,4);
yplot = a(1) + a(2).*xplot + a(3).*xplot.^2 + a(4).*xplot.^3;

figure
hold on
plot(xplot,yplot,'LineWidth',2)
plot(points(:,1),points(:,2),'ok','MarkerSize',7,'MarkerFaceColor','k')
xlim([0,4])
ylim([0,10])
xlabel('x')
ylabel('y')
title(['y = ',num2str(a(1)),' + ',num2str(a(2)),' x ', num2str(a(3)),' x^2 + ',num2str(a(4)),' x^3'])