Derive the error for the Midpoint rule

Solution 1:

You can start by obtaining the rule for a single interval, say \begin{align*} \int_{x_i}^{x_{i+1}} f(x) dx -hf(c_i) &= \int_{x_i}^{x_{i+1}}(f(x)-f(c_i))dx\\ & = \int_{x_i}^{x_{i+1}} \left(f(c_i)+f'(c_i)(x-c_i) + \frac{f''(\xi_i(x))}{2}(x-c_i)^2\;-\;f(c_i)\right) dx\\ & = \frac{f''(\xi_i)}{2}\int_{x_i}^{x_{i+1}}(x-c_i)^2 dx = \frac{f''(\xi_i) h^3}{24} \end{align*}

Now, if you take the sum over the $n$ intervals, you get the error term

$$ \sum_{i=1}^n \frac{f''(\xi_i) h^3}{24} = \frac{h^2(b-a)}{24}\left(\frac 1n \sum_{i=1}^n f''(\xi_i)\right) = \frac{h^2(b-a) f''(\xi)}{24}. $$


Some notes:

  1. I used the mean value theorem for integrals. Since $(x-c_i)^2$ does not change sign, we know that $$ \int_{x_i}^{x_{i+1}} \frac{f''(\xi_i(x))}{2}(x-c_i)^2 dx = \frac{f''(\xi_i)}{2} \int_{x_i}^{x_{i+1}} (x-c_i)^2 dx $$

  2. If we assume the $f\in C^2$, the term $\frac 1n \sum f''(\xi_i)$ is an average of values of $f''$, hence between the minimum and maximum of $f''$. The intermediate value theorem says that it will correspond to $f''(\xi)$, for some $\xi \in (a,b)$.

Solution 2:

There is another proof that avoids double integrals and uses the generalized mean value instead. I have learned this technique from reading @LutzLehmann's answers to very similar questions.


Let $h>0$ be given and consider the problem of computing the integral $$I = \int_{-h}^h f(x)dx.$$ The midpoint rule takes the form $$M_h = 2h f(0).$$ We will now obtain the familiar error formula by studying the auxiliary function $g$ given by $$ g(x) = \int_{-x}^x f(t) dt - 2x f(0).$$ This function is interesting precisely because $$ g(h) = I - M_h.$$ Let $F$ denote an anti-derivative of $f$. Then $$ g(x) = F(x) - F(-x) - 2xf(0).$$ It is clear that $g$ is as smooth as $F$ and that $g(0) = 0$. We have $$g'(x) = f(x) + f(-x) - 2f(0).$$ It follows that $$g'(0) = 0.$$ We have $$g''(x) = f'(x) - f'(-x).$$ It follows that $$g''(0) = 0.$$ We conclude that the graph of $g$ is quite flat near $x=0$. To make further progress we make repeated use of the generalized mean value theorem. There exists at least one $x_1$ between $0$ and $x$ such that $$ \frac{g(x)}{x^3} = \frac{g(x) - g(0)}{x^3 - 0^3} = \frac{g'(x_1)}{3x_1^2}.$$ There exists at least one $x_2$ between $0$ and $x_1$ such that $$ \frac{g'(x_1)}{3x_1^2} = \frac{g'(x_1) - g'(0)}{3x_1^2 - 3\cdot 0^2}= \frac{g''(x_2)}{6x_2}.$$ Similarly, there exists at least one $x_3$ between $0$ and $x_2$ such that $$ \frac{g''(x_2)}{6x_2} = \frac{g''(x_2)- g''(0)}{6x_2 - 6 \cdot 0} = \frac{g'''(x_3)}{6} = \frac{f''(x_3) + f''(-x_3)}{6}$$ Finally, by the continuity of $f''$ there is at least one $\xi$ between $-x_3$ and $x_3$ such that $$\frac{g(x)}{x^3} = \frac{f''(\xi)}{3}.$$ In particular, there is at least one $\xi$ in $[-h,h]$ such that $$I - M_h = g(h) = \frac{f''(\xi)}{3} h^3.$$ Replacing $h$ with $h/2$ yields the familiar result, i.e, $$ \int_{-h/2}^{h/2} f(x) dx - h f(0) = \frac{f''(\xi)}{24} h^3.$$ We finish the proof as suggested by @RRL.