# MultiRootFinder only returns one variable solution

I have been using GSLMultiRootFinder library to solve numerically a non-linear system of two equations. It is working well, but my problem is that the library seems to have only a function that returns one of the solutions ( const double* X() const). I need both solutions, but I do not find how can I obtain the other one. Of course, I can use the first variable and one of the equations to obtain the solution of the other one, but it is not going to provide the same value that GSLMultiRootFinder gives (the solution for the first variable of course has an error because of the tolerance when solving the system). Has anyone an idea on how can I solve this issue?

Hi,

I think the class returns via the function `const double* X() const` the solution vector which is closes to the starting point. In case of multiple roots you would need to start the iterative procedure closer to the other solution. If you don’t know the position, you would need to generate random initial points

Lorenzo

Hi,

Thank you for the reply. Are you sure that `const double* X() const` returns a vector? I was assigning the output to a double as `double x = (*solver.X())` and I did not have any errors or warnings. And if try something like `(*r.X())`, an error appears: `error: subscripted value is not an array, pointer, or vector`

Cheers,
Antonio

Hi,

That is valid C++ and `x` will take the value of the first element of the array.

Cheers,
Enrico

Hi,

Yes, it returns to a pointer to a vector…
`double x = (*solver.X())` is correct! it is equivalent to :
`double x = solver.X()`

If you want to get all elements in something like a std::vector, you can do:

`std::vector<double> vx( solver.X(), solver.X() + solver.Dim() );`

Lorenzo

1 Like

Hi,

Thank you very much for the replies. Everything clear now!

Cheers,
Antonio

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.