%testing newton and Matlab methods 
hold off
clear
x=[-2 0 2 4 6]';
y=[4 2 8 6 6]';
flops(0);
n=length(x);
%calculate newton coefficients
[a,d]=newtoncoeff(x,y);
%specify xx column for which interpolation desired
xx=x(1):.1:x(n);
xx=xx'
%interpolate
p=newtoninterp(xx,x,a);
newt=flops;
%plot the result
figure
plot(x,y,'+',xx,p,'r-')
%MATLAB METHODS
%linear interpolation
y1=interp1(x,y,xx);
hold on
plot(xx,y1,'g-')
%cubic interpolation
y2=interp1(x,y,xx,'cubic');
hold on 
plot(xx,y2,'c-')
%cubic spline interpolation
y3=interp1(x,y,xx,'spline');
hold on
plot(xx,y3,'y-')
legend('data','Newton','piece-wise-linear','piece-wise-cubic','cubic-spline')
