scipy quad seems to provide inaccurate integral value
07:58 03 Nov 2023

I am puzzled by the fact that integrate.quad from scipy returns inaccurate results even for simple integrals. In the following, I will give a simple example for which it is easily possible to cross-check with analytical computation.

However, I would like to know a general resolution to the issue by knowing what is the best and the most reliable integral method in scipy/numpy. It is because, the actual integral I need to do is highly complicated, and an analytical solution and/or re-parametrization is not possible.

Here is a simple example:

from scipy.integrate import quad
xmax=1.0e23
xmin=0.5
def myFUN(x):
    return 1/(1+x)**(3.0)
print( quad( myFUN, xmin,xmax )[0] )

that returns:

2.3171047961935996e-40

Now, let's do it analytically:

def ana(x):
    return -0.5/(1+x)**2.0 
print( ana(xmax)-ana(xmin) )

one gets:

0.2222222222222222

Note that the numerical output differed from the analytical computation by almost 40-orders of magnitude.

Thank you in advance.

python scipy numerical-integration quad