Advertisement
ruhan008

Newton Forward

Nov 1st, 2024
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.54 KB | None | 0 0
  1. function NF = newton_forward(x, y, a)
  2.     n = length(x);
  3.     diff_table = zeros(n, n);
  4.  
  5.     for i = 1 : n
  6.         diff_table(i, 1) = y(i);
  7.     end
  8.    
  9.     for j = 2 : n
  10.         for i = 1 : n - j + 1
  11.             diff_table(i, j) = diff_table(i + 1, j - 1) - diff_table(i, j - 1);
  12.         end
  13.     end
  14.    
  15.  
  16.     NF = diff_table(1, 1);
  17.     s = (a - x(1)) / (x(2) - x(1));
  18.     fact = 1;
  19.     val = s;
  20.     for j = 2 : n
  21.         NF = NF + (val * diff_table(1, j)) / fact;
  22.         val = val * (s - j - 1);
  23.         fact = fact * j;
  24.     end
  25.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement