【发布时间】:2020-09-06 15:58:01
【问题描述】:
我试图理解为什么下面的代码不返回 -1.17 而是返回 -6.67e-09。这个数字实际上告诉我什么?
如果我将估计值从 0 更改为 -1,它确实正确计算 -1.17。但是,如果我必须为 100 多个不同的函数执行此操作,我将不得不为每个函数编写一个 while 循环,从而使计算过程变得异常缓慢。
这是简单的计算方式还是我错过了这种情况下的特定参数?
from scipy.optimize import newton
def f(x):
return x**2-3
def g(x):
return x**3
def insection():
def difference(x):
return g(x) - f(x)
insection_point_value = newton(difference, 0)
return insection_point_value
print(insection())
Returns: -6.665555511432543e-09
Has to be: -1.1745594102929802
【问题讨论】:
标签: python scipy newtons-method scipy-optimize