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 – experiment a bit more

Try out other integration functions from the same package. It should just be a matter of replacing one function call. We should get the same outcome, so you may also want to read the documentation to learn more.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset