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]
我的错误是什么?