It should perhaps go without saying but I suppose, using the interval halving method for minimizing or maximizing purposes, that you have to choose your points, a and b, well so that you for sure get the global minimum or maximum within those points?
Otherwise you'll never find the right point?