Advertisement
Guest User

Untitled

a guest
Mar 27th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 1.34 KB | None | 0 0
  1. function X_new = shuffle(X,P,x_max)
  2.     # X - набор точек квазиальтернанса для f(x)-P(x)
  3.     # P - коэффициенты полинома "наименее отклоняющегося" от f(x)
  4.     # x_max - максимум модуля отклонения
  5.     for i = 1 : length(X) - 1
  6.         if (x_max > X(i) && x_max < X(i+1))
  7.             if (sign(func(X(i)) - polyval(P, X(i)))==sign(func(x_max) - polyval(P, x_max)))
  8.                 X(i) = x_max;
  9.             elseif (sign(func(X(i+1)) - polyval(P, X(i+1)))==sign(func(x_max) - polyval(P, x_max)))
  10.                 X(i+1) = x_max;
  11.             endif
  12.         endif
  13.     endfor
  14.    
  15.     % Шаг 6 алгоритма
  16.     if (x_max < X(1) && (sign(func(X(1)) - polyval(P, X(1)))==sign(func(x_max) - polyval(P, x_max))))
  17.         X(1) = x_max;
  18.     elseif (x_max < X(1) && !(sign(func(X(1)) - polyval(P, X(1)))==sign(func(x_max) - polyval(P, x_max))))
  19.         X = [x_max X];
  20.         X(end) = [];
  21.     endif
  22.     % Шаг 7 алгоритма
  23.     if (x_max > X(end) && (sign(func(X(end)) - polyval(P, X(end)))==sign(func(x_max) - polyval(P, x_max))))
  24.         X(end) = x_max;
  25.     elseif (x_max > X(end) && !(sign(func(X(end)) - polyval(P, X(end)))==sign(func(x_max) - polyval(P, x_max))))
  26.         X = [X x_max];
  27.         X(1) = [];
  28.     endif
  29.     X_new = X;
  30. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement