# The error of the midpoint rule for quadrature

Wikipedia says the midpoint formula for numerical integration has error of order $h^3 f''(\xi)$. I am trying to replicate this result.

I'm guessing that I want to use Lagrange's formulation of the remainder for Taylor series. Let $x_0=\frac{a+b}{2}$ (i.e. the midpoint).

The midpoint method says $\int_a^b f(x)dx \approx (b-a)f(\frac{a+b}{2})$, so to get the error I find $(b-a) f(\frac{a+b}{2}) - \int_a^bf(x)dx$. If I expand this using Taylor's theorem I get:

\begin{aligned} error & =(b-a) f(x_0) - \int_a^bf(x_0)+\frac{f'(\xi)(x-x_0)}{2}dx \\ & =\frac{f'(\xi)}{2}\int_a^b(x-x_0)dx \\ & =\frac{f'(\xi)}{2}\int_a^b(x-\frac{a+b}{2})dx \\ & = 0 \end{aligned}

So apparently I have just proven that it has zero error? Any hints as to what I did wrong? (I realize that since wikipedia gives it in terms of $f''$ I probably want to take the expansion one level further to match them, but I don't understand why this doesn't work.)

-
Since $\xi$ depends on $x$, you can't take $f'(\xi)$ outside of the integral. – Hans Lundmark Dec 22 '10 at 21:20

You are right that you need one more term in your Taylor series. If you write $f(x)=f(x_0)+(x-x_0)f'(x_0)+(x-x_0)^2f''(\xi)/2$ and plug that into the midpoint method, the term in $f''$ will survive. What you have done essentially shows that if $f$ is linear, the method is exact.
But why doesn't this work? Shouldn't I be able to write any $f$ as $f(x_0)+f'(\xi)$, regardless of whether it's linear or not? – Xodarap Dec 22 '10 at 21:21
But it hides the fact that $\xi$ depends upon $x$, so you can't factor it out of the integral as you did unless $f$ is linear and $f'(\xi)$ is constant. – Ross Millikan Dec 22 '10 at 21:28