Trapezoid rule error I am trying to compute the error in the trapezoid rule integration for a function $f(x)$ 
in the interval $[a,b]$.
I believe I have to Taylor-expand $f(x)$ around $x=a$ 
$f(a) + (x-a)f'(a)+ 1/2 (x-a)^2 f''(a) + ...$
and then do the integral of this, to later use it when comparing with the trapezoid rule:
$(b-a) (f(b) + f(a))/2$
However I am stuck on the integration of the Taylor expansion and on how to deduct from this the trapezoid approximation.
Can someone give me a hint on how to proceed? Thanks.
 A: Estimating the error with the Taylor expansion is quite messy.  
For an alternative, consider the local error on a subinterval $[x_n, x_{n+1}]$ with $h = x_{n+1} - x_n$.
The error in approximating the integral with the trapezoidal formula is
$$E_n = \frac{h}{2}[f(x_n) + f(x_{n+1})] - \int_{x_n}^{x_{n+1}} f(x) \, dx.$$
Integration by parts shows this to be
$$E_n = \int_{x_n}^{x_{n+1}}(x-c)f'(x) \, dx,$$
where $c = (x_{n+1}+x_n)/2$ is the midpoint.  
To see this, note that
$$x_{n+1} - c = c - x_n = \frac{x_{n+1} - x_n}{2} = \frac{h}{2},$$
and with $u = (x-c)$ and $dv = f'(x)dx$, integration by parts yields
$$\int_{x_n}^{x_{n+1}}(x-c)f'(x) \, dx = (x-c)f(x)|_{x_n}^{x_{n+1}} - \int_{x_n}^{x_{n+1}} f(x) \, dx = E_n.$$
If the derivative is bounded as $|f'(x)| \leqslant M$,  we can bound the error as
$$|E_n| \leqslant \int_{x_n}^{x_{n+1}}|x-c||f'(x)| \, dx \\ \leqslant M\int_{x_n}^{x_{n+1}}|x-c| \, dx \\ = \frac{M}{4}(x_{n+1} - x_n)^2 \\ = \frac{M}{4}h^2.$$
Approximating the integral over $[a,b]$ with $m$ subintervals of length $h = (b-a)/m$, has a global error bound of
$$|GE| \leqslant \sum_{n=1}^{m} |E_n| = m\frac{M}{4}h^2 = \frac{M(b-a)^2}{4m}$$
If the second derivative is bounded  as $|f''(x)| \leqslant M$, then we can demonstrate $O(h^3)$ local accuracy. An integration by parts of the previous integral for $E_n$ yields
$$E_n = \frac1{2} \int_{x_n}^{x_{n+1}} [(h/2)^2 - (x-c)^2]f''(x) \, dx.$$
Using the bound for $f''$ and integrating we obtain the local and global error bounds
$$|E_n| \leqslant \frac{M}{12}h^3, \\ |GE| \leqslant \frac{M(b-a)^3}{12m^2}.$$
