Guest User

Untitled

a guest
Sep 14th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. % Lagrange Interpolation
  2.  
  3. clear all;
  4. clc;
  5.  
  6. n = input('P(x) grade: ');
  7.  
  8. for i = 1 : n +1
  9. fprintf('x(%i): ', i);
  10. x(i) = input('');
  11. end
  12.  
  13. for i = 1 : n +1
  14. fprintf('y(%i): ', i);
  15. y(i) = input('');
  16. end
  17.  
  18. xo = input('Aprox. to evaluate: ');
  19. sum = 0;
  20.  
  21. for i = 1 : n + 1
  22. prod = 1;
  23.  
  24. for j = 1 : n + 1
  25. if j ~= i
  26. prod = prod * (xo - x(j))/(x(i) - x(j));
  27. end
  28. end
  29.  
  30. sum = sum + y(i)*prod;
  31. end
  32.  
  33. fprintf('R: %f \n', sum);
Add Comment
Please, Sign In to add comment