% Clear variables and old plots clear all; close all; % Define our interval xr=-2.8; xl=-4; % Start of the loop, note that we have decided that 1000 iterations is too % many, this is fairly arbitrary and can be changed for j=1:1000 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; else xr=xc; end % Check to see if we are close to the 0 of the function if ( abs(fc)<10^(-5) ) break end end % Display the results xc fc