THMMY's "Optimization Techniques" course assignments.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

36 rindas
659 B

  1. function [a, b, k] = min_bisection_der(fun_expression, alpha, beta, epsilon, lambda)
  2. %
  3. % Detailed explanation goes here
  4. %
  5. %
  6. % Error checking
  7. if lambda <= 0
  8. error ('Convergence criteria not met')
  9. end
  10. % Init output vectors
  11. a = alpha;
  12. b = beta;
  13. dfun = matlabFunction(diff(fun_expression));
  14. k=1;
  15. while b(k) - a(k) > lambda
  16. % bisect [a,b]
  17. x_mid = (a(k) + b(k)) / 2;
  18. % set new search interval
  19. k = k + 1;
  20. df = dfun(x_mid);
  21. if df < 0
  22. a(k) = x_mid;
  23. b(k) = b(k-1);
  24. elseif df > 0
  25. a(k) = a(k-1);
  26. b(k) = x_mid;
  27. else % df == 0
  28. a(k) = x_mid;
  29. b(k) = x_mid;
  30. break;
  31. end
  32. end