%testing newton and langrange methods
hold off
clear
x=[-2 0 2 4 6]';
y=[4 2 8 6 6]';
flops(0);
%calculate newton coefficients
[a,d]=newtoncoeff(x,y)
%specify xx column for which interpolation desired
xx=-2:.1:6;
xx=xx'
%interpolate
p=newtoninterp(xx,x,a)
newt=flops;
%plot the result
figure
plot(x,y,'+',xx,p,'r-')
flops(0);
%Lagrangian interpolation
%calculate coefficients
c=lagrangecoeff(x,y)
%interpolate
pl=lagrangeinterp(xx,x,c)
lang=flops;
%plot
hold on
plot(xx,pl,'g-.')
legend('data','Newton','Lagrange')
disp('Operation counts for Newton and Lagrange Interpolations are:-')
[newt,lang]
