Solve integral $\int_{-\infty}^{\infty} e^{-x^2}dx$

i trying to solve this integral

$$\int_{-\infty}^{\infty} e^{-x^2}dx$$

I'm using this

CODE

from scipy.integrate import quad
def integrand(x):
return exp(-x**2)

I = quad(integrand, -np.inf, np.inf, args=())
>>>I = (1.7724538509055159, 1.4202636780944923e-08)


Can i use any other numerical method to solve it?

• I must assume this is a homework problem because it is a very famous problem and you can look up the analytical solution. You don't need a numerical method to solve it. There are specific functions in every numerical library/language for directly computing this "type" of integral without using quadrature (error functions), but for this one the analytical solution can be seen by looking at the normalizing factor of the normal distribution (hopefully that's not too big of a hint for whatever you're doing. I assume you have to analytically solve it). Jan 23 '21 at 7:35

1 Answer

There is no need to use numerical methods. The integral has a simple analytical solution once you know the trick.

Hint: First solve

$$\int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty} e^{-(x^2 + y^2)} dx dy$$

by change of variables.