Advertisement
ruhan008

Lagranges

Nov 1st, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.26 KB | None | 0 0
  1. function LG = lagranges(x, y, a)
  2.     n = length(x);
  3.     LG = 0;
  4.     for i = 1 : n
  5.         w = 1;
  6.         for j = 1 : n
  7.             if i ~= j
  8.                 w = (w * (a - x(j))) / (x(i) - x(j));
  9.             end
  10.         end
  11.         LG = LG + w * y(i);
  12.     end
  13.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement