Advertisement
MikecIT

powell

Nov 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.59 KB | None | 0 0
  1. function [x, fx, it] = powell(fun, x0, epsilon)
  2.     n = length(x0);
  3.     u = eye(n);
  4.     x = x0; x1 = x0 + 2 * epsilon;
  5.     it = 0;
  6.  
  7.     while max(abs(x - x1)) > epsilon
  8.         it = it + 1;
  9.         ti = x;
  10.         for i = 1:n
  11.             g = @(s) fun(ti + s * u(:, i));
  12.             teta = goldenRatio(g, -100, 100, epsilon);
  13.             ti = ti + teta * u(:, i);
  14.         end
  15.  
  16.         u = [u(:, i) ti - x];
  17.         x1 = x;
  18.         g = @(s) fun(ti + s * u(:, n));
  19.         teta = goldenRatio(g, -100, 100, epsilon);
  20.         x = ti + teta * u(:, n);
  21.     end
  22.     fx = feval(fun, x);
  23. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement