Python: Can scipy.optimize,bisection use a function f that returns multiple values?

185 views Asked by At

Suppose I have a function, f, that returns multiple values.

def f(x):
    return x + 1, 2 * x

Scipy documentation tells me that f must be a function that returns a number. I take it that my given function f isn't compatible for scipy.optimize.bisection, but is it possible to perform the bisection method on just one of the return values of f?

1

There are 1 answers

0
joni On BEST ANSWER

You can define a function that calls your function f and extracts the second return value:

from scipy.optimize import bisect

def f(x):
    return x + 1, 2 * x

bisect(lambda x: f(x)[1], -1, 1)