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

64 行
1.6 KiB

  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. n = 0;
  31. dfun = matlabFunction(diff(fun_expression));
  32. % wrapper call count function
  33. % In this case the derivative of the objective function
  34. function r = count_dfun(x)
  35. n = n + 1;
  36. r = dfun(x);
  37. end
  38. k=1;
  39. while b(k) - a(k) > lambda
  40. % bisect [a,b]
  41. x_mid = (a(k) + b(k)) / 2;
  42. % set new search interval
  43. k = k + 1;
  44. df = count_dfun(x_mid);
  45. if df < 0
  46. a(k) = x_mid;
  47. b(k) = b(k-1);
  48. elseif df > 0
  49. a(k) = a(k-1);
  50. b(k) = x_mid;
  51. else % df == 0
  52. a(k) = x_mid;
  53. b(k) = x_mid;
  54. break;
  55. end
  56. end
  57. end