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.

golden_section_interval.m 1002 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. %
  2. % Plot the [a,b] interval over the iterations for different lambda
  3. % values (min, mid, max))
  4. %
  5. % Clear workspace and load the functions and interval
  6. clear
  7. addpath('..');
  8. GivenEnv;
  9. % * lambda_min: 0.0001
  10. % * lambda_max: 0.1
  11. % * N: 3 lambda values
  12. N = 3;
  13. lambda_min = 0.0001;
  14. lambda_max = 0.1;
  15. lambda = linspace(lambda_min, lambda_max, N);
  16. k = zeros(1, N); % preallocate k
  17. %
  18. % * Call the golden_sector method for each lambda value for each function and
  19. % keep the number of iterations needed.
  20. % * Plot the [a,b] interval over iterations for each lambda for each function
  21. %
  22. for i = 1:length(funs)
  23. figure;
  24. for j = 1:N
  25. [a, b, k(j)] = golden_section(funs{i}, a_0, b_0, lambda(j));
  26. subplot(length(funs), 1, j)
  27. plot(1:length(a), a, 'ob')
  28. hold on
  29. plot(1:length(b), b, '*r')
  30. if j == 1
  31. title(titles(i), 'Interpreter', 'latex')
  32. end
  33. xlabel("Iterations @lambda=" + lambda(j))
  34. ylabel('[a_k, b_k]')
  35. end
  36. end