kj <no.em...@please.post> writes: > >bisection search usually just requires the function to be continuous > >and to have its value cross the target somewhere between the endpoints, > >not be monotonic. > > Try the algorithm I posted with lo = -pi/4, hi = 2*pi, func = cos, > target = -1, and see what you get...
Sorry, my comment was poorly phrase. Bisection search usually is phrased in terms of solving f(x)=0 where f is continuous and if the initial endpoints are a and b, then f(a) and f(b) have opposite sign. > You keep missing the point that this is an *internal* *helper* > *convenience* function, ... Any internal use of this function that > applies it to a non-strictly-monotonic function is, by assumption, > an error. In that case there are better algorithms you can use. But didn't this thread start out asking what version of the code was best suited for presentation to students? In that case, the function's preconditions should be stated explicitly and not be narrower than necessary. -- http://mail.python.org/mailman/listinfo/python-list