Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function t = hj(f, x0, step, e)
- d = eye(length(x0));
- t = x0;
- xb = x0;
- while step > e
- % Pretrazivanje u okolini tacke
- for i = 1:length(d)
- t_p = t + step * d(i, :);
- t_m = t - step * d(i, :);
- if (f(t_p) < f(t))
- t = t_p;
- elseif (f(t_m) < f(t))
- t = t_m;
- end
- end
- % Skok
- tb = t + (t - xb);
- if f(tb) > f(t)
- continue;
- end
- % Pretrazujemo u okolini skoka
- for i = 1:length(d)
- t_p = tb + step * d(i, :);
- t_m = tb - step * d(i, :);
- if (f(t_p) < f(xb))
- xb = t_p;
- elseif (f(t_m) < f(xb))
- xb = t_m;
- else
- step = step / 2;
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement