function demo2_1a; % the ``IDEAL'' bisection method % for solving f(x)=0 on [A,B] % eps=0.00001; A=1; B=4; % a=A; b=B; p=(a+b)/2; % % MAIN LOOP while (f(p)~=0) & (abs(b-a)>eps) if (f(a)*f(p))<0 a=a; % this line is redundant --- it does nothing, it is left for better resemblance with the algorithm in the book b=p; else a=p; b=b; % this line is again, redundant end p=(a+b)/2; end %% To display all decimals, switch default print formatting to ''long'' format long %%%%% p pi abs(pi-p) function y=f(x); y=sin(x);