0

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)
Rok Petric
  • 75
  • 3
  • 9
  • it was my understanding that the output `x` is an array giving all the roots – DrBwts Jun 28 '19 at 10:05
  • correct, x contains roots/solution, whereas I need to get values of some other parameters – Rok Petric Jun 28 '19 at 10:26
  • what other outputs are you after? The roots are the solution. – DrBwts Jun 28 '19 at 10:39
  • function f(x,a,b,c) has about 1000+ lines of code, x provides solution to the math problem whereas does not contain rest of the results at final x, which I would like to get in terms of out1,out2,... – Rok Petric Jun 28 '19 at 11:08
  • 1
    what other results? you're not being clear enough, what are `out1, out2, out3`? what other solution other than the math solution? its impossible to guess at what you mean without at least a [minimal example](https://stackoverflow.com/help/minimal-reproducible-example) of what you are trying to achieve. Are you after an evalution of your function at a given point? – DrBwts Jun 28 '19 at 11:34
  • update your question with the example. Its impossible to read properly as a comment – DrBwts Jun 28 '19 at 12:58

0 Answers0