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.

bisection_over_epsilon.m 908 B

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