THMMY's "Optimization Techniques" course assignments.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

fmin_bisection.m 1.2 KiB

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