-1
$\begingroup$

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?

$\endgroup$
1
  • 9
    $\begingroup$ 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). $\endgroup$ – Chris Rackauckas Jan 23 at 7:35
0
$\begingroup$

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.

$\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.