THMMY's "Optimization Techniques" course assignments.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

  1. function [a, b, k, n] = min_bisection(fun_expr, alpha, beta, epsilon, lambda)
  2. % Bisection method for finding the local minimum of a function.
  3. %
  4. % fun_expr: (symbolic expression over x) The symbolic expression of the
  5. % objective function
  6. % alpha: (number) The starting point of the interval in which we seek
  7. % for minimum
  8. % beta: (number) The ending point of the interval in which we seek
  9. % for minimum
  10. % epsilon: (number) The epsilon value (distance from midpoint)
  11. % lambda: (number) The lambda value (accuracy)
  12. %
  13. % return:
  14. % a: (vector) Starting points of the interval for each iteration
  15. % b: (vector) Ending points of the interval for each iteration
  16. % k: (number) The number of iterations
  17. % n: (number) The calls of objective function fun_expr
  18. %
  19. % Error checking
  20. if alpha > beta || 2*epsilon >= lambda || lambda <= 0
  21. error ('Input criteria not met')
  22. end
  23. % Init
  24. a = alpha;
  25. b = beta;
  26. fun = matlabFunction(fun_expr);
  27. k=1;
  28. while b(k) - a(k) > lambda
  29. % bisect [a,b]
  30. mid = (a(k) + b(k)) / 2;
  31. x_1 = mid - epsilon;
  32. x_2 = mid + epsilon;
  33. % set new search interval
  34. k = k + 1;
  35. if fun(x_1) < fun(x_2)
  36. a(k) = a(k-1);
  37. b(k) = x_2;
  38. else
  39. a(k) = x_1;
  40. b(k) = b(k-1);
  41. end
  42. end
  43. % Set objective function calls
  44. n = 2*k;