function Bisection

a = -1;
b = 0;
fa = f(a);
fb = f(b);
xtol = 10^(-8);
ftol = 10^(-8);
Nmax = 50;

for j=1:Nmax
   
    x = (a+b)/2;
    if b-x < xtol | abs(f(x)) < ftol
        j
        break;
    elseif fa*f(x) < 0
        b = x;
    else
        a = x;
    end
end
x

function y = f(x)
y = exp(x)-x^2;