Trapezoid rule illustration

Below the integral of 1/x from 1 to 2 is approximated by the Trapezoid Rule with 5 trapezoids. You can clearly see that the approximation will be (1) reasonably close, and (2) an overestimate. Consider the inset picture which shows a closeup of the top of the 2nd trapezoid and the function.

TrapezoidPoints=Table[{x,1/x},{x,1,2,.2}];
TPlot=ListPlot[{TrapezoidPoints,TrapezoidPoints},Joined->{True,False},PlotStyle->{Red,PointSize[Large]},Filling->Axis];
FPlot=Plot[1/x,{x,1,2}];
Show[{TPlot,FPlot},PlotRange->{{1,2},{0,1.8}},AxesLabel->{"x","y"}, PlotLabel->"(∫_1^2)(1/x)\[DifferentialD]x and Trapezoid approximation with n=5 and closeup (inset)",Epilog->Inset[Show[{TPlot,FPlot},FrameLabel->{"x","y"},Frame->True,Background->White,PlotRange->{{1.18,1.43},{1/1.18-.01,1/1.43+.01}}],{1.8,1.25}]]

Four Riemann Approximations Compared

The commands below set up the approxiimation for the integral of f from a to b for four rules, left- and right-endpoint approximations, midpoint rule, and trapezoid rule. A comparative summary table is given for various increasing values of n.

LeftApprox[f_,n_,a_,b_]:=Sum[(b-a)/n*f[a+(i-1)(b-a)/n],{i,1,n}]
RightApprox[f_,n_,a_,b_]:=Sum[(b-a)/n*f[a+(i)(b-a)/n],{i,1,n}]
MidApprox[f_,n_,a_,b_]:=Sum[(b-a)/n*f[a+(i-1/2)(b-a)/n],{i,1,n}]
TrapApprox[f_,n_,a_,b_]:=
(1/2)(LeftApprox[f,n,a,b]+RightApprox[f,n,a,b])

Now check the definitions by using f(x)=1/x, a=1, and b=2.

f[x_]:=1/x;
LeftApprox[f,5,1,2]//N
RightApprox[f,5,1,2]//N
MidApprox[f,5,1,2]//N
TrapApprox[f,5,1,2]//N
NIntegrate[1/x,{x,1,2}]

Next build a table for n starting at 5 and increasing in steps of 5, for all approximations.

ApproxData=Table[{n,N[LeftApprox[f,n,1,2]],N[RightApprox[f,n,1,2]],N[MidApprox[f,n,1,2]],
N[TrapApprox[f,n,1,2]]},{n,Table[5*2^i,{i,0,5}]}];
TableForm[ApproxData,TableHeadings->{{},{"n","(Subscript[L, n])","(Subscript[R, n])","(Subscript[M, n])","(Subscript[T, n])"}}]

The error between (Subscript[L, n]),(Subscript[R, n]),(Subscript[M, n]), (Subscript[T, n]), and (∫_1^2)(1/x)dx

Needs["PlotLegends`"];ListPlot[{Table[{n,N[LeftApprox[f,n,1,2]]},{n,Table[5*2^i,{i,2,5}]}],Table[{n,N[RightApprox[f,n,1,2]]},{n,Table[5*2^i,{i,2,5}]}],Table[{n,N[MidApprox[f,n,1,2]]},{n,Table[5*2^i,{i,2,5}]}],
Table[{n,N[TrapApprox[f,n,1,2]]},{n,Table[5*2^i,{i,2,5}]}]},AxesLabel->{"n","Estimate"},PlotLegend->{"(Subscript[L, n])","(Subscript[R, n])","(Subscript[M, n])","(Subscript[T, n])"},LegendPosition->{.65,-.5},PlotStyle->PointSize[.015],PlotLabel->"Approximations of  (∫_1^2)(1/x)\[DifferentialD]x",PlotMarkers->Automatic]

A closer look at the error between (Subscript[M, n]), (Subscript[T, n]), and (∫_1^2)(1/x)dx

ListPlot[{Table[{n,N[MidApprox[f,n,1,2]]},{n,Table[5*2^i,{i,2,5}]}],
Table[{n,N[TrapApprox[f,n,1,2]]},{n,Table[5*2^i,{i,2,5}]}],Table[{n,Integrate[1/x,{x,1,2}]},{n,Table[5*2^i,{i,2,5}]}]},AxesLabel->{"n","Estimate"},PlotLegend->{"(Subscript[M, n])","(Subscript[T, n])","Actual"},LegendPosition->{.65,-.5},PlotStyle->{PointSize[.015],PointSize[.015],PointSize[.001]},Joined->{False,False,True},PlotLabel->"(Subscript[M, n]) and (Subscript[T, n]) approximations of  (∫_1^2)(1/x)\[DifferentialD]x",PlotMarkers->Automatic]

A closer look at the error between (Subscript[M, n]), (Subscript[S, n]), and (∫_1^2)(1/x)dx

SimpsonApprox[f_,n_,a_,b_]:=((b-a)/(3n))*(f[a]+Sum[If[EvenQ[i],2,4]*f[a+i(b-a)/n],{i,1,n-1}]+f[b]);
ListPlot[{Table[{n,N[MidApprox[f,n,1,2]]},{n,Table[4*2^i,{i,1,5}]}],
Table[{n,N[SimpsonApprox[f,n,1,2]]},{n,Table[4*2^i,{i,1,5}]}],Table[{n,Integrate[1/x,{x,1,2}]},{n,Table[4*2^i,{i,1,5}]}]},AxesLabel->{"n","Estimate"},PlotLegend->{"(Subscript[M, n])","(Subscript[S, n])","Actual"},LegendPosition->{.65,-.5},PlotStyle->{PointSize[.015],PointSize[.015],PointSize[.001]},Joined->{False,False,True},PlotLabel->"(Subscript[M, n]) and (Subscript[T, n]) approximations of  (∫_1^2)(1/x)\[DifferentialD]x",PlotMarkers->Automatic,PlotRange->{{4,130},{.69311,.69316}},Frame->True]

Example 1 of Comparison Theorem (∫_0^∞)(e^(-(x^2)))dx

Plot[{Exp[-x],Exp[-x^2]},{x,0,3},PlotStyle->{{ Blue,Red},{Thickness[.01],Thickness[.005]}},AspectRatio->1]

\[Placeholder]

Integrate[Exp[-x],{x,1,Infinity}]

Conclusion: Since the integral under the red curve from 1 to ∞ converges, and the integral under both curves from 0 to 1 converge, then the integral under the blue curve from 0 to ∞ converges.

Example 2 of Comparison Theorem (∫_0^1)(((Sec[x])^2)/(x^(3/2)))dx

Plot[{Sec[x]^2/(x*Sqrt[x]),1/(x Sqrt[x])},{x,0,1},PlotRange->{0,10}]

Integrate[1/(x Sqrt[x]),{x,0,1}]

Conclusion: Since the integral under the red curve from 0 to 1 diverges, so does the corresponding integral under the blue curve.

Example 3 of Comparison Theorem (∫_0^∞)((ArcTan[x])/(2+(e^x)))dx

Plot[{ArcTan[x]/(2+Exp[x]),(Pi/2)/(Exp[x])},{x,0,10}]

Integrate[(Pi/2)/(Exp[x]),{x,0,Infinity}]

Conclusion: Since the integral under the red curve for the limits [0,∞) converges, so does the corresponding integral under the blue curve.