Advertisement
ruhan008

Newton Backward

Nov 1st, 2024
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.55 KB | None | 0 0
  1. function NB = newton_backward(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.     NB = diff_table(n, 1);
  17.     s = (a - x(n)) / (x(2) - x(1));
  18.     fact = 1;
  19.     val = s;
  20.     for j = 2 : n
  21.         NB = NB + (val * diff_table(n - j + 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