Skip to article frontmatterSkip to article content

Spectrally accurate integration

In Numerical integration we derived methods of order 2, 4, and higher for numerical integration. They all use a formula

11f(x)dxk=0nwkf(tk)\int_{-1}^1 f(x)\, dx \approx \sum_{k=0}^n w_k f(t_k)

for a collection of nodes t0,,tnt_0,\ldots,t_n in [1,1][-1,1] and weights w0,,wnw_0,\ldots,w_n. (Throughout this section we use [1,1][-1,1] as the domain of the integral; for a general interval [a,b][a,b], see Exercise 4.) The nodes and weights are independent of the integrand f(x)f(x) and determine the implementation and properties of the formula.

The process for deriving a specific method was to interpolate the integrand, then integrate the interpolant. Piecewise linear interpolation at equally spaced nodes, for instance, produces the trapezoid formula. When the integrand is approximated by a spectrally accurate global function, the integration formulas are also spectrally accurate.

9.6.1Periodic functions

For a function periodic on [1,1][-1,1], the most natural interpolant is the trigonometric polynomial (9.5.4). However, from (9.5.3) one finds that

11k=nnykτk(x)dx=k=nnyk[11τk(x)dx]=22n+1k=nnyk.\int_{-1}^1 \sum_{k=-n}^n y_k\tau_k(x)\, dx = \sum_{k=-n}^n y_k\left[ \int_{-1}^1 \tau_k(x)\, dx\right] = \frac{2}{2n+1} \sum_{k=-n}^n y_k.

In Exercise 1 you are asked to verify that this result is identical to the value of the trapezoid formula on 2n+12n+1 nodes.

9.6.2Clenshaw–Curtis integration

Suppose ff is smooth but not periodic. If we use a global polynomial interpolating ff at the Chebyshev second-kind points from (9.3.2),

tk=cos(kπn),k=0,,n,%:label: chebextremerepeat t_k = - \cos\left(\frac{k \pi}{n}\right), \qquad k=0,\ldots,n,

and integrate the resulting polynomial interpolant, the method should have spectral accuracy for a smooth integrand. The resulting algorithm is known as Clenshaw–Curtis integration.

Having specified the nodes in (9.6.1), all that remains is to find the weights. The Lagrange form of the interpolating polynomial is

p(x)=k=0nf(xk)k(x).p(x) = \sum_{k=0}^{n} f(x_k) \ell_k(x).

From this,

I=11f(x)dx11p(x)dx=11k=0nf(xk)k(x)dx=k=0nf(xk)11k(x)dx=k=0nwkf(xk),\begin{align*} I = \int_{-1}^1 f(x)\, dx \approx \int_{-1}^1 p(x) \, d x &= \int_{-1}^1 \sum_{k=0}^n f(x_k) \ell_k(x) \, d x\\ &= \sum_{k=0}^n f(x_k) \int_{-1}^1 \ell_k(x) \, d x = \sum_{k=0}^n w_k f(x_k), \end{align*}

where wk=11k(x)dx.w_k = \int_{-1}^1 \ell_k(x)\,dx. For even values of nn the result is

wk={1n21,k=0 or k=n,4nj=0n/2cos(2πjk/n)γj(14j2),k=1,,n1,γj={2,j=0 or n/2,1,j=1,2,,n/21. w_k = \begin{cases} \dfrac{1}{n^2-1}, & \text{$k=0$ or $k=n$},\\[3mm] \dfrac{4}{n} \displaystyle \sum_{j=0}^{n/2} \frac{\cos ( 2 \pi j k / n)}{\gamma_j (1-4 j^2) }, & k=1,\dots,n-1, \end{cases} \quad \gamma_j = \begin{cases} 2, & j=0 \text{ or } n/2,\\ 1, & j=1,2,\dots,n/2-1. \end{cases}

There are different formulas for odd values of nn. Note that the weights also depend on nn; e. g. w2w_2 for n=4n=4 is not the same as w2w_2 for n=10n=10. Also note that the interpolant itself never needs to be computed.

Function 9.6.1 performs Clenshaw–Curtis integration for even values of nn.[1]

9.6.3Gauss–Legendre integration

Let us reconsider the generic numerical integration formula (9.6.1),

11f(x)dxk=1nwkf(tk)=Qn[f],\int_{-1}^1 f(x)\, dx \approx \sum_{k=1}^n w_k f(t_k) = Q_{n}[f],

where Qn[f]Q_n[f] stands for the application of the formula to function ff. (We start the sum from k=1k=1 instead of k=0k=0 for notational convenience in what follows.)

The interpolation approach spurred us to use Chebyshev nodes. But it’s not clear that these are ideal nodes for the specific application of finding an integral. Instead, we can define formula as the integral of a polynomial interpolant, but with the weights and nodes chosen to satisfy an optimality criterion. As usual, we denote the set of all polynomials of degree at most mm by Pm\mathcal{P}_m.

Since there are nn nodes and nn weights available to choose, it seems plausible to expect m=2n1m=2n-1, and this intuition turns out to be correct. Hence the goal is now to find nodes tkt_k and weights wkw_k such that

11p(x)dx=Qn[p]=k=1nwkp(tk),pP2n1.\int_{-1}^1 p(x)\,dx = Q_{n}[p] = \sum_{k=1}^n w_k p(t_k), \qquad p \in \mathcal{P}_{2n-1}.

If these conditions are satisfied, the resulting method is called Gauss–Legendre integration or simply Gaussian integration. Because the integration formula is linear, i.e., Qn[αp+q]=αQn[p]+Qn[q]Q_n[\alpha p + q] = \alpha Q_n[p] + Q_n[q], it is sufficient to show that QnQ_n gets the exact value for the monomials 1,x,x2,,x2n1.1,x,x^2,\ldots,x^{2n-1}.

Generalizing the process above to general nn would be daunting, as the conditions on the nodes and weights are nonlinear. Fortunately, a more elegant approach is possible.

From Theorem 9.4.3 we know that the roots of PnP_n are distinct and all within (1,1)(-1,1). (Indeed, it would be strange to have the integral of a function depend on some of its values outside the integration interval!) While there is no explicit formula for the roots, there are fast algorithms to compute them and the integration weights on demand. Function 9.6.2 uses one of the oldest methods, practical up to n=100n=100 or so.

9.6.4Convergence

Both Clenshaw–Curtis and Gauss–Legendre integration are spectrally accurate. The Clenshaw–Curtis method on n+1n+1 points has degree nn, whereas the Gauss–Legendre method with nn points has degree 2n1{2n-1}. For this reason, it is possible for Gauss–Legendre to converge at a rate that is “twice as fast,” i.e., with roughly the square of the error of Clenshaw–Curtis. But the full story is not simple.

The difference in convergence between Clenshaw–Curtis and Gauss–Legendre is dwarfed by the difference between spectral and algebraic convergence. It is possible, though, to encounter integrands for which adaptivity is critical. Choosing a method is highly problem-dependent, but a rule of thumb is that for large error tolerances, an adaptive low-order method is likely to be a good choice, while for high accuracy, the spectral methods often dominate.

9.6.5Exercises

  1. ✍ Suppose ff is periodic on [1,1][-1,1]. Show that the result of applying the trapezoid formula on 2n+12n+1 points is identical to (9.6.2).

  2. ✍ For each integral, use Gauss–Legendre integration with n=2n=2 to write out the terms w1f(t1)w_1f(t_1) and w2f(t2)w_2f(t_2) explicitly.

    (a) 11exdx=2sinh(1)\displaystyle\int_{-1}^1 e^{-x}\, dx = 2 \sinh(1) \qquad (b) 11ex2\displaystyle\int_{-1}^1 e^{-x^2} \qquad (c) 11(2+x)1\displaystyle\int_{-1}^1 (2+x)^{-1}

  1. ⌨ For each integral, compute approximations using Function 9.6.1 and Function 9.6.2 with n=4,6,8,,40n=4,6,8,\ldots,40. Plot the errors of both methods together as functions of nn on a semi-log scale.

    (a) 11e4xdx=sinh(4)/2\displaystyle\int_{-1}^1 e^{-4x}\, dx = \sinh(4)/2

    (b) 11e9x2=πerf(3)/3\displaystyle\int_{-1}^1 e^{-9x^2} = \sqrt{\pi}\, \operatorname{erf}(3)/3

    (c) 11sech(x)dx=2tan1[sinh(1)]\displaystyle\int_{-1}^1 \operatorname{sech}(x) \, dx = 2 \tan^{-1} [ \sinh (1) ]

    (d) 1111+9x2dx=23tan1(3)\displaystyle\int_{-1}^1 \frac{1}{1+9x^2}\, dx = \frac{2}{3} \tan^{-1}(3)

  1. (a) ✍ (See also Exercise 9.3.5.) Using the change of variable

    z=ϕ(x)=a+(ba)(x+1)2,z = \phi(x) = a + (b-a)\frac{(x+1)}{2},

    show that

    abf(z)dz=ba211f(ϕ(x))dx.\int_{a}^b f(z) \, d z= \frac{b-a}{2} \int_{-1}^{1} f( \phi(x) ) \, d x .

    (b) ⌨ Rewrite Function 9.6.1 and Function 9.6.2 to accept additional inputs for aa and bb and compute integrals over [a,b][a,b].

    (c) ⌨ Repeat the steps of Exercise 2 for the integral

    π/2πx2sin8xdx=3π232.\int_{\pi/2}^{\pi} x^2 \sin 8x \, d x = -\frac{3 \pi^2}{32}.
  2. ⌨ A particle moves in a circular path with angular velocity given by ω(θ)=sin(exp(sinθ))\omega(\theta)=\sin(\exp(\sin \theta)). The time it takes to complete one full orbit is

    T=0Tdt=02πdθdθ/dt=02πdθω(θ).T = \int_0^T dt = \int_{0}^{2\pi} \frac{d\theta}{d\theta / dt } = \int_{0}^{2\pi} \frac{d\theta}{\omega(\theta) }.

    Use Function 5.6.1 to find the period of the motion. Show results for different values of nn to establish convergence to at least 12 digits.

  3. ✍ Prove the claim about linearity of the Gauss–Legendre integration formula alluded to in the derivation of Theorem 9.6.1. Namely, show that condition (9.6.10) is true if and only if

    11xjdx=k=1nwkxkj\int_{-1}^1 x^j\,dx = \sum_{k=1}^n w_k x_k^j

    for all j=0,,2n1j=0,\ldots,2n-1.

Footnotes
  1. This function is modeled after the function clencurt.m of Trefethen (2000).

References
  1. Trefethen, L. N. (2000). Spectral Methods in MATLAB. SIAM.