Comparison of Midpoint and Trapezoidal errors

Assuming a parabolic section of the curve (that it can be well-approximated by a parabola).

Suggested by Elementary Numerical Computing with Mathematica (Skeel and Kelper) , p. 272: “From calculus we know that the area under a parabola is one-third the area of the rectangle that contains it.” (See the picture on p. 271.) 

What this next bit of code says is that for a snippet of a parabola, the tangent parallel to the secant through the endpoints of an interval occurs at the midpoint of the interval.

Clear[a,b,c,x0,x1,x2]
f[x_]:=a*x^2+b*x+c
mends=Simplify[(f[x1]-f[x0])/(x1-x0)]
middle=x/.Solve[f'[x]==mends,x]
middle=middle[[1]]

Suppose we’re on the interval [x0,x1]. 

The parallelogram box encompassing the parabola has a width w (=x1-x0)  and height the difference in f between the two lines: the secant line joining the ends, and the midpoint tangent line:

ys[x_]:=f[x0]+mends*(x-x0)
ym[x_]:=f[middle]+f'[middle](x-middle)
Simplify[Integrate[ys[x]-f[x],{x,x0,x1}]]
Simplify[Integrate[f[x]-ym[x],{x,x0,x1}]]

a=1;
b=2;
c=3;
x0=0;
x1=2;
Plot[{f[x],ys[x],ym[x],f[middle]},{x,x0,x1},PlotRange->{0,12},PlotStyle->{{Black,Thick},{Red,Dashed},{Blue,Dashed},{Gray,Dashed}}]
trapError=Simplify[Integrate[ys[x]-f[x],{x,x0,x1}]]
midError=Integrate[f[x]-ym[x],{x,x0,x1}]