我使用scipy.optimize.root
该hybr
方法(最好的方法?)来查找数值函数的根
我在每次迭代时打印残差
delta d 117.960112417
delta d 117.960112417
delta d 117.960112417
delta d 117.960048733
delta d 117.960112427
delta d 117.960112121
delta d 1.46141491664
delta d 0.0322651167588
delta d 0.000363688881595
delta d 4.05494689256e-08
如何通过增加步长来加速寻根,尤其是在第一次迭代之间?我不知道该算法究竟是如何工作的,但看起来很奇怪,前 3 个结果相同,而后 3 个结果也完全相同。
阅读文档,我尝试修改eps
因子,但没有成功
编辑:@sasha,这是一个非常基本的功能来说明这个问题
def f(X1,X2):
print ' X1 , diff , norm ' , X1 , X2 - X1 , np.linalg.norm(X2 - X1)
return X2 - X1
Xa = np.array([1000,1000,1000,1000])
Xb = np.array([2000,2000,2000,2000])
SOL = scipy.optimize.root(f,Xa,(Xb,))
结果将如下我们在开始时有 3 次相同的迭代,无论 X 的长度如何
X1 , diff , norm [1000 1000 1000 1000] [1000 1000 1000 1000] 2000.0
X1 , diff , norm [ 1000. 1000. 1000. 1000.] [ 1000. 1000. 1000. 1000.] 2000.0
X1 , diff , norm [ 1000. 1000. 1000. 1000.] [ 1000. 1000. 1000. 1000.] 2000.0
X1 , diff , norm [ 1000.0000149 1000. 1000. 1000. ] [ 999.9999851 1000. 1000. 1000. ] 1999.99999255
X1 , diff , norm [ 1000. 1000.0000149 1000. 1000. ] [ 1000. 999.9999851 1000. 1000. ] 1999.99999255
X1 , diff , norm [ 1000. 1000. 1000.0000149 1000. ] [ 1000. 1000. 999.9999851 1000. ] 1999.99999255
X1 , diff , norm [ 1000. 1000. 1000. 1000.0000149] [ 1000. 1000. 1000. 999.9999851] 1999.99999255
X1 , diff , norm [ 2000. 2000. 2000. 2000.] [-0. -0. -0. -0.] 4.36239133705e-09
X1 , diff , norm [ 2000. 2000. 2000. 2000.] [ 0. 0. 0. 0.] 0.0