Integrating smooth periodic functions
Several posts lately have looked at the function
f(x) = cos(sin(x) +x).
This post will look at the function from a different angle. It's a smooth function with period 2. For reasons I wrote about here, this means that the trapezoid rule should find its integral very efficiently.
In general, the error in the trapezoid rule is on the order of 1/N^2 whereN is the number of integration points. To be more specific, the error in integrating a function f over [a, b] with N points is bounded by
(b - a)^3 M / 12N^2
where M is the maximum absolute value of the second derivative of f. So in our case we should expect the error to be less than 82.67/N^2. In fact we domuch better than that. The error does not decrease quadratically, as it does in general, but exponentially.

With just 16 integration points, we've reached the limit of floating point representation.
The post Integrating smooth periodic functions first appeared on John D. Cook.