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.

44 lines
922 B

  1. %
  2. % Keeping epsilon fixed, test the iteration needed for different lambda
  3. % values.
  4. %
  5. % Clear workspace and load the functions and region
  6. clear
  7. addpath('..');
  8. GivenEnv;
  9. % * epsilon: e = 0.001
  10. % * lambda: l > 2e = 0.001
  11. % * dl: A small step away from 2e
  12. % dl = 0.0001
  13. % * lambda_max: 0.1
  14. % * N: 50 points
  15. N = 50;
  16. epsilon = 0.001;
  17. dl = 0.0001;
  18. lambda_max= 0.1;
  19. lambda = linspace(2*epsilon + dl, lambda_max, N);
  20. k = zeros(1, N); % preallocate k
  21. %
  22. % * Call the bisection method for each lambda value for each function and
  23. % keep the number of iterations needed.
  24. % * Plot the iterations k(lambda) for each function
  25. %
  26. for i = 1:length(funs)
  27. for j = 1:N
  28. [a, b, k(j)] = bisection(funs{i}, a_0, b_0, epsilon, lambda(j));
  29. end
  30. subplot(1, length(funs), i)
  31. plot(lambda, k, '-b', 'LineWidth', 1.0)
  32. title(titles(i), 'Interpreter', 'latex')
  33. xlabel('lambda')
  34. ylabel('Iterations')
  35. end