daily pastebin goal
43%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 57 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  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);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top