I have nonlinear problem with multiple outputs of the following type:
[F,out1,out2,out3] = f(x,a,b,c)
I am trying to solve it in Python by method Levenberg-Marquardt in the way:
xSol = scipy.optimize.root(lambda x: f(x,a,b,c), x0, method='lm')
If I specify no outputs, i.e. F = f(x,a,b,c)
, the method converges to correct solution x, but I cannot get my other solution values, i.e. out1, out2, out3.
According to DOC, the root function does not provide option for multiple outputs, i.e. full_output=True
like e.g. fsolve or bisec (which does not provide a good solution to my problem).
Here goes simplified example of the problem:
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)