function root=bisect2(a,b,epsilon)

fa=f(a); fb=f(b); c=(a+b)/2;  fc=f(c);
d=b-a;
if (fa*fb>0)
    fprintf('Error: f has the same sign in the endpoint of the given interval\n')
    return
end
if (d<=0)
    fprintf('Error: Wrong interval\n')
    return
end
n=1;  nmax=100;
%fprintf('n        c            d             f(c)\n',n,c,d,fc);
%fprintf('-------------------------------------------------\n');
%fprintf('%d     %2.8f    %2.8f   %e\n',n,c,d,fc);
while ((d>=epsilon) & (fc~=0) & (n<nmax)),
    c=(a+b)/2;
    fc=f(c);
%    fprintf('%d     %2.10f    %2.10f   %e\n',n,c,d,fc);
    if fa*fc >=0
       a=c; fa=fc;
    else
       b=c; fb=fc;
    end
    d=b-a;n=n+1;
end
if (n==nmax)
    fprintf('Error: Performed maximum number of iterations\n')
    return
end
root=c;

