Fundamentals / Numerical mathematics / Approximation and quadrature

Choosing where to sample

Exploit endpoint structure, test aliasing and design a stratified random estimate with a known variance.

Remove a singular factor

Evaluate \(\int_0^1 x^{-2/3}(1+x)\,dx\) using \(x=t^q\). Select \(q\), derive the transformed integrand, and decide whether one Simpson panel pair gives the exact integral.

Worked solution

To neutralise the power require \(q(1-2/3)-1=0\), giving \(q=3\). Then \(x^{-2/3}dx=t^{-2}3t^2dt=3dt\) and the finite endpoint value is 3.

Integrating \(3(1+t^3)\) gives

\[3+3/4=3.75.\]

Simpson is exact on cubics; its three samples are \(3,3.375,6\), and their weighted sum divided by six is 3.75.

Explore the related calculation with adjustable inputs. Change the parameters in the corresponding calculation and compare its independently recomputed values with the equation derived in this solution.

Expose a false agreement

For \(f(x)=\cos(12\pi x)\) on \([0,1]\), find the trapezoid results with 3 and 6 panels. Test 12 panels and explain why the initial equal answers cannot justify a zero error estimate.

Worked solution

With three panels the phase advances \(4\pi\) at each sample; with six it advances \(2\pi\). Both return the constant sample average 1.

With twelve panels samples alternate between 1 and −1. The half-weight endpoints together count as one positive value, so all contributions cancel. The exact integral is zero. Correlated aliasing on the first two grids invalidates a smooth-error extrapolation.

Explore the related calculation with adjustable inputs. Change the parameters in the corresponding calculation and compare its independently recomputed values with the equation derived in this solution.

Two strata with different variability

A response has variance 1 on the first half of \([0,1]\) and 4 on the other half. Estimate the integral from twelve independent evaluations. Compare the variances for allocations (6,6) and (4,8). Derive the continuous optimum under the same fixed budget.

Worked solution

Each stratum mean has variance \(\sigma_i^2/n_i\) and weight \(1/2\), so total variance is \((1/n_1+4/n_2)/4\). Equal allocation gives \(5/24\); (4,8) gives \(3/16\), slightly smaller.

Differentiating \(1/n_1+4/(12-n_1)\) gives \(-1/n_1^2+4/(12-n_1)^2\). Its zero requires

\[12-n_1=2n_1.\]

Positive second derivative yields the optimum (4,8), allocating in proportion to each stratum's standard deviation.

Explore the related calculation with adjustable inputs. Change the parameters in the corresponding calculation and compare its independently recomputed values with the equation derived in this solution.

Choose a quadrature variable before choosing a rule

Estimate the integral of exp(−x)/√x from 0 to 1. A composite trapezoidal rule in x fails at its first endpoint. Remove the singularity by substitution, compute Simpson estimates using two and four panels in the new variable, and derive a practical error estimate. Explain why fitting a polynomial to the original endpoint would change the question.

Worked solution

Set x = t². The Jacobian 2t cancels 1/√x for t positive, and the integrand extends smoothly to g(0) = 2. The integral is now the integral of 2 exp(−t²) over [0,1]. The endpoint value is a limit implied by the model and the substitution.

With two equal panels Simpson gives [g(0)+4g(0.5)+g(1)]/6 ≈ 1.49436. With four panels the weights are 1,4,2,4,1 times 1/12, giving about 1.49371. If the leading error is proportional to h⁴, the estimated fine-grid error magnitude is |S₄−S₂|/15 ≈ 0.000043.

The exact benchmark √π erf(1) ≈ 1.4936483 shows that the fine-grid estimate is already close; the asymptotic estimate is approximate on these coarse grids. Replacing the infinite original endpoint by a fitted finite number amounts to imposing an arbitrary sampling model. The substitution preserves the exact integral and also explains why a higher-order rule now has the smoothness it needs.

Explore the related calculation with adjustable inputs. Change the parameters in the corresponding calculation and compare its independently recomputed values with the equation derived in this solution.