Compute $$\int_{0}^{3}e^{x}dx$$ using five nodes with
As we will calculate the error, we need the exact value.
$$ I =\int_{0}^{3}e^x\,dx = \left(e^x\right)_0^3 = e^3-e^0= 20.0855-1=19.0855$$One way to decrease the error is to divide the interval $\left[ a,b\right]$ into $n$ subintervals, and then, a quadrature formula is used for each of these subintervals. We are then applying a composite formula.
To have 5 nodes with the composite Midpoint rule, we must divide the interval into 5 subintervals, that is, $n = 5$ and then, if $a = 0$ and $b=3$, we have
and then the nodes are
$$\begin{array}{lcl} \bar x_1 & = & a+\dfrac{h}{2} = 0 + 0.3=0.3\\ \bar x_2 & = & \bar x_1 + h = 0.3+0.6 = 0.9\\ \bar x_3 & = & \bar x_2 + h = 0.9+0.6 = 1.5\\ \bar x_4 & = & \bar x_3 + h = 1.5+0.6 = 2.1\\ \bar x_5 & = & \bar x_4 + h = 2.1+0.6 = 2.7\\ \end{array} $$then
$$ \int_a^b f(x) dx =$$. $$= \int_{x_0}^{x_1} f(x) dx+\int_{x_1}^{x_2} f(x) dx+\int_{x_2}^{x_3} f(x) dx+\int_{x_3}^{x_4} f(x) dx+\int_{x_4}^{x_5} f(x) dx\approx$$ . $$\approx hf(\bar x_1)+hf(\bar x_2)+hf(\bar x_3)+hf(\bar x_4)+hf(\bar x_5)=$$ . $$= h(f(\bar x_1)+f(\bar x_2)+f(\bar x_3)+f(\bar x_4)+f(\bar x_5))=$$ . $$= h(f(0.3)+f(0.9)+f(1.5)+f(2.1)+f(2.7))=$$ . $$= 0.6\left( e^{0.3}+e^{0.9}+e^{1.5}+e^{2.1}+e^{2.7}\right)=$$ . $$ = 0.6 \left(1.35+2.46+4.482+8.16614.88 \right)= 18.8022$$
And the error is
$$Error =\left| I-I_{aprox}\right|=19.0855-18.8022=0.2833$$To have 5 nodes with the composite Trapezoidal rule, we must divide the interval into 4 subintervals, that is, $n = 4$ and then, if $a = 0$ and $b=3$, we have
and the nodes are
$$\begin{array}{lcl} x_0 & = & a = 0\\ x_1 & = & x_0 + h = 0 + 0.75 = 0.75\\ x_2 & = & x_1 + h = 0.75+ 0.75 = 1.5\\ x_3 & = & x_2 + h = 1.5 + 0.75 = 2.25\\ x_4 & = & x_3 + h = 2.25+ 0.75 = 3 = b\\ \end{array} $$then
$$\int_a^b f dx =$$. $$=\int_{x_0}^{x_1} f(x) dx+\int_{x_1}^{x_2} f(x) dx+\int_{x_2}^{x_3} f(x) dx+\int_{x_3}^{x_4} f(x) dx\approx$$ . $$\approx\frac{h}{2}(f(x_0)+f(x_1))+\frac{h}{2}(f(x_1)+f(x_2))+\frac{h}{2}(f(x_2)+f(x_3))+\frac{h}{2}(f(x_3)+f(x_4))= $$ . $$=\frac{h}{2}\left(f(x_0)+2(f(x_1)+f(x_2)+f(x_3))+f(x_4)\right)= $$ . $$=\frac{h}{2}\left(f(0)+2(f(0.75)+f(1.5)+f(2.25))+f(3)\right)= $$ . $$=\frac{0.75}{2}\left(e^0+2(e^{0.75}+e^{1.5}+e^{2.25})+e^{3}\right)= $$ . $$=\frac{0.75}{2}\left(1+2(2.117+4.482+9.488)+20.086\right)= 19.9719$$
And the error is
$$Error =\left| I-I_{aprox}\right|=\left|19.0855-19.9719\right|=0.8864$$The Simpson's rule for the interval $[x_0,x_2]$ with midpoint $x_1$ and if the length of the intervals $[x_0,x_1]$ and $[x_1,x_2]$ is $h$
$$\int_{x_0}^{x_2}f(x)dx\approx \frac{x_2-x_0}{6}\left( f\left( x_0\right) +4f\left( x_1\right) +f\left( x_2\right) \right)$$then
$$\int_{x_0}^{x_2}f(x)dx\approx \frac{2h}{6}\left( f\left( x_0\right) +4f\left( x_1\right) +f\left( x_2\right) \right)$$To have 5 nodes with the composite Simpson's rule, we must divide the interval into 4 subintervals, that is, $n = 4$ and then, if $a = 0$ and $b=3$, we have
$$h=\frac{b-a}{n}=\frac{3-0}{4}=0.75$$and the nodes are
$$\begin{array}{lcl} x_0 & = & a = 0\\ x_1 & = & x_0 + h = 0 + 0.75 = 0.75\\ x_2 & = & x_1 + h = 0.75+ 0.75 = 1.5\\ x_3 & = & x_2 + h = 1.5 + 0.75 = 2.25\\ x_4 & = & x_3 + h = 2.25+ 0.75 = 3 = b\\ \end{array} $$then
$$\int_a^b f(x) dx = $$. $$= \int_{x_0}^{x_2} f(x) dx+\int_{x_2}^{x_4} f(x) dx\approx$$ . $$\approx\frac{h}{3}(f(x_0)+4f(x_1)+f(x_2))+\frac{h}{3}(f(x_2)+4f(x_3)+f(x_4))= $$ . $$=\frac{h}{3}\left(f(x_0)+4(f(x_1)+f(x_3))+2f(x_2)+f(x_4)\right)= $$ . $$=\frac{h}{3}\left(f(0)+4(f(0.75)+f(2.25))+2f(1.5)+f(3)\right)= $$ . $$=\frac{0.75}{2}\left(e^0+4(e^{0.75}+e^{2.25})+2e^{1.5}+e^{3}\right)= $$ . $$=\frac{0.75}{2}\left(1+4(2.117+9.488)+2(4.482)+20.086\right)= 19.1170$$
And the error is
$$Error =\left| I-I_{aprox}\right|=\left|19.0855-19.1170\right|=0.0314$$