使用二分法求解方程

有没有我可以在网上找到的二分法,特别是对于python? 例如,给定这些方程式,我如何使用二分法求解它们?
x^3 = 9  
3 * x^3 + x^2 = x + 5  
cos^2x + 6 = x  
    
已邀请:
使用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
调用
_zeros._bisect
,用C实现。     

要回复问题请先登录注册