2

I am confused about how to use scipy.integrate.quad properly because I found this :

import numpy as np
import scipy.integrate

def f(x):
 return 1/np.sqrt(np.pi)*np.exp(-x**2)

print(scipy.integrate.quad(f,-np.inf,np.inf))

Then I got 0.99999998 and a small error. That's right. But like this :

print(scipy.integrate.quad(f,-1e4,1e4))

The answer I got is like (1.11468e-203 , 2.2157e-203) which is absolutely wrong. It should be near 1 for this function like before. I want to know why did this happen? How can I use numerical integral properly so that I can avoid this kind of errors? Many thanks!

AKX
  • 152,115
  • 15
  • 115
  • 172
yangyong
  • 51
  • 1
  • 1
  • 2
  • 1
    The docs for the function do say "Be aware that pulse shapes and other sharp features as compared to the size of the integration interval may not be integrated correctly using this method.", but I'm not sure if that's the issue here. – AKX May 13 '20 at 07:38
  • 3
    Does this answer your question [scipy.integrate.quad precision on big numbers](https://stackoverflow.com/questions/39515582/scipy-integrate-quad-precision-on-big-numbers)? – FBruzzesi May 13 '20 at 07:42

0 Answers0