% bisection0.m
% Bisection method
% function:             f(x)=x^2-4*sin(x)
% starting interval:    [a,b]=[1,3]
% tolerance:            tol=1e-6
% K. Ming Leung, 02/13/03

clear all; format long;
a=1; b=3;   % End points of interval
tol=eps;    % set tolerance 
fa= a*a-4*sin(a);   % function value at a
result=[]; loop=0;
while abs(b-a) > tol
    m = a+(b-a)/2;          % midpoint of interval
    fm=m*m-4*sin(m);        % function value at m
    if sign(fa)==sign(fm)
        a=m; fa=fm;
    else b=m;
    end;
    loop=loop+1;
    result=[result ;[loop a fa fm]];
end
display(result);



