Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Lagrange Interpolation
- clear all;
- clc;
- n = input('P(x) grade: ');
- for i = 1 : n +1
- fprintf('x(%i): ', i);
- x(i) = input('');
- end
- for i = 1 : n +1
- fprintf('y(%i): ', i);
- y(i) = input('');
- end
- xo = input('Aprox. to evaluate: ');
- sum = 0;
- for i = 1 : n + 1
- prod = 1;
- for j = 1 : n + 1
- if j ~= i
- prod = prod * (xo - x(j))/(x(i) - x(j));
- end
- end
- sum = sum + y(i)*prod;
- end
- fprintf('R: %f \n', sum);
Add Comment
Please, Sign In to add comment