简体   繁体   English

Broyden1 中的中等数字

[英]Medium numbers in Broyden1

I used broyden1 in Python resolver.我在 Python 旋转变压器中使用了 broyden1。 The question was answered here , I need to use a bit larger numbers, but not newton_krylov.这个问题在这里得到了回答,我需要使用更大的数字,但不是 newton_krylov。 If I use numbers over 100, then it starts throwing errors.如果我使用超过 100 的数字,那么它就会开始抛出错误。 The code is here:代码在这里:

 import numpy as np
 import scipy.optimize
 from scipy.optimize import fsolve
 from functools import partial
 from itertools import repeat

 small_data=[100,220,350,480]
 def G(small_data, x):
    return np.cos(x) +x[::-1] - small_data

 G_partial = partial(G, small_data)
 approximate=list(repeat(1,period))
 y = scipy.optimize.broyden1(G_partial, approximate, f_tol=1e-14)
 print(y)

The error is:错误是:

 Warning (from warnings module):
 File "C:\Python\Python38\lib\site-packages\scipy\optimize\nonlin.py", line 1004
d = v / vdot(df, v)
RuntimeWarning: invalid value encountered in true_divide
Traceback (most recent call last):
File "read_data.py", line 176, in <module>
y = scipy.optimize.broyden1(G_partial, approximate, f_tol=1e-14)
File "<string>", line 6, in broyden1
File "C:\Python\Python38\lib\site- 
packages\scipy\optimize\nonlin.py", line 350, in nonlin_solve
raise NoConvergence(_array_like(x, x0))
scipy.optimize.nonlin.NoConvergence: [ 99.49247662 219.22593164 350.14354166 480.95722345]

I found that the best method is changing the equation in Boryden1 to:我发现最好的方法是将 Boryden1 中的方程式更改为:

y = scipy.optimize.broyden1(G_partial, approximate, f_tol=5000e-14)

instead of:代替:

f_tot=1e-14

so larger values will be accepted with a good accuracy所以较大的值将被接受并具有良好的准确性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM