Advertisement
ruhan008

newton divided difference

Nov 1st, 2024
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.50 KB | None | 0 0
  1. function NDD = newton_divided_difference(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)) / (x(i + j - 1) - x(i));
  12.         end
  13.     end
  14.  
  15.     NDD = diff_table(1, 1);
  16.     val = (a - x(1));
  17.  
  18.     for j = 2 : n
  19.         NDD = NDD + (val * diff_table(1, j));
  20.         val = val * (a - x(2));
  21.     end
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement