I have a set of functions f_t
with several roots (two actually). I want to find the \"first\" root and doing this with fsolve
works fine most of th
It is generally accepted that for smooth, well-behaved functions, the Brent method is the fastest method guaranteed to give a root. As with the other two methods listed, you must provide an interval [a,b] across which the function is continuous and changes sign.
The Scipy implementation is documented here. An example use case for the function you mentioned could look like this:
from __future__ import division
import scipy
def func(x,t):
return(x**2 - 1/t)
t0 = 1
min = 0
max = 100000 # set max to some sufficiently large value
root = scipy.optimize.brentq(func, min, max, args = (t0)) # args just supplies any extra
# argument for the function that isn't the varied parameter