Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [minimum, error] = simplex(),
- clf;
- minimum = 1000;
- epsilon = 0.0001;
- n = 2;
- l = 2.0;
- x0 = [0.0; -1.0];
- x = -20:.1:20;
- y = -20:.1:20;
- % Формируем начальный симплекс.
- r1 = l * (sqrt(n + 1.0) + n - 1.0) / (n * sqrt(2.0));
- r2 = l * (sqrt(n + 1.0) - 1.0) / (n * sqrt(2.0));
- x1 = [r1; r2];
- x2 = [r2; r1];
- x_max = [0; 0];
- x_mid = [0; 0];
- x_min = [0; 0];
- iterations = 0;
- while iterations < 1000,
- iterations += 1;
- [x_min, x_mid, x_max] = sort(x0, x1, x2);
- x_cen = (x_min + x_mid) / 2.0;
- error = sqrt(0.5*((f(x_max) - f(x_min))^2.0 + (f(x_mid) - f(x_min))^2.0));
- if error < epsilon
- fprintf('\nDone...\n');
- minimum = x_min;
- x_min
- hold off;
- return;
- end
- % Отражение.
- x_new = x_cen + (x_cen - x_max);
- if f(x_new) < f(x_max),
- x0 = x_new;
- x1 = x_min;
- x2 = x_mid;
- end
- if f(x_new) >= f(x_max),
- x_max = (x_max + x_min).*0.5;
- x_mid = (x_mid + x_min).*0.5;
- x0 = x_max;
- x1 = x_min;
- x2 = x_mid;
- end
- x_min
- steps_x = 0;
- steps_y = 0;
- end
- end
Add Comment
Please, Sign In to add comment