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_interval.m 1.0 KiB

пре 2 недеља
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. %
  2. % Keeping epsilon fixed, plot the [a,b] interval over the iterations for
  3. % different lambda values (min, mid, max))
  4. %
  5. % Clear workspace and load the functions and interval
  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: 3 lambda values
  15. N = 3;
  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
  23. % * Plot the [a,b] interval over iterations for each lambda for each function
  24. %
  25. for i = 1:length(funs)
  26. figure;
  27. for j = 1:N
  28. [a, b, k(j)] = bisection(funs{i}, a_0, b_0, epsilon, lambda(j));
  29. subplot(length(funs), 1, j)
  30. plot(1:length(a), a, 'ob')
  31. hold on
  32. plot(1:length(b), b, '*r')
  33. if j == 1
  34. title(titles(i), 'Interpreter', 'latex')
  35. end
  36. xlabel("Iterations @lambda=" + lambda(j))
  37. ylabel('[a_k, b_k]')
  38. end
  39. end