THMMY's "Optimization Techniques" course assignments.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Script_3_SteepDesc_Proj.m 1.0 KiB

123456789101112131415161718192021222324252627
  1. % Define environment (functions, gradients etc...)
  2. GivenEnv
  3. % Settings
  4. max_iter = 1000; % Maximum iterations
  5. % Define parameters
  6. % =========================================================================
  7. x0 = [-5, 10]';
  8. gamma = 0.1;
  9. sk_step = 15;
  10. tol = 0.01; % Tolerance
  11. point_str = "[" + x0(1) + ", " + x0(2) + "]";
  12. f = fun(x0);
  13. gf = grad_fun(x0);
  14. hf = hessian_fun(x0);
  15. fprintf('Initial point (%d, %d), f = %f, grad = [%f;%f], hessian = [%f %f ; %f %f]=> Method applicable\n', x0, f, gf, hf);
  16. gamma_fixed_step = gamma;
  17. [x_fixed, f_fixed, kk] = method_SteepDesc_Proj(fun, grad_fun, x0, sk_step, XSetLimmits, 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', gamma_fixed_step, x0, kk, x_fixed(:, end), f_fixed(end));
  19. plotPointsOverContour(x_fixed, fun, XSetLimmits(1, :), XSetLimmits(2, :), 100, point_str + ": Steepest descent proj $s_k$ = " + sk_step + ", $\gamma$ = " + gamma_fixed_step, "figures/StDesProj_sk_" + sk_step + "_gamma_" + gamma + ".png");