# 5.6 | Numerical Integration

The definite integral of $$f(x)$$ on $$[a,b]$$ is denoted
$$\int_a^b f(x) \; dx$$
and informally represents the “area” of the region “bounded” by the graphs of $$y = f(x)$$, there vertical lines $$x=a$$ and $$x =b$$, and the $$x$$-axis.
Right Rectangular Rule If $$f(x)$$ is continuous on $$[a,b]$$,
$$\int_a^b f(x) \; dx \approx \sum_{k = 1}^n f(a+k \Delta x) \Delta x$$
and
$$\int_a^b f(x) \; dx =\lim_{n \rightarrow \infty} \sum_{k = 1}^n f(a+k \Delta x) \Delta x$$
where $$\Delta x = \frac{b-a}{n}.$$
Left Rectangular Rule If $$f(x)$$ is continuous on $$[a,b]$$,
$$\int_a^b f(x) \; dx \approx \sum_{k = 1}^n f(a+(k-1) \Delta x) \Delta x$$
and
$$\int_a^b f(x) \; dx =\lim_{n \rightarrow \infty} \sum_{k = 1}^n f(a+(k-1) \Delta x) \Delta x$$
where $$\Delta x = \frac{b-a}{n}.$$
Midpoint Rule If $$f(x)$$ is continuous on $$[a,b]$$,
$$\int_a^b f(x) \; dx \approx \sum_{k = 1}^n f\left(a+\left(k-\frac{1}{2} \right) \Delta x \right) \Delta x$$
and
$$\int_a^b f(x) \; dx =\lim_{n \rightarrow \infty} \sum_{k = 1}^n f\left(a+\left(k-\frac{1}{2}\right) \Delta x \right) \Delta x$$
where $$\Delta x = \frac{b-a}{n}.$$
Trapezoidal Rule If $$f(x)$$ is continuous on $$[a,b]$$,
\begin{aligned} \int_a^b f(x) \; dx & \approx \sum_{k = 1}^n \frac{f(a+k \Delta x)+f(a + (k-1) \Delta x)}{2} \Delta x \\ & = \frac{\Delta x}{2} [ f(x_0) + 2 f(x_1) + \cdots + 2 f(x_{n-1}) + f(x_n)], \end{aligned}
where $$\Delta x = (b-a)/n$$ and $$x_i = a+ i \Delta x,$$ for $$0 \leq i \leq n$$
and
$$\int_a^b f(x) \; dx =\lim_{n \rightarrow \infty} \sum_{k = 1}^n \frac{f(a+k \Delta x)+f(a + (k-1) \Delta x)}{2} \Delta x$$
where $$\Delta x = \frac{b-a}{n}.$$
Error Bound for the Trapezoidal Rule:
If $$f^{\prime \prime}$$ is continuous on $$[a,b],$$ then the error $$E_n$$ in approximating $$\int_a^b f(x) \; dx$$ by the Trapezoidal Rule satisfies
$$|E_n| \leq \frac{M(b-a)^3}{12n^2}$$
where $$M$$ is a positive number such that $$|f^{\prime \prime}(x)| \leq M$$ for all $$x$$ in $$[a,b]$$.
Simpson’s Rule If $$f(x)$$ is continuous on $$[a,b]$$ and $$n$$ is even,
\begin{aligned} \int_a^b f(x) \; dx & \approx \sum _{k=1}^{n/2} \left( \frac{f(a+(2k-2) \Delta x) +4 f(a+(2 k-1)\Delta x )+f(a+2 k \Delta x )}{3} \right) \Delta x \\ & = \frac{\Delta x}{3}[f(x_0) + 4f(x_1) + 2f(x_2) + 4f(x_3) + \cdots + 4f(x_{n-1}) + f(x_n)] \end{aligned}
and
\begin{aligned} \int_a^b f(x) \; dx & =\lim_{n \rightarrow \infty} \sum _{k=1}^{n/2} \left( \frac{f(a+(2k-2) \Delta x) +4 f(a+(2 k-1)\Delta x )+f(a+2 k \Delta x )}{3} \right) \Delta x \\ & =\lim_{n \rightarrow \infty} \frac{\Delta x}{3}[f(x_0) + 4f(x_1) + 2f(x_2) + 4f(x_3) + \cdots + 4f(x_{n-1}) + f(x_n)] \end{aligned}
where $$\Delta x = \frac{b-a}{n}.$$
Error Bound for Simpson’s Rule
If $$f^{(4)}$$ is continuous on $$[a,b],$$ then the error $$E_n$$ in approximating $$\int_a^b f(x) \; dx$$ by Simpson’s Rule satisfies
$$|E_n| \leq \frac{M(b-a)^5}{180n^4}$$
where $$M$$ is a positive number such that $$|f^{(4)}(x)| \leq M$$ for all $$x$$ in $$[a,b].$$

Use the right rectangular rule, left rectangular rule, and midpoint rule to approximate
$$\int_{-1}^2 x \sin x +2 \; dx$$
using 4 rectangles.

• The right rectangular rule (also referred to as a right Riemann sum) with 4 rectangles:
\begin{aligned} \int_{-1}^2 x \sin x +2 \; dx & \approx \sum_{k = 1}^4 f(-1+k \Delta x) \Delta x = \sum_{k = 1}^4 f\left(-1+k \frac{3}{4} \right) \frac{3}{4} \\ &= \sum_{k = 1}^4 f\left(\frac{3k-4}{4} \right) \frac{3}{4} = \frac{3}{4}\sum_{k = 1}^4 f\left(\frac{3k-4}{4} \right) \\ & = \frac{3}{4}\left(f\left(\frac{-1}{4} \right)+ f\left(\frac{1}{2} \right) + f\left(\frac{5}{4} \right) + f\left(2 \right) \right) \\ & \approx 8.47979 \end{aligned}
• The left rectangular rule (also referred to as a left Riemann sum) with 4 rectangles:
\begin{aligned} \int_{-1}^2 x \sin x +2 \; dx & \approx \sum_{k = 1}^4 f(-1+(k-1) \Delta x) \Delta x \\ & = \sum_{k = 1}^4 f\left(-1+(k-1) \frac{3}{4} \right) \frac{3}{4} \\ &= \sum_{k = 1}^4 f\left(\frac{3k-7}{4} \right) \frac{3}{4} = \frac{3}{4}\sum_{k = 1}^4 f\left(\frac{3k-7}{4} \right) \\ & = \frac{3}{4}\left(f\left(-1 \right)+ f\left(\frac{-1}{4} \right) + f\left(\frac{1}{2} \right) + f\left(\frac{5}{4} \right) \right) \\ & \approx 7.74695 \end{aligned}
• The midpoint rule with 4 rectangles:
\begin{aligned} \int_{-1}^2 x \sin x +2 \; dx & \approx \sum_{k = 1}^4 f(-1+(k-1/2) \Delta x) \Delta x \\ & = \sum_{k = 1}^4 f\left(-1+(k-1/2) \frac{3}{4} \right) \frac{3}{4} \\ & = \sum_{k = 1}^4 f\left(\frac{6k-9}{8} \right) \frac{3}{4} = \frac{3}{4}\sum_{k = 1}^4 f\left(\frac{3k-7}{4} \right) \\ & = \frac{3}{4}\left(f\left(-3/8 \right)+ f\left(\frac{3}{8} \right) + f\left(\frac{9}{8} \right) + f\left(\frac{15}{8} \right) \right) \\ & \approx 8.00661 \end{aligned}
Use the trapezoidal rule and Simpson’s rule to approximate
$$\int_{-1}^2 x \sin x +2 \; dx$$
using 4 trapezoids and 2 parabolas, respectively.

• The trapezoidal rule with 4 trapezoids:
\begin{aligned} \int_{-1}^2 x \sin x +2 \; dx & \approx \sum_{k = 1}^4 \frac{f\left(-1+k \frac{3}{4}\right)+f \left(-1 + (k-1) \frac{3}{4} \right)}{2} \frac{3}{4} \\ & = \sum_{k = 1}^4 \frac{f\left(\frac{3k-4}{4}\right)+f \left(\frac{3k-7}{4} \right)}{2} \frac{3}{4} \\ & = \frac{3}{8}\sum_{k = 1}^4 \left[f\left(\frac{3k-4}{4}\right)+f \left(\frac{3k-7}{4} \right) \right] \\ & = \frac{3}{8}\left[f \left(-1 \right)+2f \left(\frac{-1}{4} \right)+2f \left(\frac{1}{2} \right)+2f \left(\frac{5}{4} \right) +f\left(2\right)\right] \\ & \approx 8.11337 \end{aligned}
• Simpson’s rule with 2 parabolas:
\begin{aligned} \int_{-1}^2 x \sin x +2 \; dx & \approx \frac{\Delta x}{3}[f(x_0) + 4f(x_1) + 2f(x_2) + 4f(x_3) + f(x_4)] \\ & = \frac{\frac{3}{4}}{3} \left[f\left(-1+0 \cdot \frac{3}{4} \right) + 4 f\left(-1+1 \cdot \frac{3}{4} \right) + \cdots \right. \\ & \quad \left. + f\left(-1+4 \cdot \frac{3}{4} \right) \right] \\ & = \frac{1}{4} \left[f\left(-1\right) + 4 f\left( -\frac{1}{4} \right) + 2f\left(\frac{1}{2}\right) +4f\left(\frac{5}{4}\right) + f\left(2 \right) \right] \\ & \approx 8.03295 \end{aligned}
Use the Trapezoidal Rule to approximate
$$\int_1^2 \frac{x^2}{4} + 1 \; dx$$
with $$n = 4$$. Then find the exact value of the definite integral and find the actual error.

\begin{aligned} \int_1^2 \frac{x^2}{4} + 1 \; dx & = \frac{\Delta x}{2} [ f(x_0) + 2f(x_1) + 2f(x_2) + 2f(x_3) + f(x_4)] \\ & = \frac{1}{8}[f(1) + 2f(5/4)+2f(3/2)+2f(7/4)+f(2)] \\ & \approx \frac{1}{8} [ 1.25 + 2(1.39) + 2(1.56) + 2(1.76) +2] \\ & \approx 1.58 \end{aligned}

$$\int_1^2 \frac{x^2}{4} +1 \; dx = \left( \frac{x^3}{4} +x \right) \Big|_1^2 = 19/12 \approx 1.585333$$

$$|E_4| = |\text{actual} – \text{approx}| = |19/12 – 1.58| = 0.003$$

Find a bound on the error in approximating
$$\int_0^2 x \sqrt{x^2+1} \; dx$$
with $$n = 4$$.

\begin{aligned} f'(x) & = \frac{2 x^2+1}{\sqrt{x^2+1}} \\ f^{\prime \prime}(x) & = \frac{2 x^3+3 x}{\left(x^2+1\right)^{3/2}}\\ f^{\prime \prime \prime}(x) & = \frac{3}{\left(x^2+1\right)^{5/2}} \\ f^{(4)}(x) & = -\frac{15 x}{\left(x^2+1\right)^{7/2}} \end{aligned}

$$M$$ is a bound on $$g(x) = |f^{(4)}(x)|$$ on the interval $$[0,2]$$. From the graph of $$g(x)$$, we see that we can choose $$M = 3.7$$.

The best choice of $$M$$ is $$g(1/\sqrt{6})$$. Find the extreme values of $$g(x)$$ on the interval $$[0,2]$$. The largest of these, in absolute value, will be the best choice for $$M$$.
$$g'(x) = \frac{15 \left(6 x^2-1\right)}{\left(x^2+1\right)^{9/2}}$$
$$g'(x) = 0 \Rightarrow x = \pm 1/\sqrt{6} \Rightarrow x = 1 /\sqrt{6}$$
By the Extreme Value Theorem, the extreme values of $$g(x)$$ occur either at the critical numbers or the endpoints.
\begin{aligned} g(0) & = 0 \\ g(1/\sqrt{6}) & = -\frac{3240}{343 \sqrt{7}} \approx -3.57028 \\ g(2) & = -\frac{6}{25 \sqrt{5}} \approx -0.107331 \end{aligned}

Therefore, the maximum value for $$|g(x)|$$ on $$[0,2]$$ is $$\frac{3240}{343 \sqrt{7}}$$. This is the best choice for $$M$$.

Therefore,
$$|E_n| \leq \frac{M (b-a)^5}{180 n^4} \Rightarrow |E_4| \leq \frac{\frac{3240}{343 \sqrt{7}} 2^5}{180 \cdot 4^4} = \frac{9}{1372 \sqrt{7}} \approx 0.00247936$$