Function for which trapezoidal rule outperforms midpoint rule for every $n$

Is there a continuous elementary function $f:[0,1]\to [0,\infty)$ such that for every $n$ the trapezoidal approximation to $\int_{0}^{1}f(x)\,dx$ with $n$ trapezoids is strictly better than the midpoint approximation with $n$ rectangles?

The point of this questions is that even though the midpoint approximation to an integral is generally better than the trapezoidal approximation, there is, for each $n$, a continuous function $f:[0,1]\to \mathbb{R}$ such that the trapezoidal approximation to $\int_{0}^{1}f(x)\,dx$ with $n$ trapezoids is better than the midpoint approximation with $n$ rectangles. See here for an example.

I added the restriction that $f$ be elementary so I can talk about the answer with my calculus students. I added the restriction that $f$ be non-negative for simplicity.

• I can't help with your question, but I find it curious in your link the author claimed there was no antiderivitive of $\frac 1 x$. Strange.
– Alan
Commented Oct 6, 2014 at 15:37
• What does the author mean when writing that "we have never come across a function whose derivative is $\frac1x$"? Commented Oct 6, 2014 at 15:38
• @Alan Actually he only claimed that they'd "never come across a function whose derivative is $\frac{1}{x}$". I suppose this means they've not defined the natural log yet. Commented Oct 6, 2014 at 15:39
• Hmm, so is it calculus limited to polynomials? Sounds like the precalculus was badly neglected in that class ;)
– MPW
Commented Oct 6, 2014 at 15:41
• Here's one where at least midpoint isn't always better. In fact the choice of lowest error method fluctuates in an oscillatory way with n: f(x)=$\sqrt{|\tan(\pi x)|}$.
– SDiv
Commented Oct 9, 2014 at 14:58

Consider a function of the form $$f(x) = \sum_{j=1}^\infty c_j \cos(2 \pi j x)$$ Then the errors $ME(n)$ and $TE(n)$ in midpoint and trapezoid rules are \eqalign{TE(n) &= \sum_{k=1}^\infty c_{kn} \cr ME(n) &= 2 TE(2n) - TE(n) = \sum_{k=1}^\infty (-1)^{k} c_{kn} \cr} For example, let $c_j = (-1)^{d(j)} 2^{-j}$ where $d(j)$ is the $2$-adic order of $j$, i.e. $d(j) = d$ if $2^d$ divides $j$ but $2^{d+1}$ does not. Then if $d(n) = d$ we have \eqalign{TE(n) &= (-1)^d \left(\sum_{k\; odd} 2^{-kn} - \sum_{k\; odd} 2^{-2kn} + \sum_{k \; odd} 2^{-4kn} + \ldots\right)\cr &= (-1)^d \left( \dfrac{2^{-n}}{1-4^{-n}} - \dfrac{2^{-2n}}{1-4^{-2n}} + \dfrac{2^{-4n}}{1-4^{-4n}} - \ldots \right)\cr } while $$ME(n) = (-1)^{d+1} \left( \dfrac{2^{-n}}{1-4^{-n}} + \dfrac{2^{-2n}}{1-4^{-2n}} - \dfrac{2^{-4n}}{1-4^{-4n}} + \ldots \right)$$ so $|ME(n)| > |TE(n)|$.
• Hmm, well, it's not elementary, but it is the sum of a rapidly convergent series of elementary functions: $$\sum_{j=0}^\infty \dfrac{(8^{2^j} - 2^{2^j}) \cos(2^{j+1} \pi x)}{16^{2^j} + 1 - 2 \cdot 4^{2^j} \cos(2^{j+2} \pi x)}$$ if I haven't made a mistake. Commented Oct 7, 2014 at 21:49