Course Webpage

Exercise

Given the integral

$$ I=\int_{0}^{1}e^{x}dx, $$
  • Approximate its value by the composite Trapezoidal rule with two subintervals.
  • Find an error bound for the error.
  • How many intervals may guarantee an error lower than $10^{-6}$ using the composite trapezoidal formula?

The exact integral is

$$ I = \int_{0}^{1}e^{x}\,dx=\left[ e^x\right]_0^1=e^1-e^0=2.7183-1 = 1.7183 $$

Composite Trapezoidal rule

The Trapezoidal rule is

$$\int_{a}^{b}f(x)dx\approx \frac{b-a}{2}\left( f\left( a\right) +f\left( b\right) \right)$$

For two subintervals

$$h=\frac{b-a}{n}=\frac{1-0}{2}=0.5$$

Let us compute the nodes

$$\begin{array}{lcl} x_0 & = & a = 0\\ x_1 & = & x_0 + h = 0 + 0.5 = 0.5\\ x_2 & = & x_1 + h = 0.5 + 0.5 = 1 = b \end{array} $$
$$I_{trap} = \int_a^b f(x)\, dx =\int_{x_0}^{x_1} f(x) \,dx+\int_{x_1}^{x_2} f(x) \,dx\approx$$

. $$ \approx\frac{h}{2}\left(f(x_0)+f(x_1)\right)+\frac{h}{2}\left(f(x_1)+f(x_2)\right)=\frac{h}{2}\left(f(x_0)+2f(x_1)+f(x_2)\right)$$

If $f(x)=e^x$

$$I_{trap} = \frac{0.5}{2}\left(e^0+2e^{0.5}+e^1\right)=0.25\left(1+2(1.65)+2.72\right)=1.75$$

And the error is

$$e_a = \left|I-I_{trap}\right|= 1.75-1.72=0.03$$

Error bound

The error for the composite Trapezoidal rule is

$$E_h^T=\left|\;f^{\prime\prime}(c)\right| (b-a)\frac{h^2}{12} \quad \mathrm{with} \quad h=\frac{b-a}{n}$$

If $f(x) = e^x$ and $[a,b]=[0,1]$ then

$f^{\prime}(x)= e^x \quad \quad \mathrm{y} \quad \quad f^{\prime\prime}(x)= e^x$

$$\left|\;f^{\prime\prime}(c)\right| = e^c \lt e^1 = e \quad c\in (0,1)$$

Thus

$$ E_h^T = \left|\;f^{\prime\prime}(c)\right| (b-a)\frac{h^2}{12}\lt \frac{e^1}{12}(b-a)h^2 = \frac{e}{12} (1-0) 0.5^2=0.06$$

And, as it was to be expected, the error bound, $0.06$, is greater than the error, $0.03$.

Number of intervals

To approximate $I=\int_{0}^{1}e^{x}dx$ with an error less than $10^{-6}$

If we take the error in absolute value

$$E_h^T =\frac{h^2}{12} (b-a)\left|f^{\prime\prime}(c)\right|$$

We can write

$$\frac{h^2}{12} (b-a)\left|f^{\prime\prime}(c)\right| \lt 10^{-6}$$

and then

$$E_h^T \lt 10^{-6}$$

As

$f^{\prime}(x)= e^x$ y $f^{\prime\prime}(x)= e^x$

$$\left|\;f^{\prime\prime}(c)\right| = e^c \lt e^1 = e \quad c\in (0,1)$$

Then

$$ E_h^T = \left|\;f^{\prime\prime}(c)\right| (b-a)\frac{h^2}{12}\lt \frac{e}{12}(b-a)h^2 = \frac{e}{12} (1-0) h^2 \lt 10^{-6}$$

That is

$$ \frac{e}{12} h^2 \lt 10^{-6}$$

As

$$ h =\frac{b-a}{n}=\frac{1}{n} $$

then $$ \frac{e}{12}\frac{1}{n^2} \lt 10^{-6}$$

and as

$$a\lt b, 0 \lt c \Longrightarrow ac \lt bc$$

multiplying both sides of the inequality by $n^2$ and $10^6$ we have

$$\frac{e}{12}10^6 \lt n^2 $$

And taking into account that if we have an increasing $g$ function

$x_1 \lt x_2 \Longrightarrow g(x_1) \lt g(x_2)$ and as the function $g(x)= \sqrt{x}$ is increasing

we have

$$\sqrt{\frac{e}{12}10^6} \lt n $$

or

$$475.94 \lt n$$

And a sufficient condition for the error to be less than $10^{-6}$ is that $\fbox{$n=476$}$.

In fact, running a script that approximates this integral with the composite Trapezoidal rule and 476 subintervals the results have been:

  • Aproximate value 1.7182824604330484
  • Exact value 1.7182818284590453
  • The error is $6 \times 10^{-7} = 0.6 \times 10^{-6} \lt 10^{-6} $