Time for action – calculating the Gaussian integral

The Gaussian integral is related to the error() function (also known in mathematics as erf), but has no finite limits. It evaluates to the square root of pi.

Time for action – calculating the Gaussian integral

Let's calculate the integral with the quad() function (for the imports check the file in the code bundle):

print("Gaussian integral", np.sqrt(np.pi),integrate.quad(lambda x: np.exp(-x**2), -np.inf, np.inf))

The return value is the outcome and its error would be as follows:

Gaussian integral 1.77245385091 (1.7724538509055159, 1.4202636780944923e-08)

What just happened?

We calculated the Gaussian integral with the quad() function.

Have a go hero ...

Get NumPy : Beginner's Guide - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.