Trapezoidal Rule

We will obtain the trapezoidal rule (approximation) from averaging the right and left endpoint approximations: abf(x)dx12(Ln+Rn)=12(i=1nf(xi1)Δx+i=1nf(xi)Δx){\int_{{a}}^{{b}}}{f{{\left({x}\right)}}}{d}{x}\approx\frac{{1}}{{2}}{\left({L}_{{n}}+{R}_{{n}}\right)}=\frac{{1}}{{2}}{\left({\sum_{{{i}={1}}}^{{n}}}{f{{\left({x}_{{{i}-{1}}}\right)}}}\Delta{x}+{\sum_{{{i}={1}}}^{{n}}}{f{{\left({x}_{{i}}\right)}}}\Delta{x}\right)}.

Rewriting it we obtain the trapezoidal rule: abf(x)dxTn=Δx2(f(x0)+2f(x1)+2f(x2)++2f(xn1)+f(xn)){\int_{{a}}^{{b}}}{f{{\left({x}\right)}}}{d}{x}\approx{T}_{{n}}=\frac{{\Delta{x}}}{{2}}{\left({f{{\left({x}_{{0}}\right)}}}+{2}{f{{\left({x}_{{1}}\right)}}}+{2}{f{{\left({x}_{{2}}\right)}}}+\ldots+{2}{f{{\left({x}_{{{n}-{1}}}\right)}}}+{f{{\left({x}_{{n}}\right)}}}\right)}.trapezoidal rule

It is called trapezoidal because as appeared this formula gives approximation by approximating area not with rectangles but trapezoids, with height of trapezoid Δx\Delta{x} and lengths of bases f(xi1){f{{\left({x}_{{{i}-{1}}}\right)}}} and f(xi){f{{\left({x}_{{i}}\right)}}}. Thus the area of i-th trapezoid is Δx(f(xi1)+f(xi)2)\Delta{x}{\left(\frac{{{f{{\left({x}_{{{i}-{1}}}\right)}}}+{f{{\left({x}_{{i}}\right)}}}}}{{2}}\right)}. Adding all trapezoids will give the trapezoidal rule.

It is worth noting that if function is concave up then trapezoidal rule overestimates integral, if function is concave down then trapezoidal rule underestimates integral.

Example 1. Use Trapezoidal Rule to approximate value of 121x2dx{\int_{{1}}^{{2}}}\frac{{1}}{{{x}}^{{2}}}{d}{x} with n=5{n}={5}.

Here a=1{a}={1}, b=2{b}={2}, f(x)=1x2{f{{\left({x}\right)}}}=\frac{{1}}{{{x}}^{{2}}} and n=5{n}={5}. So, Δx=ban=215=0.2\Delta{x}=\frac{{{b}-{a}}}{{n}}=\frac{{{2}-{1}}}{{5}}={0.2}.

So, 121x2(dx)Tn=0.22(f(1)+2f(1.2)+2f(1.4)+2f(1.6)+2f(1.8)+f(2))={\int_{{1}}^{{2}}}\frac{{1}}{{{x}}^{{2}}}{\left({d}{x}\right)}\approx{T}_{{n}}=\frac{{0.2}}{{2}}{\left({f{{\left({1}\right)}}}+{2}{f{{\left({1.2}\right)}}}+{2}{f{{\left({1.4}\right)}}}+{2}{f{{\left({1.6}\right)}}}+{2}{f{{\left({1.8}\right)}}}+{f{{\left({2}\right)}}}\right)}=

=0.1(112+2(1.2)2+2(1.4)2+2(1.6)2+2(1.8)2+122)0.505783={0.1}{\left(\frac{{1}}{{{1}}^{{2}}}+\frac{{2}}{{{\left({1.2}\right)}}^{{2}}}+\frac{{2}}{{{\left({1.4}\right)}}^{{2}}}+\frac{{2}}{{{\left({1.6}\right)}}^{{2}}}+\frac{{2}}{{{\left({1.8}\right)}}^{{2}}}+\frac{{1}}{{{2}}^{{2}}}\right)}\approx{0.505783}.

In the Left Endpoint, Right Endpoint note we found for this example Ln=0.580783{L}_{{n}}={0.580783} and Rn=0.430783{R}_{{n}}={0.430783}.

So, 12(Ln+Rn)=12(0.580783+0.430783)=0.505783=Tn\frac{{1}}{{2}}{\left({L}_{{n}}+{R}_{{n}}\right)}=\frac{{1}}{{2}}{\left({0.580783}+{0.430783}\right)}={0.505783}={T}_{{n}} as expected.

True value of integral is I=121x2dx=0.5{I}={\int_{{1}}^{{2}}}\frac{{1}}{{{x}}^{{2}}}{d}{x}={0.5}.

So, the trapezoidal rule overestimates integral as expected (function f(x)=1x2{f{{\left({x}\right)}}}=\frac{{1}}{{{x}}^{{2}}} is concave up on [1,2]{\left[{1},{2}\right]}).

When we approximate integral we will always have some error: E=abf(x)dxApp{E}={\int_{{a}}^{{b}}}{f{{\left({x}\right)}}}{d}{x}-{A}{p}{p} where App{A}{p}{p} is approximation and E{E} is error.

Error bound for the trapezoidal rule. Suppose f(x)M{\left|{f{''}}{\left({x}\right)}\right|}\le{M} for axb{a}\le{x}\le{b} then EM(ba)312n2{\left|{E}\right|}\le\frac{{{M}{{\left({b}-{a}\right)}}^{{3}}}}{{{12}{{n}}^{{2}}}}.

Example 2. How large should we take n in order to guarantee that the trapezoidal rule approximation for 121x2dx{\int_{{1}}^{{2}}}\frac{{1}}{{{x}}^{{2}}}{d}{x} are accurate to within 0.0002?

Here a=1{a}={1}, b=2{b}={2}, f(x)=1x2{f{{\left({x}\right)}}}=\frac{{1}}{{{x}}^{{2}}}.

Then f(x)=2x3{f{'}}{\left({x}\right)}=-\frac{{2}}{{{x}}^{{3}}} and f(x)=6x4{f{''}}{\left({x}\right)}=\frac{{6}}{{{x}}^{{4}}}.

Therefore f(x)6{\left|{f{''}}{\left({x}\right)}\right|}\le{6} for 1x2{1}\le{x}\le{2}.

Thus, 6(21)312n2>0.0002\frac{{{6}{{\left({2}-{1}\right)}}^{{3}}}}{{{12}{{n}}^{{2}}}}>{0.0002} or n2>10.0004{{n}}^{{2}}>\frac{{1}}{{{0.0004}}}.

So, n>10.0004=50{n}>\frac{{1}}{\sqrt{{{0.0004}}}}={50}.

So, we need to take n=51{n}={51}.