Numerical Analysis Home

## Composite Numerical Integration

Approximating $$\displaystyle\int_{a}^{b} f(x) \,dx$$ by quadrature rules like trapezoidal, Simpson's will give large error when the interval $$[a,b]$$ is large. We can modify those rules by using $$n+1$$ points instead of 2 or 3 points. Then the Lagrange polynomial of degree $$n$$ might give large error near the end points for large $$n$$. So we use a composite quadrature rule that breaks $$[a,b]$$ into $$n$$ subintervals $$[x_0,x_1],[x_1,x_2],\ldots,[x_{n-1},x_n]$$ ($$x_i=a+ih$$ and $$h=(b-a)/n$$) and approximates the integral by applying quadrature rules on each subinterval and adding them up: $\int_{a}^{b} f(x) \,dx = \int_{x_0}^{x_1} f(x) \,dx+ \int_{x_1}^{x_2} f(x) \,dx+\cdots+\int_{x_{n-1}}^{x_n} f(x) \,dx.$

Applying trapezoidal rule on each subinterval $$[x_{i-1},x_i]$$, we get \begin{align*} \int_{a}^{b} f(x) \,dx = \sum_{i=1}^n \int_{x_{i-1}}^{x_i} f(x) \,dx &\approx \sum_{i=1}^n h\left( \frac{f(x_{i-1})+f(x_i)}{2} \right)\\ &=\displaystyle\frac{h}{2} \Big[ f(x_0)+2f(x_1)+\cdots+2f(x_{n-1})+f(x_n) \Big]. \end{align*} So the Composite Trapezoidal Rule is $\int_{a}^{b} f(x) \,dx \approx \displaystyle\frac{h}{2} \Big[ f(x_0)+2f(x_1)+\cdots+2f(x_{n-1})+f(x_n) \Big].$ Similarly the Composite Midpoint Rule is $\int_{a}^{b} f(x) \,dx \approx h \sum_{i=1}^n f\left(\frac{x_{i-1}+x_i}{2} \right).$

For the Composite Simpson's Rule, we take even $$n$$ and apply simple Simpson's Rule to the subintervals $$[x_{0},x_{2}],[x_{2},x_{4}],\ldots,[x_{n-2},x_{n}]$$: \begin{align*} \int_{a}^{b} f(x) \,dx &= \sum_{i=1}^{n/2} \int_{x_{2i-2}}^{x_{2i}} f(x) \,dx\\ &\approx \sum_{i=1}^{n/2} \frac{2h}{6}\bigg[ f(x_{2i-2})+4f(x_{2i-1})+f(x_{2i}) \bigg]\\ &= \frac{h}{3} \bigg[ \scriptstyle{\Big( f(x_0)+4f(x_1)+f(x_2) \Big) + \Big( f(x_2)+4f(x_3)+f(x_4) \Big) + \cdots+ \Big( f(x_{n-2})+4f(x_{n-1})+f(x_n) \Big) } \bigg]\\ &= \frac{h}{3} \bigg[ \scriptstyle{f(x_0)+f(x_n) + 4\Big( f(x_1)+f(x_3)+\cdots+f(x_{n-1}) \Big) + 2\Big( f(x_2)+f(x_4)+\cdots+f(x_{n-2}) \Big) } \bigg]\\ &= \frac{h}{3}\left[ f(x_0)+f(x_n)+ 4\sum_{i=1}^{n/2} f(x_{2i-1})+ 2\sum_{i=1}^{(n-2)/2} f(x_{2i}) \right] \end{align*}

Example. Approximate $$\displaystyle\int_{0}^2 e^x\,dx$$ using $$4$$ subintervals in (a) Composite Trapezoidal Rule, (b) Composite Midpoint Rule, (c) Composite Simpson's Rule.

Solution. First of all let's find the exact integral: $$\displaystyle\int_{0}^2 e^x\,dx= e^x \Big]_0^2=e^2-1 \approx 6.389.$$
$$n=4\implies h=(2-0)/4=0.5$$ and the 4 subintervals are $$[0,0.5],\; [0.5,1],\; [1,1.5],\; [1.5,2]$$. \begin{align*} \text{CTR}:\; \int_{0}^2 e^x\,dx &\approx \frac{0.5}{2}\Big[ e^0+2e^{0.5}+2e^{1}+2e^{1.5}+e^{2} \Big]=6.52\\ \text{CMR}:\; \int_{0}^2 e^x\,dx &\approx 0.5\Big[ e^{0.25}+e^{0.75}+e^{1.25}+e^{1.75} \Big]=6.32\\ \text{CSR}:\; \int_{0}^2 e^x\,dx &\approx \frac{0.5}{3}\Big[ e^0+4e^{0.5}+2e^{1}+4e^{1.5}+e^{2} \Big]= 6.39 \end{align*}

The error in the composite trapezoidal rule (using $$n$$ subintervals) is given by $E_{T_n}=-\sum_{i=1}^n f''(c_i)\frac{(x_i-x_{i-1})^3}{12} =-\frac{h^3}{12} \sum_{i=1}^n f''(c_i).$ Assuming continuity of $$f''$$ on $$(a,b)$$, by the IVT we can find $$c\in (a,b)$$ such that $\frac{1}{n}\sum_{i=1}^n f''(c_i)=f''(c).$ Thus $$\sum_{i=1}^n f''(c_i)=nf''(c)$$ and then $E_{T_n}=-\frac{nh^3}{12} f''(c).$ Note that $$n=(b-a)/h$$. Then the error for the composite trapezoidal rule becomes: $\boxed{E_{T_n}=-\frac{(b-a)}{12} h^2 f''(c) }$ Similarly we get errors in the composite midpoint and Simpson's rule: $\boxed{E_{M_n}=\frac{(b-a)}{24} h^2 f''(c) } \;\;\;\;\;\; \boxed{E_{S_n}=-\frac{(b-a)}{180} h^4 f^{(4)}(c) }$ Note that since errors are $$O(h^2)$$ and $$O(h^4)$$, small step sizes lead to more accurate integral.

Example. Find the step size $$h$$ and the number of subintervals $$n$$ required to approximate $$\displaystyle\int_{0}^2 e^x\,dx$$ correct within $$10^{-2}$$ using (a) Composite Trapezoidal Rule, (b) Composite Midpoint Rule, (c) Composite Simpson's Rule.

Solution. Note $$f''(x)=f^{(4)}(x)=e^x$$ which have the maximum absolute value $$e^2$$ on $$[0,2]$$. \begin{align*} & |E_{T_n}|=\Big|-\frac{(b-a)}{12} h^2 f''(c)\Big|\leq \frac{(b-a)}{12} h^2 \cdot \max_{[0,2]}| f''(x)| = \frac{(2-0)}{12} \left(\frac{2-0}{n} \right)^2 \cdot e^2 < 10^{-2}\\ \implies & n> \sqrt{200e^2/3}=22.19 \end{align*} Thus for the CTR we need $$n=23$$ and $$h=(2-0)/23=2/23 \approx 0.087$$.
Similarly for the CMR we need $$n=16$$ and $$h=(2-0)/16=0.125$$, and for the CSR we need $$n=4$$ and $$h=(2-0)/4=0.5$$.

Last edited