% Clear variables clear all; xr = -2.8; % initial right boundary xl = -4; % initial left boundary for j=1:1000 % j cuts the interval xc = (xr+xl) / 2 % Find the midpoint of the interval fc = exp(xc)-tan(xc); % Calculate the function at the midpoint % Check to see if we should go left or right if ( fc > 0 ) xl = xc; % move left boundary else xr = xc; % move right boundary end % Check to see if we are close to the 0 of the function if ( abs(fc) < 10^(-5) ) break % quit the loop end end xc % print value of root fc % print value of function