Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [x, fx, cnt] = hookJeeves(fun, x0, d, dmin)
- n = length(x0);
- e = eye(n) * d;
- x = x0;
- fx = feval(fun, x);
- cnt = 1;
- while e(1, 1) > dmin
- t = x;
- for i = 1:n
- z = t + e(:, i);
- y = feval(fun, z);
- cnt = cnt + 1;
- if y < fx
- t = z;
- fx = y;
- else
- z = t - e(:, i);
- y = feval(fun, z);
- cnt = cnt + 1;
- if y < fx
- t = z;
- fx = y;
- end
- end
- end
- if all(t == x)
- e = e * 0.5;
- else
- x1 = t + (t - x);
- f1 = feval(fun, x1);
- cnt = cnt + 1;
- x = t;
- if f1 < fx
- for i = 1:n
- z = x1 + e(:, i);
- y = feval(fun, z);
- cnt = cnt + 1;
- if y < f1
- x = z;
- fx = y;
- break;
- end
- z = x1 - e(:, i);
- y = feval(fun, z);
- cnt = cnt + 1;
- if y < f1
- x = z;
- fx = y;
- break;
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement