Advertisement
Voldemord

[Matlab]WzorInterpolacyjnyNewtona

May 15th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.53 KB | None | 0 0
  1. function [ W ] = WzorInterpolacyjnyNewtona( X,Y )
  2. %WzorInterpolacyjnyNewtona([-4,-3,-1,0,2,4],[2,-1,-37,-58,464,-3382])
  3. %ans: - 3*x^5 - 15*x^4 + 16*x^3 + 138*x^2 + 89*x - 58
  4. %WzorInterpolacyjnyNewtona
  5. syms x;
  6. R = LiczRzedy([-4,-3,-1,0,2,4],[2,-1,-37,-58,464,-3382]);
  7. suma = R(1,1);
  8. n = length(R);
  9.     for i = 1:n-1
  10.         V = R(1,i+1);
  11.         for j = 1:i
  12.             V = V * (x - X(j));
  13.         end
  14.     suma = suma + V;
  15.     end
  16.     W= simplify(suma);
  17.    
  18.     z=X(1)-1:0.1:X(n)+1;
  19.    
  20.     plot(z,subs(W,z),X,Y,'*');
  21. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement