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_over_lambda.m 805 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. %
  2. % Test the iteration needed for different lambda values.
  3. %
  4. % Clear workspace and load the functions and interval
  5. clear
  6. addpath('..');
  7. GivenEnv;
  8. % * lambda_min: 0.0001
  9. % * lambda_max: 0.1
  10. % * N: 50 points
  11. N = 50;
  12. lambda_min = 0.0001;
  13. lambda_max = 0.1;
  14. lambda = linspace(lambda_min, lambda_max, N);
  15. k = zeros(1, N); % preallocate k
  16. %
  17. % * Call the golden_sector method for each lambda value for each function and
  18. % keep the number of iterations needed.
  19. % * Plot the iterations k(lambda) for each function
  20. %
  21. for i = 1:length(funs)
  22. for j = 1:N
  23. [a, b, k(j)] = golden_section(funs{i}, a_0, b_0, lambda(j));
  24. end
  25. subplot(1, length(funs), i)
  26. plot(lambda, k, '-b', 'LineWidth', 1.0)
  27. title(titles(i), 'Interpreter', 'latex')
  28. xlabel('lambda')
  29. ylabel('Iterations')
  30. end