# Integrate function with cumulative distibution function inside

I'm trying to integrate a function which is defined as func in my code below, a cumulative distribution function is inside:

from scipy.stats import norm
import math
import numpy as np

def func(v, r):
return (1 - norm.cdf(r / math.sqrt(v)))

print(quad(lambda x: func(x, 1) , 0, np.inf))


and I get this warning:

IntegrationWarning: The algorithm does not converge. Roundoff error is detected in the extrapolation table. It is assumed that the requested tolerance cannot be achieved, and that the returned result (if full_output = 1) is the best which can be obtained.

and the result is:

(1465037253.745132, 2713580385.6787577)


I think that this result is wrong, but I don't know what to change in my code. I tried to exclude point 0, but that didn't help.

I tried also to change limit to try not from 0, but from r (so in attached example from 1) (these are different results that I need to check) and there is different error:

IntegrationWarning: The integral is probably divergent, or slowly convergent.

And also I think that obtained results is wrong. Do you have any advice?

EDIT:

I'm trying to calculate this:

$$\displaystyle \int_0^\infty 1 - G(r/\sqrt v)\, dv$$

where G(x) is the cumulative distribution function.

• Can you add the function that you want to integrate using MathJax? Jan 26, 2021 at 14:32

Welcome to SE! For growing x, your function converges to 1-norm.cdf(0), which is $$1-0.5=0.5$$. Consequently, the integral is indeed divergent, just like Python told you;)