I'm trying to integrate a complicated combination of functions using scipy.integration.quadrature, and it's throwing accuracy warnings, and the 'Latest difference' values are (gulp) nan:
'C:\Program Files\Anaconda3\lib\site-packages\scipy\integrate\quadrature.py:199: AccuracyWarning: maxiter (1000) exceeded. Latest difference = nan'
The problem seems similar to this post, but using a different integration method, and the parameters are different.
SciPy Quad Integration: Accuracy Warning
Rather than post the original set of functions, here is an example of a simpler function that also throws the warning, although the 'Latest difference' values here are actually defined numbers.
def func(phi):
return phi**3
def func2(phi):
return 1/(phi)
def int(phi):
return func(phi)/abs(2/func2(phi)**5)
res, err = integrate.quadrature(int, 0, 1, maxiter=10)
print("The numerical result is {:f} (+-{:g})"
.format(res, err))
Question: why is this behaviour (warning and values) occurring?
I note that raising the value of the maxiter
value here (eg by powers of 10) drastically changes the result, but the Latest difference values increase - suggests the integral is diverging from a result.
Interestingly, use of scipy.integration.quad
with the same inputs gives the warning 'The integral is probably divergent, or slowly convergent. warnings.warn(msg, IntegrationWarning)'. So is this just a case of a bad choice of function for the integration? Note this is not the actual function, but one that seems to give similar (but not identical) behaviour.