Advertisement
DMG

Newton's interpolation

DMG
Nov 17th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.44 KB | None | 0 0
  1. function p = newton_interpolation(x,y)
  2.  
  3.     cols = length(x);
  4.     p = zeros(1, cols);
  5.     D = zeros(cols, cols);
  6.     D(1,:) = y';
  7.    
  8.     for j = 2:cols
  9.         for i = 1:n-j+1
  10.             D(i, j) = (D(i+1,j-1) - D(i,j-1))/(x(i+j-1) - x(i));
  11.         end
  12.     end
  13.    
  14.     for i=1:n
  15.         pom = 1;
  16.         for j=2:i
  17.             pom = conv(pom,[1 -x(j-1)]);
  18.         end
  19.         p = p + [zeros(1,n-i) pom * D(1,i)];
  20.     end
  21.    
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement