Course Webpage

Exercise

Given the integral

$$ I=\int_{0}^{3}(x^{3}+1)\,dx $$
  1. Approximate its value using the Trapezoidal rule.
  2. Approximate its value using the Simpson's rule.
  3. Compare the approximate values to the exact value. Could you have predicted any of the errors?
  4. How many intervals may guarantee an error lower than $10^{-6}$ using the composite trapezoidal formula?

The exact integral is

$$ I = \int_{0}^{3}\left(x^3+1\right)\,dx=\left[ \frac{x^4}{4}+x\right]_0^3=\frac{3^4}{4}+3=23.25 $$

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)$$

Applying it

$$\int_{0}^{3}f(x)dx\approx \frac{3-0}{2}\left( f\left( 0\right) +f\left( 3\right) \right)=\frac{3}{2}\left( \left( 0^3+1\right) +\left( 3^3+1\right) \right)=\frac{3}{2}\times 29=43.5$$

The absolute error is

$$e_a = \left|I-I_{trap}\right| = \left|23.25-43.5\right|= 20.25$$

Simpson's rule

The Simpson's rule is

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

. $$\int_{0}^{3}f(x)dx\approx \frac{3-0}{6}\left( f\left(0\right) +4f\left( 1.5\right) +f\left( 3\right) \right)=$$ . $$ =\frac{3}{6}\left( \left( 0^3+1\right) +4\left( 1.5^3+1\right) +\left( 3^3+1\right) \right)=23.25$$

An the absolute error

$$e_a = \left|I-I_{Simp}\right| = \left|23.25-23.25\right|= 0$$

Error

It could have been expected that the error would be zero for Simpson's rule because Simpson's degree of precision is 3 and therefore exact for polynomials of degree 3.

Number of intervals

Error of the Trapezoidal rule

Simple

The error for the Trapezoidal rule is $$ E^T = -f^{\prime\prime}(c_o) \frac{(b-a)^3}{12} \quad c_o \in (a,b)$$

Composite

If we split $[a,b]$ into $n$ subintervals of equal length

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

and we apply the Trapezoidal rule in each of them, the error will be the sum of the errors for each of these $n$ subintervals

$$E_h^T = -f^{\prime\prime}(c_1) \frac{h^3}{12}-f^{\prime\prime}(c_2) \frac{h^3}{12}-\dots -f^{\prime\prime}(c_n) \frac{h^3}{12} $$

that is

$$E_h^T = -\frac{h^3}{12}\left(f^{\prime\prime}(c_1) +f^{\prime\prime}(c_2) +\dots +f^{\prime\prime}(c_n) \right) $$

if we multiply and divide by $n$

$$E_h^T = -\frac{n\,h^3}{12}\frac{f^{\prime\prime}(c_1) +f^{\prime\prime}(c_2) +\dots +f^{\prime\prime}(c_n)}{n} $$

From the intermediate value theorem it can be deduced that there is a value of $c\in(a,b)$ so that $f^{\prime\prime}(c)$ is equal to this average that appears in the previous formula (as the average is an intermediate value). So

$$E_h^T = -\frac{n\,h^3}{12}f^{\prime\prime}(c) $$

an due to (1), $nh = b-a$ the error is

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

Approximate $$I=\int_{0}^{3}(x^{3}+1)dx$$ with the Trapezoidal rule with error less than $10^{-6}$


If we use the error in absolute value

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

If we propose

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

then it will be true that

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

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

$$f^{\prime}(x)= 3x^2 \quad \quad \mathrm{y} \quad \quad f^{\prime\prime}(x)= 6x$$

and we have

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

Thus, the error is

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

That is

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

As

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

we have

$$ \frac{9}{2}\left(\frac{3}{n}\right)^2 \lt 10^{-6}$$

or

$$ \frac{81}{2n^2} \lt 10^{-6}$$

and then, 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{81}{2}10^6 \lt n^2 $$

Taking into account that if $h$ is an increasing function

$x_1 \lt x_2 \Longrightarrow h(x_1) \lt h(x_2)$ and $h(x)= \sqrt{x}$ is an increasing function

we have

$$\sqrt{\frac{81}{2}10^6} \lt n $$

or

$$ 6363.96\lt n $$

And taking $\fbox{$n = 6364$}$ we can guarantee that the error is less than $10^{-6}.$

In fact, running a script that approximates this integral with the compound trapezoid rule and 6364 subintervals the results have been:

  • The approximate value is $23.250000499993877$
  • The exact value is $23.25$
  • The error is $5 \times 10^{-7} = 0.5 \times 10^{-6} \lt 10^{-6} $