Numerical Integration

5. Numerical Integration#

Like derivatives, integrals are also common mathematical tools used in physics. While derivatives suffer from catastrofic cancellation due to the subtraction of two similar values, numerical integration is a bit more robust than numerical derivative since integration is essentiall addition. However, the huge repetition of additions incur significant round-off errors as discussed in. A good algorithm uses less addition without the expense of accuracy. First, a simple method (rectangle rule) is used to demonstrate a basic idea of numerical integration. Like forward finite difference method of numerical derivative, this method is not accurate enough for practical use. However, a simple modification (trapezoidal rule), similar to mean finite difference method of numerical derivative, improves the accuracy. More advanced methods (Simpson rule) will be introduced.

Improper integral needs special attention. For example, when integral limits involve infinity like \(\displaystyle\int_0^\infty f(x) dx\), most numerical integration methods require infinitely many addition, which cannot be done. Another example is the case where integrand has integrable singularities like \(\displaystyle\frac{1}{\sqrt{x}}\). Since we cannot evaluate the function value at \(x=0\), the common numerical methods fail. There is no systematic resolution to these problems. We need to deal with them on case-by-case basis. Several common practices will be introduced in this chapter. In addition, a magic method called Gaussian quadrature, which gives rather accurate results for certain types of integrals just by computing several points, will be discussed.