Systems of nonlinear equations in python

2

I have the following concern with a nonlinear equation system in python :

from scipy.optimize import fsolve as fs
def nonlinear(z):
    '''Solve a sistems  2x2 not linear
    '''
    x, y = z[0], z[1]
    f1 = (x**2)+(y**2)-2*(4.41*x+2.68*y)+25.59
    f2 = (x**2)+(y**2)-2*(3.23*x+2.1*y)+14.49
    return [f1, f2]

How can I find the multiple solutions of the previous system with the code I made?

Because if I execute the previous function with initial values, I would throw only one solution:

x, y = fs(nonlinear, [1,1])
print(x,y)
3.38998152293 2.67210655679

All the solutions that the system has are the following:

    
asked by Andres A. 30.01.2018 в 05:06
source

1 answer

2

fsolve uses a numerical optimization approach to find a solution to the given equation. In theory it is not possible (or there is no general method) with SciPy to do this, in practice it is possible to do it numerically if we know the number of solutions and playing with the initial values, which in physical variables we have many times bounded. However, given the variability of the systems, this will not always be easy or even possible.

In this case I think it's simpler to use an analytical approach with SymPy instead of a numerical one with SciPy:

from sympy import var, solve


x, y = var('x y')

f1 = (x**2)+(y**2)-2*(4.41*x+2.68*y)+25.59
f2 = (x**2)+(y**2)-2*(3.23*x+2.1*y)+14.49

sols = solve((f1, f2), (x, y))

Solutions:

>>> sols
>>> [(3.38998152293488, 2.67210655678766),
     (3.78069409020719, 1.87720857509572)]
    
answered by 30.01.2018 / 10:46
source