[SciPy-User] Speedup with integrate.romberg() and vector arguments

arsbbr at gmx.net arsbbr at gmx.net
Wed Apr 27 04:50:06 EDT 2011


Hi,

I need to integrate a function with an [1xn] array argument q.
For this I used integrate.quad(), but then I have to loop through every element in q.

In http://www.astrobetter.com/interpolation-and-integration-in-python/ I found a hint how to speed up the integration.

Unfortunately I can't seem to get romberg() to work:

q is a [1 x n] numpy array, so I went from

def phi_quad(q, a, alpha, beta, r_0, r=r): # phi(q,...,r)
    y = zeros(r.size)
    for k in range(r.size):
        y[k] = integrate.quad(dy_dr, r[0], r[-1], # dy(r,...)
            args=(q[k], A, a, alpha, beta, r_0))[0]
    return y    

to 

def phi_romb_vec(q, a, alpha, beta, r_0, r=r): # phi(q,...,r)
    y = integrate.romberg(dy_dr, r[0], r[-1], # dy(r,...)
         args=(q, A, a, alpha, beta, r_0), vec_func=True)
    return y     

which raises an error, if q is an array. The other arguments are all floats. I attached a working example of the problem. Is there any way to speed up the integration?

Best regards,
Arne                                       
-- 
NEU: FreePhone - kostenlos mobil telefonieren und surfen!			
Jetzt informieren: http://www.gmx.net/de/go/freephone
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nonlin_sans.py
Type: text/x-python
Size: 2247 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110427/474639c4/attachment.py>


More information about the SciPy-User mailing list