I have written aitken's method for interpolation in octave/matlab.

I would like know if it's right. Because i get this result if I call
Code:
drawint(4)
.




Here is the code, feel free to modify for correcting.

Code:
  1. function w = aitken(t,x,y)
  2. % t is a vector of x axis values of points where we want to interpolate
  3. % x and y are vectors of known points
  4. % return value w is a vector of calculated points (aitken method) on y axis
  5. n=length(y);
  6. Z=zeros(n);
  7. Z(1,:)=y;
  8. temp=zeros(1,length(t));
  9. for k=1:1:length(t)
  10. for j=1:n-1
  11. for i=j+1:n
  12. Z(j+1,i)=(Z(j,i)*(t(k)-x(j))-Z(j,j)*(t(k)-x(i)))/(x(i)-x(j));
  13. end
  14. end
  15. temp(k)=Z(n,n);
  16. end
  17. w=temp;
  18. end
  19. function drawint(m)
  20. x=0:pi/20:pi;
  21. figure; clf;
  22. plot(x,sin(x));
  23. hold on;
  24. step=(pi/m);
  25. xf=0:step:pi;
  26. yf=aitken(xf,x,sin(x))
  27. plot(xf,yf,'r');
  28. end


Thank you for your help.