How can I increase the number of subdivisions for functions in `scipy.integrate.dblquad`?

Dan picture Dan · Jan 4, 2014 · Viewed 10.8k times · Source

I'm using scipy.integrate.dblquad, and I get this error:

UserWarning: The maximum number of subdivisions (50) has been achieved.
If increasing the limit yields no improvement ...

I want to increase this limit to see if the integral is well-converged. The documentation specifies how to do this for scipy.integrate.quad (that function takes the maximum number of iterations as an argument), but not for scipy.integrate.dblquad. How can I increase the number of subdivisions for dblquad?

Answer

Dan picture Dan · Apr 2, 2014

A simpler way of doing this is to use the nquad function instead of dblquad. Example code:

from scipy.integrate import nquad

options={'limit':100}
integral=nquad(func,[[xmin,xmax],[ymin,ymax]],
          args=(other_arg,),opts=[options,options])

Note that several of the arguments are lists. The elements of these lists apply to each of the coordinates in order. See the documentation for nquad here.