如何从scipy.optimize.root获取多个输出?

时间:2019-06-28 05:56:06

标签: python optimization scipy root multipleoutputs

我有以下类型的多个输出的非线性问题:

[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)

0 个答案:

没有答案