Bhagwan rajneesh
Bhagwan rajneesh

Reputation: 23

Two-dimensional bisection method in Python?

I am looking for an extension of the optimize.bisect function in Python, some code that allows me to solve a system of two couple self-consistent equations, i.e. y= f(x,y) and x= g(x,y). I was looking for a kind of two dimensional bisection method, but I doesn't mind to use other possibilities if it works fine.

Upvotes: 2

Views: 1714

Answers (1)

CodeZero
CodeZero

Reputation: 1689

As far as I understand your problem, you want to find the root of the following function

def fun(x):
    return [f(x[0], x[1]) - x[1],
            g(x[0], x[1]) - x[0]]

where x[0] corresponds to x in your definition and x[1] corresponds to y. You can solve this by using e.g. scipy.optimize.root

from scipy import optimize
solution = optimize.root(fun, [0, 0])

Here [0, 0] is the initial guess for the root. However, the choice of the proper algorithm highly depends on your problem.

Upvotes: 1

Related Questions