THMMY's "Optimization Techniques" course assignments.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

62 lignes
1.6 KiB

  1. %
  2. % Keeping lambda (accuracy) fixed, test the iteration needed for different
  3. % epsilon values.
  4. %
  5. % Load the functions and interval
  6. GivenEnv;
  7. fig_dir = 'figures';
  8. if ~exist(fig_dir, 'dir')
  9. mkdir(fig_dir);
  10. end
  11. % Setup
  12. % ========================
  13. % lambda = 0.01
  14. % epsilon: e < lambda/2 = 0.005
  15. % de: A small step away from zero and lambda/2
  16. % de = 0.0001
  17. % N: 50 points (50 epsilon values)
  18. N = 50;
  19. lambda = 0.01;
  20. de = 0.0001;
  21. epsilon = linspace(de, (lambda/2)-de, N);
  22. k = zeros(1,N); % preallocate k
  23. %
  24. % Call the min_bisection method for each epsilon value for each
  25. % function and keep the number of iterations needed.
  26. % Then plot and save the # of iterations k(epsilon) for each function.
  27. %
  28. figure('Name', 'iterations_over_epsilon_min_bisection', 'NumberTitle', 'off');
  29. set(gcf, 'Position', [100, 100, 1280, 600]); % Set the figure size to HD
  30. for i = 1:length(funs)
  31. for j = 1:N
  32. [a, b, k(j)] = min_bisection(funs(i), a_0, b_0, epsilon(j), lambda);
  33. end
  34. fprintf('%20s(%34s ): [a, b]= [%f, %f], iterations(min, max)= (%d, %d)\n', ...
  35. "min_bisection", char(funs(i)), a(end), b(end), k(1), k(N) );
  36. subplot(1, length(funs), i)
  37. plot(epsilon, k, '-b', 'LineWidth', 1.0)
  38. title(titles(i), 'Interpreter', 'latex')
  39. xlabel('epsilon')
  40. ylabel('Iterations')
  41. end
  42. %
  43. % Print and save the figures
  44. %
  45. %fig_epsc = fullfile(fig_dir, "iter_over_epsilon_min_bisection" + ".epsc");
  46. fig_png = fullfile(fig_dir, "iter_over_epsilon_min_bisection" + ".png");
  47. %print(gcf, fig_epsc, '-depsc', '-r300');
  48. print(gcf, fig_png, '-dpng', '-r300');