我有以下类型的多个输出的非线性问题:
[F,out1,out2,out3] = f(x,a,b,c)
我正在尝试通过方法 Levenberg-Marquardt 在 Python 中解决它:
xSol = scipy.optimize.root(lambda x: f(x,a,b,c), x0, method='lm')
如果我没有指定输出,即F = f(x,a,b,c)
,该方法收敛到正确的解 x,但我无法获得其他解值,即 out1、out2、out3。
根据DOC,根函数不提供多个输出的选项,full_output=True
例如 fsolve 或 bisec (它不能很好地解决我的问题)。
这是问题的简化示例:
def root2d(x):
F = [np.exp(-np.exp(-(x[0] + x[1]))) - x[1] * (1 + x[0] ** 2)]
F.append(x[0] * np.cos(x[1]) + x[1] * np.sin(x[0]) - 0.5)
out = x[0]+x[1] # other results, which I would like to get too
return (F,out) # it yields error, but it works/converges with only "return F"
# --- run the test code with the root solver
x0 = [0,0]
x = root(root2d, x0) # how could I get also value of "out"?
print(x)