%Demo program for polynomial interpolation
clc
clear all
close all
%Data set
n = 6;
x = [0.0; 0.5; 1.0; 6.0; 7.0; 9.0];
y = [0.0; 1.6; 2.0; 2.0; 1.5; 0.0];
%call polyfit to obtain n-1 order fit:
a = polyfit(x,y,n-1)';
disp ('coefficients in decreasing order')
a
%evaluation of interpolant for plotting
xlo=min(x)-0.5;
xhi=max(x)+0.5;
x2 = linspace(xlo,xhi,120)';
f3 = polyval(a,x2);
figure
plot(x,y,'*',x2,f3)
title('Interpolant and data points using polyval')
xlabel ('X')
ylabel ('p(x) and y(x)')


