# -*- coding: utf-8 -*- # # bisseccao.py # # # Autor: Pedro Garcia Freitas # License: Creative Commons # License: Creative Commons """ x = 0 iterCount = 0 fl = F(xl) # used in O1 imax = int(ceil(fabs(log(fabs(xr-xl)/errto)/log(2)))) # used in O2 while iterCount < imax: xold = x x = (xl+xr)/2 iterCount += 1 fx = F(x) # O1 if x != 0: errno = fabs((x - xold)/x) test = fl*fx # O1 reduce the funcion call:test = F(xl)*F(x) if test < 0: xr = x elif test > 0: xl = x else: # test == 0 is when the F(x) is the root errno = 0 return x if __name__ == "__main__": print Bissecc_O3((lambda x: x*log(x/3) - x), 1.5, 20.2, 1e-14)