Gaussian quadrature
Introduction
Numerical integration of function is pervasive in scientific computations. It is also termed as quadrature and is generally evaluated on discretized grids. The simplest example would be
where
It is exact if for any
For a fixed
If we relax the constraint of fixed nodes
Gauss-Legendre quadrature
To determine the nodes
where
For the
These two equations are the same as Eq.
where
Each term in the summation over
Therefore
On the other hand, the integral
For the second term, as
where we have used the property of Legendre polynomials:
which is the desired weight.
Gauss-Legendre quadrature is available in SciPy. The roots and weights can be obtained by calling roots_legendre in the scipy.special module. Below is an example to integrate
1
2
3
4
5
6
7
8
9
10
11
import scipy
import numpy as np
def f(x):
return 6. * x ** 8 + 4. * x ** 2 - 1.
for n in [2, 3, 4, 5, 6]:
xs, ws = scipy.special.roots_legendre(n)
integral = np.sum(ws * f(xs))
print("N = {:d}, 2N-1 = {:2d}, integral = {:.10f}"
.format(n, 2 * n - 1, integral))
N = 2, 2N-1 = 3, integral = 0.8148148148
N = 3, 2N-1 = 5, integral = 1.5306666667
N = 4, 2N-1 = 7, integral = 1.9303401361
N = 5, 2N-1 = 9, integral = 2.0000000000
N = 6, 2N-1 = 11, integral = 2.0000000000
Extension to any interval
For any function
therefore
The
Therefore for interval
It can be also extended to some open intervals. For example,
can be used for semi-infinite integral
therefore
In practice, the semi-infinite integral can be divided into separate regions, and each region is integrated using its own Gauss-Legendre grids. [1]
See also
- Gaussian quadrature - Wikipedia
- Legendre polynomials - Wikipedia
- Gauss-Legendre quadrature - Wikipedia
roots_legendre- SciPy Manual
References
[1] R. W. Godby, M. Schlüter, and L. J. Sham, Phys. Rev. B 37, 10159 (1988) [DOI].
Comments powered by Disqus.