function [x, itr] = bisect(f, xl, xu, acc)
% BISECT    finds the approx. root of a given function using bisection method.
% Inputs:   f -- an anonymous function
%           xl, xu -- start and end bound of the solution
%           acc -- accuracy of the approx. solution
% Outputs:  x -- the approx. solution
%           itr -- number of iteration performed to get the solution

if (f(xl) * f(xu)) > 0
    error("Invalid lower and upper bound. Both produces result of same sign!")
end

itr = 0;
disp(["itr", "x", "y"])
while true
    itr = itr + 1;

    x = (xl + xu) / 2;
    y = f(x);
    disp([itr, x, y])

    if abs(y) < acc
        break;
    elseif (f(xl) * y) < 0
        xu = x;
    else
        xl = x;
    end
end