THMMY's "Optimization Techniques" course assignments.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

min_bisection_der.m 1.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. function [a, b, k, n] = min_bisection_der(fun_expression, alpha, beta, epsilon, lambda)
  2. % Bisection using derivatives method for finding the local minimum of a
  3. % function.
  4. %
  5. % fun_expr: (symbolic expression over x) The symbolic expression of the
  6. % objective function
  7. % alpha: (number) The starting point of the interval in which we seek
  8. % for minimum
  9. % beta: (number) The ending point of the interval in which we seek
  10. % for minimum
  11. % epsilon: (number) The epsilon value
  12. % **note:**
  13. % epsilon in not used in this method, but it is part of the
  14. % method calling interface.
  15. % lambda: (number) The lambda value (accuracy)
  16. %
  17. % return:
  18. % a: (vector) Starting points of the interval for each iteration
  19. % b: (vector) Ending points of the interval for each iteration
  20. % k: (number) The number of iterations
  21. % n: (number) The calls of objective function fun_expr
  22. %
  23. % Error checking
  24. if alpha > beta || lambda <= 0
  25. error ('Input criteria not met')
  26. end
  27. % Init output vectors
  28. a = alpha;
  29. b = beta;
  30. dfun = matlabFunction(diff(fun_expression));
  31. k=1;
  32. while b(k) - a(k) > lambda
  33. % bisect [a,b]
  34. x_mid = (a(k) + b(k)) / 2;
  35. % set new search interval
  36. k = k + 1;
  37. df = dfun(x_mid);
  38. if df < 0
  39. a(k) = x_mid;
  40. b(k) = b(k-1);
  41. elseif df > 0
  42. a(k) = a(k-1);
  43. b(k) = x_mid;
  44. else % df == 0
  45. a(k) = x_mid;
  46. b(k) = x_mid;
  47. break;
  48. end
  49. end
  50. % Update the objctive function calls. In this case the derivative of the
  51. % function ;)
  52. n = k;