Advertisement
Voldemord

Untitled

May 8th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. function [ output ] = wielomianLagrangea( X , Y )
  2. %x[-2,-1,0,2]
  3. %y[0,1,1,2]
  4. %x^3/6 - x/6 + 1
  5. syms x;
  6. n = length(X);
  7. output = 0;
  8. for i = 1:n;
  9. y=1;
  10. for j = 1:n
  11. if j~=i
  12. y = y * (x-X(j))/(X(i)+X(j));
  13. end
  14. end
  15. y = y * Y(i)
  16. output = output + y;
  17. end
  18. output = simplify(output);
  19. f = @(X)eval(output)
  20. z = x(1)-1:0.1:x(n)+1;
  21. plot(z,f(z),x,y,'v');
  22.  
  23. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement