-1
$\begingroup$

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
from scipy.integrate import quad
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.

$\endgroup$
1
  • 1
    $\begingroup$ Can you add the function that you want to integrate using MathJax? $\endgroup$
    – nicoguaro
    Jan 26, 2021 at 14:32

1 Answer 1

2
$\begingroup$

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;)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.