1

scipy.optimize.fsolve当我得到一个10^85太大的答案时,我有 3 个带有三个未知数的大型非线性方程。也会引发运行时警告。

import scipy.optimize as opt
def func(variables):
    (A, B, C) = variables
    x1=4
    x2=10
    x3=20
    x4=5
    y1=4
    y2=15
    y3=10
    y4=10

    eq1 = ((((x2)/(A*x2+B*y2+C))-((x1)/(A*x1+B*y1+C))) *  (((x3)/(A*x3+B*y3+C))-((x2)/(A*x2+B*y2+C))) + (((y2)/(A*x2+B*y2+C))-((y1)/(A*x1+B*y1+C))) * (((y3)/(A*x3+B*y3+C))-((y2)/(A*x2+B*y2+C))) +(((1 )/(A*x2+B*y2+C))-((1 )/(A*x1+B*y1+C))) * (((1 )/(A*x3+B*y3+C))-((1 )/(A*x2+B*y2+C))))
    eq2 = ((((x3)/(A*x3+B*y3+C))-((x2)/(A*x2+B*y2+C))) * (((x4)/(A*x4+B*y4+C))-((x3)/(A*x3+B*y3+C))) + (((y3)/(A*x3+B*y3+C))-((y2)/(A*x2+B*y2+C))) * (((y4)/(A*x4+B*y4+C))-((y3)/(A*x3+B*y3+C))) +(((1 )/(A*x3+B*y3+C))-((1 )/(A*x2+B*y2+C))) * (((1 )/(A*x4+B*y4+C))-((1 )/(A*x3+B*y3+C))))
    eq3 = ((((x4)/(A*x4+B*y4+C))-((x3)/(A*x3+B*y3+C))) * (((x1)/(A*x1+B*y1+C))-((x4)/(A*x4+B*y4+C))) + (((y4)/(A*x4+B*y4+C))-((y3)/(A*x3+B*y3+C))) * (((y1)/(A*x1+B*y1+C))-((y4)/(A*x4+B*y4+C))) +(((1 )/(A*x4+B*y4+C))-((1 )/(A*x3+B*y3+C))) * (((1 )/(A*x1+B*y1+C))-((1 )/(A*x4+B*y4+C))))

    return [eq1, eq2, eq3]


solution = opt.fsolve(func, np.array([1,1,1]))
print(solution)

答案是:

RuntimeWarning:The number of calls to function has reached maxfev = 800.
      warnings.warn(msg, RuntimeWarning)
    [6.72215161e+84 5.84595081e+84 6.34963908e+85]

我的错误是什么?

4

1 回答 1

0

scipy 优化中还包括 fmin_tnc,它允许在根上放置边界:

opt.fmin_tnc(func,x0=np.array([1,1,1]),
             approx_grad=True, 
             bounds=[(None,1E5),(None,1E5),(None,1E5)])
于 2020-04-01T18:24:01.823 回答