THMMY's "Optimization Techniques" course assignments.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

30 linhas
1.1 KiB

  1. % Define environment (functions, gradients etc...)
  2. GivenEnv
  3. % Define parameters
  4. max_iter = 1000; % Maximum iterations
  5. tol = 1e-4; % Tolerance
  6. % Point x0 = (1, 1)
  7. % =========================================================================
  8. point = 1;
  9. x0 = [5, -5]';
  10. point_str = "[" + x0(1) + ", " + x0(2) + "]";
  11. f = fun(x0);
  12. gf = grad_fun(x0);
  13. hf = hessian_fun(x0);
  14. fprintf('Initial point (%d, %d), f = %f, grad = [%f;%f], hessian = [%f %f ; %f %f]=> Method applicable\n', x0, f, gf, hf);
  15. for g=[0.1, 0.3, 0.5, 3, 5]
  16. gamma_fixed_step = g;
  17. [x_fixed, f_fixed, kk] = method_SteepDesc(fun, grad_fun, x0, tol, max_iter, 'fixed');
  18. fprintf('Fixed step g=%f: Initial point (%f, %f), steps:%d, Final (x1,x2)=(%f, %f), f(x1,x2)=%f\n', g, x0, kk, x_fixed(:, end), f_fixed(end));
  19. if g <= 1
  20. plotPointsOverContour(x_fixed, fun, XSetLimmits(1, :), XSetLimmits(2, :), 100, point_str + ": Steepest descent $\gamma$ = " + gamma_fixed_step, "");
  21. else
  22. plotPointsOverContour(x_fixed, fun, [-500, 500], [-500, 500], 100, point_str + ": Steepest descent $\gamma$ = " + gamma_fixed_step, "");
  23. end
  24. end