clear all % clear all variables close all % close all figures x=-10:0.1:10; y=exp(x)-tan(x); plot(x,y) xr=-2.8; % initial right boundary xl=-4; % initial left boundary for j=1:1000 % j cuts the interval xc=(xl+xr)/2; % calculate the midpoint fc=exp(xc)-tan(xc); % calculate function if fc>0 xl=xc; % move left boundary else xr=xc; % move right boundary end if abs(fc)<10^(-5) break % quit the loop end end xc % print value of root fc % print value of function