Solving equation using bisection method
Using scipy.optimize.bisect:
import scipy.optimize as optimize
import numpy as np
def func(x):
return np.cos(x)**2 + 6 - x
# 0<=cos(x)**2<=1, so the root has to be between x=6 and x=7
print(optimize.bisect(func, 6, 7))
# 6.77609231632
optimize.bisect
calls _zeros._bisect
, which is implemented in C.