【发布时间】:2019-03-09 14:35:07
【问题描述】:
我有一个函数func(x)。我想知道x 的func(x)-7=0。因为没有确切的真实答案,我认为minimize 是个好主意。
from scipy.optimize import minimize
def func(x): # testing function which leads to the same behaviour
return (x * 5 + x * (1 - x) * (6-3*x) * 5)
def comp(x): # comparison function which should get zero
return abs(((func(x)) - 7))
x0 = 0.
x_real = minimize(comp, x0) # minimize comparison function to get x
print(x_real.x)
最后一个print 给了我[ 0.7851167]。以下print...
print(comp(x_real.x))
print(comp(0.7851167))
...导致不同的输出:
[ 1.31290960e-08]
6.151420706146382e-09
谁能解释一下这种行为?
【问题讨论】: