Without a working example, it is difficult to debug your code, but here are some suggestions based on what you have shown.
quad
returns a tuple with two values: the estimate of the integral, and an estimate of the absolute error in the result. You don't appear to be using just the first value in your code. Try changing integrand
to
def integrand(a, b):
return scipy.integrate.quad(function, a, b)[0]
Note the [0]
after the call to quad
.
Next, you should print the values of integrand(0, x)
and integrand(0, x+1)
when you find a "weird" case. If they are approximately the same, then normal numerical imprecision could destroy the order that you would theoretically expect. Take a look at the second value returned by quad
. If that value is bigger than the difference between integrand(0, x)
and integrand(0, x+1)
, you can't really expect the estimates of the integrals to increase monotonically, because the expected increase is less than the error in the calculation. If that is the problem, you could try setting epsabs
and/or epsrel
to values smaller than the default values of 1.49e-8, but that will only get you so far. Eventually you run into the limits of floating point calculations.