We initialize the data we want to interpolate:
x = 0:0.5:10;
y = sin(x/2);
This means the underlying function for the data in the interval [0,10] is sinusoidal. Now the coefficients of the approximating polynómials are being calculated:
p1 = polyfit(x,y,1);
p2 = polyfit(x,y,2);
p3 = polyfit(...