使用fsolve
,我想找到x
,在f
的情况下,f(x)=0
由
y=1.
def f(x):
return ((x-y)**2-y**2)**2
如我们所见,函数有一个x=0
的最小值,对于这个值,我们正好有f(x=0)=0
。
当我尝试用fsolve
进行求解时,它返回一个非常接近于零的值,但也会返回一个警告:
from scipy.optimize import fsolve
y=1
def f(x):
return ((x-y)**2-y**2)**2
print fsolve(f,x0=0.001,xtol=1e-6)
输出为
RuntimeWarning: The iteration is not making good progress, as measured by the
improvement from the last ten iterations.
warnings.warn(msg, RuntimeWarning)
[1.55543489e-16]
所以,结果是令人满意的,但我如何才能避免警告,为什么它返回它,考虑到它也提供了一个体面的结果?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐