[SciPy-user] Finding lots of roots (probably with brentq)

Dan Becker dbecker@alum.dartmouth....
Mon Mar 26 20:13:35 CDT 2007


Hi,

I have a single equation whose roots I would like to find with many
sets of arguments.  I can do this by iterating over the sets of arguments, but
that doesn't feel very elegant.  I'd rather send the arrays or a matrix of
arguments to brentq once.  To be concrete, consider this code:

---
import time
from scipy.optimize import brentq
from numpy import ones

def tominimize(x,y):
    return x**2-y

t2=time.time()
for thisArg in xrange(1000):
    c=brentq(tominimize,0,100,thisArg)
print(time.time()-t2)


I wonder if this might be faster (and prettier) if I could call brentq once with
a whole set of arguments as in

brentq(tominimize,0,100,[thisArg for thisArg in xrange(1000))

I haven't figured out how to do this without getting type errors.

Thanks for any help!
Dan



More information about the SciPy-user mailing list