# Trapezoidal Rule

• We know from a previous lesson that we can use Riemann Sums to evaluate a definite integral $$\int\limits_a^b {f\left( x \right)dx}.$$

Riemann Sums use rectangles to approximate the area under a curve.

Another useful integration rule is the Trapezoidal Rule. Under this rule, the area under a curve is evaluated by dividing the total area into little trapezoids rather than rectangles.

Let $$f\left( x \right)$$ be continuous on $$\left[ {a,b} \right].$$ We partition the interval $$\left[ {a,b} \right]$$ into $$n$$ equal subintervals, each of width

${\Delta x = \frac{{b – a}}{n},}$

such that

$a = {x_0} \lt {x_1} \lt {x_2} \lt \cdots \lt {x_n} = b.$

The Trapezoidal Rule for approximating $$\int\limits_a^b {f\left( x \right)dx}$$ is given by

${\int\limits_a^b {f\left( x \right)dx} \approx {T_n} }={ {\frac{{\Delta x}}{2}}\left[ {{f\left( {{x_0}} \right)} + {2f\left( {{x_1}} \right)} }\right.}+{\left.{ {2f\left( {{x_2}} \right)} + \cdots }\right.}+{\left.{ {2f\left( {{x_{n – 1}}} \right)} + {f\left( {{x_n}} \right)}} \right],}$

where $$\Delta x = \large{\frac{{b – a}}{n}}\normalsize$$ and $${x_i} = a + i\Delta x.$$

As $$n \to \infty,$$ the right-hand side of the expression approaches the definite integral $$\int\limits_a^b {f\left( x \right)dx}.$$

• ## Solved Problems

Click a problem to see the solution.

### Example 1

Use the Trapezoidal Rule with $$n = 6$$ to approximate $$\int\limits_0^\pi {{{\sin }^2}xdx}.$$

### Example 2

A function $$f\left( x \right)$$ is given by the table of values. Approximate the area under the curve $$y = f\left( x \right)$$ between $$x = 0$$ and $$x = 8$$ using the Trapezoidal Rule with $$n = 4$$ subintervals.

### Example 3

A function $$f\left( x \right)$$ is given by the table of values. Approximate the area under the curve $$y = f\left( x \right)$$ between $$x = -4$$ and $$x = 2$$ using the Trapezoidal Rule with $$n = 6$$ subintervals.

### Example 4

Approximate the area under the curve $$y = f\left( x \right)$$ between $$x = 0$$ and $$x = 10$$ using the Trapezoidal Rule with $$n = 5$$ subintervals.

### Example 5

Approximate the area under the curve $$y = {2^x}$$ between $$x = -1$$ and $$x = 3$$ using the Trapezoidal Rule with $$n = 4$$ subintervals.

### Example 6

Approximate the area under the curve $$y = \large{\frac{1}{x}}\normalsize$$ between $$x = 1$$ and $$x = 5$$ using the Trapezoidal Rule with $$n = 4$$ subintervals.

### Example 7

Approximate the integral $$\int\limits_0^1 {{x^3}dx}$$ using the Trapezoidal Rule with $$n = 2$$ subintervals.

### Example 8

Approximate the integral $$\int\limits_0^2 {{x^2}dx}$$ using the Trapezoidal Rule with $$n = 3$$ subintervals.

### Example 9

Using the Trapezoidal Rule with $$n = 10$$ subintervals, evaluate the integral $$\int\limits_0^1 {\large{\frac{{dx}}{{1 + {x^2}}}}\normalsize}$$ and calculate the approximate value of $$\pi.$$ Round the answer to $$2$$ decimal places.

### Example 10

Using the Trapezoidal Rule with $$n = 3$$ subintervals approximate the area under the curve $$f\left( x \right) = 3x – {x^2}$$ between $$x = 0$$ and $$x = 3.$$ Estimate the relative percent error of the approximation.

### Example 11

Using the Trapezoidal Rule with $$n = 4$$ subintervals approximate the area under the sine curve $$f\left( x \right) = \sin x$$ between $$x = 0$$ and $$x = \pi$$ to $$3$$ decimal places. Estimate the relative percent error of the approximation.

### Example 1.

Use the Trapezoidal Rule with $$n = 6$$ to approximate $$\int\limits_0^\pi {{{\sin }^2}xdx}.$$

Solution.

Here

${f\left( x \right) = {\sin ^2}x,\;\;}\kern0pt{a = 0,\;\;}\kern0pt{b = \pi .}$

The width of each subinterval is

${\Delta x = \frac{{b – a}}{n} = \frac{\pi }{6},}$

so the grid points have the coordinates $${x_i} = \large{\frac{{i\pi }}{6}}\normalsize.$$

Calculate the values of the function $$f\left( x \right)$$ at the points $${x_i}:$$

${f\left( {{x_0}} \right) }={ f\left( 0 \right) }={ {\sin ^2}0 }={ {0^2} }={ 0;}$

${f\left( {{x_1}} \right) }={ f\left( {\frac{\pi }{6}} \right) }={ {\sin ^2}\frac{\pi }{6} }={ {\left( {\frac{1}{2}} \right)^2} }={ \frac{1}{4};}$

${f\left( {{x_2}} \right) }={ f\left( {\frac{{2\pi }}{6}} \right) }={ {\sin ^2}\frac{\pi }{3} }={ {\left( {\frac{{\sqrt 3 }}{2}} \right)^2} }={ \frac{3}{4};}$

${f\left( {{x_3}} \right) }={ f\left( {\frac{{3\pi }}{6}} \right) }={ {\sin ^2}\frac{\pi }{2} }={ {1^2} }={ 1;}$

${f\left( {{x_4}} \right) }={ f\left( {\frac{{4\pi }}{6}} \right) }={ {\sin ^2}\frac{{2\pi }}{3} }={ {\left( {\frac{{\sqrt 3 }}{2}} \right)^2} }={ \frac{3}{4};}$

${f\left( {{x_5}} \right) }={ f\left( {\frac{{5\pi }}{6}} \right) }={ {\sin ^2}\frac{{5\pi }}{6} }={ {\left( {\frac{1}{2}} \right)^2} }={ \frac{1}{4};}$

${f\left( {{x_6}} \right) }={ f\left( \pi \right) }={ {\sin ^2}\pi }={ {0^2} }={ 0.}$

The Trapezoidal Rule formula is written in the form

${\int\limits_0^\pi {{{\sin }^2}xdx} \approx {T_6} }={ \frac{{\Delta x}}{2}\left[ {f\left( {{x_0}} \right) + 2f\left( {{x_1}} \right) + \cdots }\right.}+{\left.{ 2f\left( {{x_5}} \right) + f\left( {{x_6}} \right)} \right] }={ \frac{\pi }{{12}}\left[ {0 + 2 \cdot \frac{1}{4} + 2 \cdot \frac{3}{4} }\right.}+{\left.{ 2 \cdot 1 + 2 \cdot \frac{3}{4} + 2 \cdot \frac{1}{4} + 0} \right] }={ \frac{\pi }{{12}}\left[ {\frac{1}{2} + \frac{3}{2} + 2 + \frac{3}{2} + \frac{1}{2}} \right] }={ \frac{\pi }{{12}} \cdot \frac{{12}}{2} }={ \frac{\pi }{2}}$

We can also determine the exact value of the integral:

${\int\limits_0^\pi {{{\sin }^2}xdx} }={ \frac{1}{2}\int\limits_0^\pi {\left( {1 – \cos 2x} \right)dx} }={ \frac{1}{2}\left[ {x – \frac{{\sin 2x}}{2}} \right]_0^\pi }={ \frac{1}{2}\left[ {\left( {\pi – 0} \right) – 0} \right] }={ \frac{\pi }{2}.}$

So, in this particular example, the trapezoidal approximation $${T_6}$$ coincides with the exact value of the integral.

### Example 2.

A function $$f\left( x \right)$$ is given by the table of values. Approximate the area under the curve $$y = f\left( x \right)$$ between $$x = 0$$ and $$x = 8$$ using the Trapezoidal Rule with $$n = 4$$ subintervals.

Solution.

The Trapezoidal Rule formula for $$n= 4$$ subintervals has the form

${{T_4} = \frac{{\Delta x}}{2}\left[ {f\left( {{x_0}} \right) + 2f\left( {{x_1}} \right) }\right.}+{\left.{ 2f\left( {{x_2}} \right) + 2f\left( {{x_3}} \right) }\right.}+{\left.{ f\left( {{x_4}} \right)} \right].}$

The width of the subinterval is $$\Delta x = 2.$$

Substituting the values of the function from the table, we find the approximate area under the curve:

${A \approx {T_4} \text{ = }}\kern0pt{ \frac{2}{2}\left[ {3 + 2 \cdot 7 + 2 \cdot 11 + 2 \cdot 9 + 3} \right] }={ 3 + 14 + 22 + 18 + 3 }={ 60.}$

### Example 3.

A function $$f\left( x \right)$$ is given by the table of values. Approximate the area under the curve $$y = f\left( x \right)$$ between $$x = -4$$ and $$x = 2$$ using the Trapezoidal Rule with $$n = 6$$ subintervals.

Solution.

We apply the Trapezoidal Rule formula with $$n = 6$$ subintervals which is given by

${{T_6} = \frac{{\Delta x}}{2}\left[ {f\left( {{x_0}} \right) + 2f\left( {{x_1}} \right) }\right.}+{\left.{ 2f\left( {{x_2}} \right) + 2f\left( {{x_3}} \right) }\right.}+{\left.{ 2f\left( {{x_4}} \right) + 2f\left( {{x_5}} \right) }\right.}+{\left.{ f\left( {{x_6}} \right)} \right].}$

The width of each interval is $$\Delta x = 1.$$

The function values are known from the table, so we can easily calculate the approximate value of the area:

${A \approx {T_6} \text{ = }}\kern0pt{\frac{1}{2}\left[ {0 + 2 \cdot 4 + 2 \cdot 5 }\right.}+{\left.{ 2 \cdot 3 + 2 \cdot 10 }\right.}+{\left.{ 2 \cdot 11 + 2} \right] }={ \frac{1}{2}\left[ {8 + 10 + 6 }\right.}+{\left.{ 20 + 22 + 2} \right] }={ \frac{{68}}{2} }={ 34.}$

### Example 4.

Approximate the area under the curve $$y = f\left( x \right)$$ between $$x = 0$$ and $$x = 10$$ using the Trapezoidal Rule with $$n = 5$$ subintervals.

Solution.

The Trapezoidal Rule formula for $$n = 5$$ intervals is given by

${{T_5} = \frac{{\Delta x}}{2}\left[ {f\left( {{x_0}} \right) + 2f\left( {{x_1}} \right) }\right.}+{\left.{ 2f\left( {{x_2}} \right) + 2f\left( {{x_3}} \right) }\right.}+{\left.{ 2f\left( {{x_4}} \right) + f\left( {{x_5}} \right)} \right].}$

It follows from the figure that $$\Delta x = 2.$$ The function values at the endpoints of the intervals are

$f\left( {{x_0}} \right) = f\left( 0 \right) = 4;$

$f\left( {{x_1}} \right) = f\left( 2 \right) = 6;$

$f\left( {{x_2}} \right) = f\left( 4 \right) = 6;$

$f\left( {{x_3}} \right) = f\left( 6 \right) = 4;$

$f\left( {{x_4}} \right) = f\left( 8 \right) = 4;$

$f\left( {{x_5}} \right) = f\left( {10} \right) = 5.$

Hence, the approximate value of the area is equal to

${A \approx {T_5} }={ \frac{2}{2}\left[ {4 + 2 \cdot 6 }\right.}+{\left.{ 2 \cdot 6 + 2 \cdot 4 }\right.}+{\left.{ 2 \cdot 4 + 5} \right] }={ 49.}$

### Example 5.

Approximate the area under the curve $$y = {2^x}$$ between $$x = -1$$ and $$x = 3$$ using the Trapezoidal Rule with $$n = 4$$ subintervals.

Solution.

The Trapezoidal Rule formula for $$n = 4$$ has the form

${{T_4} = \frac{{\Delta x}}{2}\left[ {f\left( {{x_0}} \right) + 2f\left( {{x_1}} \right) }\right.}+{\left.{ 2f\left( {{x_2}} \right) + 2f\left( {{x_3}} \right) }\right.}+{\left.{ f\left( {{x_4}} \right)} \right].}$

Compute the function values $$f\left( {{x_i}} \right):$$

$f\left( {{x_0}} \right) = f\left( { – 1} \right) = {2^{ – 1}} = \frac{1}{2};$

$f\left( {{x_1}} \right) = f\left( 0 \right) = {2^0} = 1;$

$f\left( {{x_2}} \right) = f\left( 1 \right) = {2^1} = 2;$

$f\left( {{x_3}} \right) = f\left( 2 \right) = {2^2} = 4;$

$f\left( {{x_4}} \right) = f\left( 3 \right) = {2^3} = 8.$

As $$\Delta x = 1,$$ we get

${A \approx {T_4} \text{ = }}\kern0pt{ \frac{1}{2}\left[ {\frac{1}{2} + 2 \cdot 1 + 2 \cdot 2 + 2 \cdot 4 + 8} \right] }={ \frac{1}{2} \cdot 22\frac{1}{2} }={ 11\frac{1}{4}.}$

### Example 6.

Approximate the area under the curve $$y = \large{\frac{1}{x}}\normalsize$$ between $$x = 1$$ and $$x = 5$$ using the Trapezoidal Rule with $$n = 4$$ subintervals.

Solution.

We write the Trapezoidal Rule formula for $$n = 4$$ subintervals:

${{T_4} = \frac{{\Delta x}}{2}\left[ {f\left( {{x_0}} \right) + 2f\left( {{x_1}} \right) }\right.}+{\left.{ 2f\left( {{x_2}} \right) + 2f\left( {{x_3}} \right) }\right.}+{\left.{ f\left( {{x_4}} \right)} \right].}$

The function has the following values at the points $${x_i}:$$

${f\left( {{x_0}} \right) = f\left( 1 \right) }={ \frac{1}{1} }={ 1;}$

${f\left( {{x_1}} \right) = f\left( 2 \right) }={ \frac{1}{2};}$

${f\left( {{x_2}} \right) = f\left( 3 \right) }={ \frac{1}{3};}$

${f\left( {{x_3}} \right) = f\left( 4 \right) }={ \frac{1}{4};}$

${f\left( {{x_4}} \right) = f\left( 5 \right) }={ \frac{1}{5}.}$

Since $$\Delta x = 1,$$ we obtain

${A \approx {T_4} }={ \frac{1}{2}\left[ {1 + 2 \cdot \frac{1}{2} + 2 \cdot \frac{1}{3} }\right.}+{\left.{ 2 \cdot \frac{1}{4} + \frac{1}{5}} \right] }={ \frac{1}{2}\left[ {1 + 1 + \frac{2}{3} }\right.}+{\left.{ \frac{1}{2} + \frac{1}{5}} \right] }={ \frac{1}{2} \cdot \frac{{30 + 30 + 20 + 15 + 8}}{{30}} }={ \frac{1}{2} \cdot \frac{{101}}{{30}} }={ \frac{{101}}{{60}}}$

### Example 7.

Approximate the integral $$\int\limits_0^1 {{x^3}dx}$$ using the Trapezoidal Rule with $$n = 2$$ subintervals.

Solution.

The Trapezoidal Rule formula with $$n = 2$$ subintervals is written as

${{T_2} = \frac{{\Delta x}}{2}\left[ {f\left( {{x_0}} \right) + 2f\left( {{x_1}} \right) }\right.}+{\left.{ f\left( {{x_2}} \right)} \right],}$

where

${\Delta x = \frac{{b – a}}{n} }={ \frac{{1 – 0}}{2} }={ \frac{1}{2},}$

and the function has the following values:

${f\left( {{x_0}} \right) = f\left( 0 \right) }={ {0^3} }={ 0;}$

${f\left( {{x_1}} \right) = f\left( {\frac{1}{2}} \right) }={ {\left( {\frac{1}{2}} \right)^3} }={ \frac{1}{8};}$

${f\left( {{x_2}} \right) = f\left( 1 \right) }={ {1^3} }={ 1.}$

Hence

${\int\limits_0^1 {{x^3}dx} \approx {T_2} }={ \frac{1}{4}\left[ {0 + 2 \cdot \frac{1}{8} + 1} \right] }={ \frac{1}{4} \cdot \frac{5}{4} }={ \frac{5}{{16}}}$

### Example 8.

Approximate the integral $$\int\limits_0^2 {{x^2}dx}$$ using the Trapezoidal Rule with $$n = 3$$ subintervals.

Solution.

We write the Trapezoidal Rule formula with $$n = 3$$ subintervals:

${{T_3} = \frac{{\Delta x}}{2}\left[ {f\left( {{x_0}} \right) + 2f\left( {{x_1}} \right) }\right.}+{\left.{ 2f\left( {{x_2}} \right) + f\left( {{x_3}} \right)} \right].}$

where

${\Delta x = \frac{{b – a}}{n} }={ \frac{{2 – 0}}{3} }={ \frac{2}{3},}$

and the function has the following values at $${x_i}:$$

${f\left( {{x_0}} \right) = f\left( 0 \right) }={ {0^2} }={ 0;}$

${f\left( {{x_1}} \right) = f\left( {\frac{2}{3}} \right) }={ {\left( {\frac{2}{3}} \right)^2} }={ \frac{4}{9};}$

${f\left( {{x_2}} \right) = f\left( {\frac{4}{3}} \right) }={ {\left( {\frac{4}{3}} \right)^2} }={ \frac{{16}}{9};}$

${f\left( {{x_3}} \right) = f\left( 2 \right) }={ {2^2} }={ 4.}$

Then

${\int\limits_0^2 {{x^2}dx} \approx {T_3} }={ \frac{1}{3}\left[ {0 + 2 \cdot \frac{4}{9} + 2 \cdot \frac{{16}}{9} + 4} \right] }={ \frac{1}{3}\left[ {\frac{8}{9} + \frac{{32}}{9} + 4} \right] }={ \frac{1}{3} \cdot \frac{{8 + 32 + 36}}{9} }={ \frac{1}{3} \cdot \frac{{76}}{9} }={ \frac{{76}}{{27}}}$

### Example 9.

Using the Trapezoidal Rule with $$n = 10$$ subintervals, evaluate the integral $$\int\limits_0^1 {\large{\frac{{dx}}{{1 + {x^2}}}}\normalsize}$$ and calculate the approximate value of $$\pi.$$ Round the answer to $$2$$ decimal places.

Solution.

We evaluate the given integral by the formula

${{T_{10}} = \frac{{\Delta x}}{2}\left[ {f\left( {{x_0}} \right) + 2f\left( {{x_1}} \right) + \cdots }\right.}+{\left.{ 2f\left( {{x_9}} \right) + f\left( {{x_{10}}} \right)} \right].}$

The width of each subinterval is

$\Delta x = \frac{{b – a}}{n} = \frac{{1 – 0}}{{10}} = 0.1$

The function values at the points $${x_i}$$ are given below:

Plugging in the values from the table into our equation, we obtain:

${\int\limits_0^1 {\frac{{dx}}{{1 + {x^2}}}} \approx {T_{10}} }={ 0.05 \times 15.6996 }={ 0.7850}$

Let’s also evaluate this integral by the Fundamental Theorem of Calculus:

${\int\limits_0^1 {\frac{{dx}}{{1 + {x^2}}}} }={ \left[ {\arctan x} \right]_0^1 }={ \arctan 1 – \arctan 0 }={ \frac{\pi }{4} – 0 }={ \frac{\pi }{4}.}$

Hence, the approximate value of $$\pi$$ with an accuracy of two decimal places is

${\pi \approx 4\int\limits_0^1 {\frac{{dx}}{{1 + {x^2}}}} }={ 4 \times 0.7850 }={ 3.14}$

### Example 10.

Using the Trapezoidal Rule with $$n = 3$$ subintervals approximate the area under the curve $$f\left( x \right) = 3x – {x^2}$$ between $$x = 0$$ and $$x = 3.$$ Estimate the relative percent error of the approximation.

Solution.

The Trapezoidal Rule with $$n = 3$$ segments is written in the form

${{T_3} = \frac{{\Delta x}}{2}\left[ {f\left( {{x_0}} \right) + 2f\left( {{x_1}} \right) }\right.}+{\left.{ 2f\left( {{x_2}} \right) + f\left( {{x_3}} \right)} \right].}$

The width of the subinterval is equal to

$\Delta x = \frac{{b – a}}{n} = \frac{{3 – 0}}{3} = 1.$

We calculate the values of the function at the points $${x_i}:$$

${f\left( {{x_0}} \right) = f\left( 0 \right) }={ 3 \cdot 0 – {0^2} }={ 0;}$

${f\left( {{x_1}} \right) = f\left( 1 \right) }={ 3 \cdot 1 – {1^2} }={ 2;}$

${f\left( {{x_2}} \right) = f\left( 2 \right) }={ 3 \cdot 2 – {2^2} }={ 2;}$

${f\left( {{x_3}} \right) = f\left( 3 \right) }={ 3 \cdot 3 – {3^2} }={ 0.}$

Hence, the approximate value of the area under the curve is given by

${A \approx {T_3} }={ \frac{1}{2}\left[ {0 + 2 \cdot 2 + 2 \cdot 2 + 0} \right] }={ 4.}$

The true solution is found by integration:

${\int\limits_0^3 {f\left( x \right)dx} }={ \int\limits_0^3 {\left( {3x – {x^2}} \right)dx} }={ \left[ {\frac{{3{x^2}}}{2} – \frac{{{x^3}}}{3}} \right]_0^3 }={ \frac{{27}}{2} – \frac{{27}}{3} – 0 }={ \frac{9}{2} }={ 4.5}$

So the relative error is

${\left| \varepsilon \right| }={ \frac{{4.5 – 4}}{{4.5}} }={ \frac{{0.5}}{{4.5}} }={ \frac{1}{9} }\approx{ 11.1\% }$

${A \approx 4,\;}\kern0pt{\left| \varepsilon \right| = 11.1\%}$

### Example 11.

Using the Trapezoidal Rule with $$n = 4$$ subintervals approximate the area under the sine curve $$f\left( x \right) = \sin x$$ between $$x = 0$$ and $$x = \pi$$ to $$3$$ decimal places. Estimate the relative percent error of the approximation.

Solution.

The Trapezoidal Rule formula with $$n = 4$$ segments is given by

${{T_4} = \frac{{\Delta x}}{2}\left[ {f\left( {{x_0}} \right) + 2f\left( {{x_1}} \right) }\right.}+{\left.{ 2f\left( {{x_2}} \right) + 2f\left( {{x_3}} \right) }\right.}+{\left.{ f\left( {{x_4}} \right)} \right].}$

Determine the width of each subinterval:

${\Delta x = \frac{{b – a}}{n} }={ \frac{{\pi – 0}}{4} }={ \frac{\pi }{4}.}$

Calculate the values of the sine function:

${f\left( {{x_0}} \right) = f\left( 0 \right) }={ \sin 0 }={ 0;}$

${f\left( {{x_1}} \right) = f\left( {\frac{\pi }{4}} \right) }={ \sin \frac{\pi }{4} }={ \frac{{\sqrt 2 }}{2};}$

${f\left( {{x_2}} \right) = f\left( {\frac{\pi }{2}} \right) }={ \sin \frac{\pi }{2} }={ 1;}$

${f\left( {{x_3}} \right) = f\left( {\frac{{3\pi }}{4}} \right) }={ \sin \frac{{3\pi }}{4} }={ \frac{{\sqrt 2 }}{2};}$

${f\left( {{x_4}} \right) = f\left( \pi \right) }={ \sin \pi }={ 0.}$

Substituting these values, we find the approximate value of the area:

${A \approx {T_4} }={ \frac{\pi }{8}\left[ {0 + 2 \cdot \frac{{\sqrt 2 }}{2} }\right.}+{\left.{ 2 \cdot 1 + 2 \cdot \frac{{\sqrt 2 }}{2} + 0} \right] }={ \frac{\pi }{8}\left( {2\sqrt 2 + 2} \right) }={ \frac{\pi }{4}\left( {\sqrt 2 + 1} \right) }\approx{ 1.896}$

Integrating the sine function we get the true solution:

${\int\limits_0^\pi {f\left( x \right)dx} }={ \int\limits_0^\pi {\sin xdx} }={ \left[ { – \cos x} \right]_0^\pi }={ – \cos \pi + \cos 0 }={ – \left( { – 1} \right) + 1 }={ 2.}$

Thus, the relative error is

${\left| \varepsilon \right| = \frac{{2 – 1.896}}{2} }={ 0.052 }={ 5.2\%}$

${A \approx 1.896,\;}\kern0pt{\left| \varepsilon \right| = 5.2\%}$