How to do it...

  1. It is possible to perform multivariate numerical integration on different domains via the application of adaptive Gaussian quadrature rules
  2. In the scipy.integrate module, we have to this effect the routines dblquad (double integrals), tplquad (triple integrals), and nquad (integration over multiple variables)

These routines can only compute definite integrals over type I regions:

  • In two dimensions, a type I domain can be written in the form {(x,y) : a<x<b, f(x)<y<h(x)} for two numbers a and band two univariate functions f(x) and h(x).
  • In three dimensions, a type I region can be written in the form {(x,y,z) : a<x<b, f(x)<y<h(x), q(x,y)<z<r(x,y)} for numbers a and b, univariate functions f(x) and h(x), and bivariate functions q(x,y) and r(x,y).
  • In more than three dimensions, type I regions can be written sequentially in a similar manner as their double and triple counterparts. The first variable is bound by two numbers. The second variable is bounded by two univariate functions of the first variable. The third variable is bounded by two bivariate functions of the two first variables, and so on.

Let's run a numerical integration over the function of the example inline  reference to the following example. Note the order in which the different variables must be introduced in the definition of the function to be integrated:

In [76]: def f(x, y): return np.exp(-x**2 - y**2)
In [77]: from scipy.integrate import dblquad
In [78]: dblquad(f, 0, np.inf, lambda x:0, lambda x:np.inf)
Out[78]: (0.785398163397, 6.29467149642e-09)
..................Content has been hidden....................

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