Trapezoidal Rule

Consider the result of Theorem 10 with [Maple Math] the linear polynomial fit to two data points:

[Maple Math]

We can take the integral of both sides of this expression. First, we get

> P1:=x->((x-x[1])/(x[0]-x[1]))*f(x[0])+((x-x[0])/(x[1]-x[0]))*f(x[1]);

[Maple Math]

> x[1]:=x[0]+h:x[0]:=x0:

When we use the notation [Maple Math] , for equidistant points, the integral becomes:

> iP1:=Int(P1(x),x=x0..x[1]);

[Maple Math]

> iP1:=factor(value(iP1));

[Maple Math]

The error term becomes:

> err:=(D@@2)(f)(xi(x))*(x-x[0])*(x-x[1])/2;

[Maple Math]

> Ierr:=Int(err,x=x[0]..x[1]);

[Maple Math]

In this integrand, the term [Maple Math] does not change sign over the interval [Maple Math] so that we can apply the Weighted Mean Value Theorem for Integrals:

> Ierr=(D@@2)(f)(xi)/2*Int((x-x0)*(x-x0-h),x=x0..x0+h);

[Maple Math]

with [Maple Math] in the interval [Maple Math] . This becomes

> Ierr2:=rhs(%);

[Maple Math]

> Ierr3:=value(Ierr2);

[Maple Math]

>

The formula then becomes:

> Int(f(x),x=x[0]..x[1])=iP1+Ierr3;

[Maple Math]

>

which is known as the Trapezoidal Rule:

> pl1:=plot(3+sin(2*x+.5)/2,x=0..3,y=0..4):y0:=3.+sin(2.5)/2.:y1:=3.+sin(4.5)/2.:

> pl2:=plot({[1,t,t=0..y0],[2,t,t=0..y1],[t,(t-1)*(y1-y0)+y0,t=1..2]},x=0..3,y=0..4,color=black):

> with(plots):display({pl1,pl2});

[Maple Plot]

>

>

>

If the second derivative of [Maple Math] is bounded over the interval [Maple Math] , i.e. [Maple Math] , then the maximum error is given by [Maple Math] .

For example,

> f:=x->3+sin(2*x+.5)/2;ddf:=(D@@2)(f);

[Maple Math]

[Maple Math]

> for i from 0 to 5 do h:=2.^(-i): int1:=int(f(x),x=1..1.+h):int2:=h*(f(1.+h)+f(1.))/2.:print(h, int2,abs(int2-int1),h^3*2./12.); od:

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

>

> f:=x->3*x-5;

[Maple Math]

> for i from 0 to 5 do h:=2.^(-i): int1:=int(f(x),x=1..1.+h):int2:=h*(f(1.+h)+f(1.))/2.:print(h, int2,abs((int2-int1)/int1),0); od:

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

>