%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Dichotomous Search for Minimizer of a Unimodal Function % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % A=[];C=[]; %% %% Select Parameters: endpoints & error tolerance x_l = 0 , x_r = 2 , eps= .001, eps_1 = eps/2; % %% Initialize variables a= x_l; b = x_r; N = round( log(eps_1/(b-a))/log(.5+2*eps_1)) , F = min(phi(a),phi(b)) %% %% Begin interation loop for i=1:N; mid = (a+b)/2; a1 = mid; b1 = mid + eps_1; % build array to show subinterval selections C=[ C [a a1 b1 b] ]; F1 = phi(a1); F2 = phi(b1); if F1 < F2, %% select LEFT subinterval b = b1 ; F= min(F,F1); else, %% select RIGHT subinterval a = a1 ; F=min(F,F2); end % build array of interval [a,b] and current Min of phi A=[ A [a b F] ]; end C A