THMMY's "Optimization Techniques" course assignments.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

58 lignes
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. 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;