|
123456789101112131415161718192021222324252627282930313233 |
- function [a, b, k] = bisection(fun, alpha, beta, epsilon, lambda)
- %
- % Detailed explanation goes here
- %
- %
-
- % Error checking
- if 2*epsilon >= lambda || lambda <= 0
- error ('Convergence criteria not met')
- end
-
- % Init output vectors
- a = alpha;
- b = beta;
-
- k=1;
-
- while b(k) - a(k) > lambda
- % bisect [a,b]
- mid = (a(k) + b(k)) / 2;
- x_1 = mid - epsilon;
- x_2 = mid + epsilon;
-
- % set new search interval
- k = k + 1;
- if fun(x_1) < fun(x_2)
- a(k) = a(k-1);
- b(k) = x_2;
- else
- a(k) = x_1;
- b(k) = b(k-1);
- end
- end
|