A summary of quick and useful numerical methods to compute a definite integral of the form:

When implementing some tasks we often use unnecessary complex integration methods just because they are available in most scientific computing languages. They are usually more accurate but at the expense of speed. When computational time is important it is worth to know these faster and easy to implement integration methods.

** Trapezoidal rule of integration **

The trapezoidal rule of integration approximates the function to be integrated by a first order polynomial . If we chose and as the two points to approximate by we can solve for and , leading to

To be more accurate, we usually divide the interval into sub-intervals, such that the width of each sub-interval is . In this case, the trapezoidal rule of integration is given by

The total error on the multi-segment trapezoidal rule is given by

where is some point in the interval .

** Simpson rule of integration **

The Simpson rule of integration approximates the function to be integrated by a second order polynomial . If we chose , and as the three points to approximate by we can solve for , and , leading to

Again, if we divide the interval into equidistant sub-intervals each of length , such that , and apply the Simpson rule of integration in each sub-interval we get

The total error on the multi-segment Simpson rule is given by

where is some point in the interval .

** Gaussian quadrature rule of integration **

A quadrature rule of integration [2] approximates the integral by a weighted sum of function values at specified points within the domain of integration,

The Gaussian quadrature rule is constructed to yield an exact result for polynomials of degree or less by a suitable choice of points and weights , .

By convention the domain of integration for such a rule is taken as ,

which means that applying the Gaussian quadrature to solve an integral over takes the following form:

It can be shown that the evaluation points are just the roots of a polynomial belonging to a class of orthogonal polynomials. The approximation above will give accurate results if the function is well approximated by a polynomial of degree or less. In that case the associated polynomials are known as Legendre polynomials and the method is known as Gauss-Legendre quadrature.

Here we can find the Gauss-Legendre’s quadrature weights and Abscissae values , for different values of .

The total error of the Gauss-Legendre quadrature rule is given by

** Alternative Gaussian quadrature rules **

If the integrated function can be written as , where is approximately polynomial, and is known, then there are alternative weights such that

For example, the Gauss-Hermite quadrature rule is used when .

**References:**

[1] Integration section of the Holistic Numerical Methods website.

[2] Wikipedia page on Gaussian quadrature.

[3] Gauss-Legendre’s quadrature weights and Abscissae values for different values of n.

Fun fact: If f(.) is analytic on a region containing [a,b], then the trapezoid rule converges geometrically, i.e. the error is O(e^{-cn}) for some constant c>0.

Thanks Dan, maybe later I should aggregate some fun facts like this about numerical integration for a future post.