Advertisement
ruhan008

Newton Forward differentiation

Nov 1st, 2024
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.58 KB | None | 0 0
  1. function NFD = newton_forward_differentiation(x, y)
  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.     NFD = 0;
  16.     for i = 2 : n
  17.         odd = mod(i, 2);
  18.  
  19.         if odd == 1
  20.             NFD = NFD - diff_table(1, i) / (i - 1);
  21.         else
  22.             NFD = NFD + diff_table(1, i) / (i - 1);
  23.         end
  24.  
  25.     end
  26.  
  27.     NFD = NFD / (x(2) - x(1));
  28.    
  29.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement