function [x,nit,flag]=bisezione(fun,a,b,toll)
nit=0;
flag=0;
fa=feval(fun,a);
if abs(fa) < eps, x=a; flag=2; return, end
fb=feval(fun,b);
if abs(fb) < eps, x=b; flag=2; return, end
x=(a+b)/2;
if fa*fb > 0, flag=1, return, end
while (b-a)/2 > toll
    nit=nit+1;
    fx=feval(fun,x);
    if abs(fx) < eps, flag=2; return, end
    if fa*fx < 0
       b=x; 
    else
       a=x; fa=fx;
    end
    x=(a+b)/2;
end

