5.5 Improper integrals#

The quadrature rules we have learned so far cannot be applied (or applied with a poor performance) to integrals such as \(\int_{a}^{b}f(x)dx\) if \(a,b=\pm\infty\) or if \(a,b\) are finite but \(f\) is not continuous at one or both of the endpoints: recall that both Newton-Cotes and Gauss-Legendre error bound theorems require the integrand to have a number of continuous derivatives on the closed interval \([a,b]\). For example, an integral in the form

\[\begin{equation*} \int_{-1}^{1}\frac{f(x)}{\sqrt{1-x^{2}}}dx \end{equation*}\]

clearly cannot be approximated using the trapezoidal or Simpson’s rule without any modifications, since both rules require the values of the integrand at the end points which do not exist. One could try using the Gauss-Legendre rule, but the fact that the integrand does not satisfy the smoothness conditions required by the Gauss-Legendre error bound means the error of the approximation might be large.

A simple remedy to the problem of improper integrals is to change the variable of integration and transform the integral, if possible, to one that behaves well.

Example 50

Consider the previous integral \(\int_{-1}^{1}\frac{f(x)}{\sqrt{1-x^{2}}}dx.\) Try the transformation \(\theta=\cos^{-1}x.\) Then \(d\theta=-dx/\sqrt{1-x^{2}}\) and

\[\begin{equation*} \int_{-1}^{1}\frac{f(x)}{\sqrt{1-x^{2}}}dx=-\int_{\pi}^{0}f(\cos\theta)d\theta=\int_{0}^{\pi}f(\cos\theta)d\theta. \end{equation*}\]

The latter integral can be evaluated using, for example, Simpson’s rule, provided \(f\) is smooth on \([0,\pi].\)

If the interval of integration is infinite, another approach that might work is truncation of the interval to a finite one. The success of this approach depends on whether we can estimate the resulting error.

Example 51

Consider the improper integral \(\int_0^\infty e^{-x^2}dx\). Write the integral as

\[\begin{equation*} \int_0^\infty e^{-x^2}dx=\int_0^t e^{-x^2}dx+\int_t^\infty e^{-x^2}dx, \end{equation*}\]

where \(t\) is the “level of truncation” to determine. We can estimate the first integral on the right-hand side using a quadrature rule. The second integral on the right-hand side is the error due to approximating \(\int_0^\infty e^{-x^2}dx\) by \(\int_0^t e^{-x^2}dx\). An upper bound for the error can be found easily for this example: note that when \(x\geq t\), \( x^2=xx \geq tx\), thus

\[\begin{equation*} \int_t^\infty e^{-x^2}dx \leq \int_t^\infty e^{-tx} dx =e^{-t^2}/t. \end{equation*}\]

When \(t=5\), \(e^{-t^2}/t \approx 10^{-12}\), therefore, approximating the integral \(\int_0^\infty e^{-x^2}dx\) by \(\int_0^5 e^{-x^2}dx\) will be accurate within \(10^{-12}\). Additional error will come from estimating the latter integral by numerical quadrature.

Exercise 5.5-1

The function \(\frac{e^{-x}}{x}\) does not have an antiderivative that can be expressed with elementary functions. In this problem, you will estimate the improper integral \(\int_1^\infty \frac{e^{-x}}{x} dx\) using composite Simpson’s rule such that the error is less than \(10^{-6}\). To do that, first write the improper integral as \(\int_1^a \frac{e^{-x}}{x} dx+ \int_a^\infty \frac{e^{-x}}{x} dx\). You want to approximate each integral with an error of at most \(10^{-6}/2\), so that the total error is at most \(10^{-6}\).

a. Find \(a\) such that \(\int_a^\infty \frac{e^{-x}}{x} dx < 10^{-6}/2\). (Hint: Use the limit definition of the improper integral and the fact that \(\int_a^b \frac{e^{-x}}{x}dx < \int_a^b e^{-x} dx\) where \(1<a<b.\))

b. Using the value of \(a\) obtained in the previous step, find \(n\) that ensures the composite Simpson’s rule approximates \(\int_1^a \frac{e^{-x}}{x}dx\) with an absolute error of at most \(10^{-6}/2\). (Hint: The fourth derivative of \(e^{-x}/x\) is \(e^{-x}(x^4+4x^3+12x^2+24x+24)/x^5\).)

c. Use the Python code for composite Simpson’s rule and the value for \(n\) found in the previous step to compute an approximation for \(\int_1^a \frac{e^{-x}}{x} dx\). Explain why this estimate has error less than \(10^{-6}\), summarizing your findings in steps (a) and (b).