Numerical Zoo · Integration

The oscillatory integral

A lot can happen between two perfectly reasonable sample points.

Why numerical analysts keep this one around

An oscillatory integrand is a direct challenge to methods that sample too coarsely. If positive and negative lobes are missed or represented unevenly, the numerical integral can look confident while the geometry between the nodes was never really observed.

This is a useful comparison problem because Simpson, Gauss-Legendre, and Monte Carlo spend evaluations differently. None of them gets to know the function between evaluations for free.

The example also keeps the discussion honest about cost. A method can become accurate simply by throwing enough evaluations at the problem, but that is not the same as spending those evaluations well.

R setup

Start with the actual object.

f <- function(x) {
  sin(50*x) / (1 + x^2)
}

curve(f, from = 0, to = pi, n = 3000)
abline(h = 0, lty = 3)

By hand first

Do enough arithmetic to see the trap.

1

The sine term changes sign repeatedly over [0, pi]. Contributions from neighboring lobes partially cancel.

2

A coarse regular partition can land at points that do a poor job representing what happened between them.

3

A Gaussian rule moves the nodes, while Monte Carlo replaces deterministic coverage with random sampling.

What to look for

Now make it earn its reputation.

  • Use the same function and interval in Simpson and Gauss-Legendre labs.
  • Compare results at low evaluation counts before making either method generous.
  • Run Monte Carlo with several seeds. Noise becomes particularly visible when the true integral is the result of substantial cancellation.
Keep this distinction:

A function evaluation tells us what happened at one point. Numerical integration is largely the art of deciding how much we are willing to infer between those points.