THMMY's "Optimization Techniques" course assignments.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

44 lines
1.2 KiB

  1. % Define environment (functions, gradients etc...)
  2. GivenEnv
  3. % Point x0 = (0, 0)
  4. % =========================================================================
  5. point = 1;
  6. x0 = [0, 0];
  7. f = fun(x0(1), x0(2));
  8. gf = grad_fun(x0(1), x0(2));
  9. hf = hessian_fun(x0(1), x0(2));
  10. ev = eig(hf);
  11. fprintf('Initial point (%d, %d), f = %f, grad = [%f;%f], hessian = [%f %f ; %f %f]. Eigenvalues= [%f, %f], Can NOT use method\n', x0, f, gf, hf, ev);
  12. disp(' ');
  13. % Point x0 = (-1, 1)
  14. % =========================================================================
  15. point = 2;
  16. x0 = [-1, 1];
  17. point_str = "[" + x0(1) + ", " + x0(2) + "]";
  18. f = fun(-1, 1);
  19. gf = grad_fun(x0(1), x0(2));
  20. hf = hessian_fun(x0(1), x0(2));
  21. ev = eig(hf);
  22. fprintf('Initial point (%d, %d), f = %f, grad = [%f;%f], hessian = [%f %f ; %f %f]. Eigenvalues= [%f, %f], Can NOT use method\n', x0, f, gf, hf, ev);
  23. disp(' ');
  24. % Point x0 = (1, -1)
  25. % =========================================================================
  26. point = 3;
  27. x0 = [1, -1];
  28. point_str = "[" + x0(1) + ", " + x0(2) + "]";
  29. f = fun(-1, 1);
  30. gf = grad_fun(x0(1), x0(2));
  31. hf = hessian_fun(x0(1), x0(2));
  32. ev = eig(hf);
  33. fprintf('Initial point (%d, %d), f = %f, grad = [%f;%f], hessian = [%f %f ; %f %f]. Eigenvalues= [%f, %f], Can NOT use method\n', x0, f, gf, hf, ev);