Advertisement
lossyy

Scilab5_2

Mar 13th, 2021
3,152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 0.66 KB | None | 0 0
  1. X = [-8 -2 3 11];
  2. Y = [2 7 9 4];
  3. plot2d(X, Y, -1, leg="Точки");
  4.  
  5. Y5 = [];
  6. n = 3;
  7.  
  8. C = [];
  9. C(1) = Y(1);
  10. for i = 1:n
  11.     s = Y(i+1) - C(1);
  12.     for j = 1:i-1
  13.         p = 1;
  14.         for k = 0:j-1
  15.             p = p * (X(i+1) - X(k+1));
  16.         end
  17.         s = s - p;
  18.     end
  19.    
  20.     for j = 0:i-1
  21.         s = s / (X(i+1) - X(j+1));
  22.     end
  23.     C(i+1) = s;
  24. end
  25.  
  26. for x = -15:15
  27.     s = C(1);
  28.     for i = 1:n
  29.         p = C(i+1);
  30.         for j = 0:i-1
  31.             p = p * (x - X(j+1));
  32.         end
  33.         s = s + p;
  34.     end
  35.    
  36.     Y5 = [Y5, s];
  37. end
  38.  
  39. plot2d(-15:15, Y5, style=[color("magenta")], leg="Метод Ньютона");
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement