Search code examples
python-2.7scipynumerical-integration

SciPy Quad Integration: Accuracy Warning


I am currently trying to compute out an integral with scipy.integrate.quad, and for certain values I get the following error:

/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/scipy/integrate/quadrature.py:616: AccuracyWarning: divmax (20) exceeded. Latest difference = 2.005732e-02 AccuracyWarning)

Looking at the documentation, it isn't entirely clear to me why this warning is raised, what it means, and why it only occurs for certain values.


Solution

  • in scipy.integrate.quad there's a lower-level call to a difference function that is iterated over, and it's iterated over divmax times. In your case, the default for divmax=20. There are some functions that you can override this default -- for example scipy.integrate.quadrature.romberg allows you to set divmax (default here is 10) as a keyword. The warning is thrown when the tolerances aren't met for the difference function. Setting divmax to a higher value will run longer, and hopefully meet the tolerance requirements.