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.

12345678910111213141516171819202122232425262728293031323334
  1. function [a, b, k] = min_bisection(fun_expression, alpha, beta, epsilon, lambda)
  2. %
  3. % Detailed explanation goes here
  4. %
  5. %
  6. % Error checking
  7. if 2*epsilon >= lambda || lambda <= 0
  8. error ('Convergence criteria not met')
  9. end
  10. % Init
  11. a = alpha;
  12. b = beta;
  13. fun = matlabFunction(fun_expression);
  14. k=1;
  15. while b(k) - a(k) > lambda
  16. % bisect [a,b]
  17. mid = (a(k) + b(k)) / 2;
  18. x_1 = mid - epsilon;
  19. x_2 = mid + epsilon;
  20. % set new search interval
  21. k = k + 1;
  22. if fun(x_1) < fun(x_2)
  23. a(k) = a(k-1);
  24. b(k) = x_2;
  25. else
  26. a(k) = x_1;
  27. b(k) = b(k-1);
  28. end
  29. end