function x = Bisection(a, b, Nmax, TOL)
f=@(x) x.*x.*x-2;
i=1;
ya = f(a);
while i <= Nmax
m=(a+b)/2;
ym=f(m);
if ym == 0 || (b-a)/2 < TOL
disp(m);
break;
end
i = i+1;
if ya*ym > 0
a = m;
ya = ym;
else
b = m;
end
end
if i==Nmax
fprintf('method failed after %d iterations\n', Nmax);
x=NaN;
else
x=m;
end