|
- function [a, b, k, n] = min_golden_section(fun_expression, alpha, beta, epsilon, lambda)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if alpha > beta || lambda <= 0
- error ('Input criteria not met')
- end
-
-
- gamma = 0.618;
- a = alpha;
- b = beta;
- n = 0;
- fun = matlabFunction(fun_expression);
-
-
- function r = count_fun(x)
- n = n + 1;
- r = fun(x);
- end
-
-
-
- k=1;
- x_1 = a(k) + (1 - gamma)*(b(k) - a(k));
- x_2 = a(k) + gamma*(b(k) - a(k));
-
- f1 = count_fun(x_1);
- f2 = count_fun(x_2);
- while b(k) - a(k) > lambda
-
- k = k + 1;
- if f1 <= f2
- a(k) = a(k-1);
- b(k) = x_2;
- x_2 = x_1;
- f2 = f1;
- x_1 = a(k) + (1 - gamma)*(b(k) - a(k));
- f1 = count_fun(x_1);
- else
- a(k) = x_1;
- b(k) = b(k-1);
- x_1 = x_2;
- f1 = f2;
- x_2 = a(k) + gamma*(b(k) - a(k));
- f2 = count_fun(x_2);
- end
- end
-
- end
-
|