I need to evaluate several integrals, and I am using the normal(0,1) density to test out.
In python
import scipy.integrate as integrate
import scipy.stats
import numpy as np
def integrand(x):
return scipy.stats.norm(0, 1).pdf(x)
print integrate.quad(integrand, -float('inf'), 0)
print integrate.quad(integrand,-np.inf,100)
(0.4999999999999999, 5.089095674629994e-09)
(0.0, 0.0)
I was very puzzled by the fact that the computer calculated the integral correctly for the range (-inf,0), but completely missed (-inf,100) (which should be close to 1). Therefore, I tried the following in R
integrate(dnorm,-Inf,0)
0.5 with absolute error < 4.7e-05
integrate(dnorm,-Inf,100,abs.tol=0L)
0 with absolute error < 0
library(pracma)
integral(dnorm,-Inf,0)
[1] 0.5
integral(dnorm,-Inf,100,abstol=0)
[1] 0
What on earth is going on? What adaptive method should I use?