Skip to main content

Section 7.8 Numerical Integration

In this section, we will discuss some more numerical methods to approximate the definite integrals.

Investigation 7.8.1.

Recall we learned about three methods to approximate the area under the curve back in SectionΒ 5.1: left-endpoint approximation, right-endpoint approximation, and midpoint approximation. Let’s quickly review the left- and right- endpoint approximations.
Let \(f(x) = \sqrt{1 + \sqrt{x}}\) whose graph on \([0,4]\) is shown below.
Figure 7.8.1. Graph of \(f(x) = \sqrt{1 + \sqrt{x}}\)
We want to approximate the area under the curve on \([0,4]\) using the following methods.

(a)

Approximate the shaded area using the left-endpoint approximation with four rectangles.
Hint.
In case you don’t recall how the left-endpoint approximation works, below is the diagram with the rectangles for this approximation method.
Figure 7.8.2. Left-endpoint Approximation of \(f(x) = \sqrt{1 + \sqrt{x}}\)
What is the combined area of the four rectangles?
Solution.
Observe that
\begin{equation*} \Delta x = \frac{4 - 0}{4} = 1 \end{equation*}
Then the left-endpoint approximation with four rectangles is
\begin{align*} L_4 \amp= \Delta x\left(f(0) + f(1) + f(2) + f(3)\right) \\ \amp= 1\cdot 1\cdot\left(1 + 1.414 + 1.554 + 1.653\right) \\ \amp= 5.621 \end{align*}

(b)

Approximate the shaded area using the right-endpoint approximation with four rectangles.
Hint.
In case you don’t recall how the right-endpoint approximation works, below is the diagram with the rectangles for this approximation method.
Figure 7.8.3. Right-endpoint Approximation of \(f(x) = \sqrt{1 + \sqrt{x}}\)
What is the combined area of the four rectangles?
Solution.
Observe that
\begin{equation*} \Delta x = \frac{4 - 0}{4} = 1 \end{equation*}
Then the right-endpoint approximation with four rectangles is
\begin{align*} L_4 \amp= \Delta x\left(f(1) + f(2) + f(3) + f(4)\right) \\ \amp= 1\cdot 1\cdot\left(1.414 + 1.554 + 1.653 + 1.732\right) \\ \amp= 6.353 \end{align*}
In this section, we will learn three more numerical methods to approximate the area under the curve, the midpoint rule, the trapezoidal rule, and the Simpson’s rule. We will use the same function as the example to explore both the rules and the relation between the rules.

Subsection The Midpoint Rule

We have seen the midpoint rule before. This is the same thing as the midpoint approximation we learned back in SectionΒ 5.1, that we want to construct the rectangles whose height is the function value of the midpoint of each subinterval.

Example 7.8.4.

Approximate the shaded area under the curve of \(f(x) = \sqrt{1 + \sqrt{x}}\) on \([0,4]\) with four rectangles using the midpoint rule.
Hint.
In case you don’t recall how the midpoint rule (aka the midpoint approximation) works, below is the diagram with the rectangles for this approximation method.
Figure 7.8.5. Midpoint Rule to Find the Approximation of \(f(x) = \sqrt{1 + \sqrt{x}}\)
What is the combined area of the four rectangles?
Solution.
Observe that
\begin{equation*} \Delta x = \frac{4 - 0}{4} = 1 \end{equation*}
Then the midpoint rule with four rectangles is
\begin{align*} M_4 \amp= \Delta x\left(f\left(\frac{0 + 1}{2}\right) + f\left(\frac{1 + 2}{2}\right) + f\left(\frac{2 + 3}{2}\right) + f\left(\frac{3 + 4}{2}\right)\right) \\ \amp= \Delta x\left(f(0.5) + f(1.5) + f(2.5) + f(3.5)\right) \\ \amp= 1\cdot\left(1.306 + 1.497 + 1.621 + 1.714\right) \\ \amp= 6.138 \end{align*}
Observe that we first find the midpoint of each sub-interval, then find the function outputs of these midpoints as the heights of the rectangles. So we are really finding the midpoints of the inputs, not the outputs.
Make sure you have some sort of formulas on your notes so that you can recall the formula on the exam.

Subsection The Trapezoidal Rule

You may be wondering why we always approximate the area under the curve using rectangles. That is because the area of rectangles can be easily calculated. But the tradeoff here is that the approximation may not be accurate.
If you don’t oppose using another shape to approximate the area under the curve, we can approximate the area using trapezoids. This approximation method will give us a slightly better result compared to the left- and the right- endpoint approximation, but the tradeoff here is that the area of the trapezoids is a bit more complicated to calculate compared to the area of rectangles.
If you don’t recall how to find the area of a trapezoid, the diagram below may jog your memory.
Figure 7.8.7. A trapezoid
\begin{equation*} \text{Area} = \frac{\Delta x}{2}\left(a + b\right) \end{equation*}

Example 7.8.8.

Approximate the shaded area under the curve of \(f(x) = \sqrt{1 + \sqrt{x}}\) on \([0,4]\) with four trapezoids using the trapezoidal rule.
Hint.
To help you visualize the diagram, Richard graphed the function and the four trapezoids.
Figure 7.8.9. Trapezoidal Rule to Find the Approximation of \(f(x) = \sqrt{1 + \sqrt{x}}\)
How do we find the area of each trapezoid and then sum them up?
Solution.
Observe that each trapezoid has the width of \(\Delta x\text{,}\) where
\begin{equation*} \Delta x = \frac{4 - 0}{4} = 1 \end{equation*}
Then the approximation using the trapezoidal rule is
\begin{align*} T_4 \amp= \frac{\Delta x}{2}\left(f(0) + f(1)\right) + \frac{\Delta x}{2}\left(f(1) + f(2)\right) + \frac{\Delta x}{2}\left(f(2) + f(3)\right) + \frac{\Delta x}{2}\left(f(3) + f(4)\right)\\ \amp= \frac{\Delta x}{2}\left(f(0) + 2f(1) + 2f(2) + 2f(3) + f(4)\right) \\ \amp= \frac{1}{2}\left(1 + 2\cdot 1.414 + 2\cdot 1.554 + 2\cdot 1.653 + 1.732\right) \\ \amp= 5.987 \end{align*}
We can summarize the pattern and make it a fancy formula out of it (so we don’t need to keep on drawing trapezoids). Observe that we need to divide \(\Delta x\) by \(2\text{.}\) In addition, we need to multiply all the function values in the middle by \(2\text{,}\) but not to the first and the last function values.
If you are super observant, you may notice that the trapezoidal rule is just the average of the left- and right- endpoint approximation. That is,
\begin{equation*} T_N = \frac{L_N + R_N}{2} \end{equation*}
To demonstrate this idea, we will again look at the same example.
Observe that
\begin{equation*} L_4 = 1\cdot \left(f(0) + f(1) + f(2) + f(3)\right) \end{equation*}
and
\begin{equation*} R_4 = 1\cdot \left(f(1) + f(2) + f(3) + f(4)\right) \end{equation*}
Then
\begin{align*} \frac{L_4 + R_4}{2} \amp= \frac{1}{2}\cdot 1\cdot\left(f(0) + f(1) + f(2) + f(3) + f(1) + f(2) + f(3) + f(4)\right) \\ \amp= \frac{1}{2}\cdot 1\cdot \left(f(0) + 2\cdot f(1) + 2\cdot f(2) + 2\cdot f(3) + f(4)\right) \\ \amp= T_4 \end{align*}

Subsection Simpson’s Rule

This is the most fanciest type of approximation we will learn in this class. In fact, this method is kind of complicated to demonstrate algebraically (not hard, just a lot of work) so Richard will not explain the theorem but just to state the rule below. If you really want to figure out why this rule works the way it does, your textbook includes the derivation.
Simpson’s rule uses parabolas to approximate the area under the curve, providing a more accurate approximation of the area under the curve (but again, the tradeoff is the more complicated formula). We can determine a parabola using three points, so technically we will be constructing back-to-back parabolas to approximate the area.
There are patterns we can observe from Simpson’s rule: we need to divide \(\Delta x\) by \(3\text{.}\) In addition, the coefficient for the first and the last function values is \(1\text{.}\) The coefficients for the middle function values alternate between \(4\) and \(2\text{.}\)

Example 7.8.12.

Approximate the shaded area under the curve of \(f(x) = \sqrt{1 + \sqrt{x}}\) on \([0,4]\) using Simpson’s rule with \(N = 8\text{.}\)
P.S.: Richard will not code the parabolas on the graph as he sucks at coding. He will draw the diagram in class on the board. The goal here is for you to know how to use the formula AND what the output represents.
Solution.
Observe that
\begin{equation*} \Delta = \frac{4 - 0}{8} = \frac{1}{2} \end{equation*}
Then we obtain
\begin{align*} S_8 \amp= \frac{\Delta x}{3}\left(y_0 + 4\cdot y_1 + 2\cdot y_2 + 4\cdot y_3 + 2\cdot y_4 + 4\cdot y_5 + 2\cdot y_6 + 4\cdot y_7 + y_8\right) \\ \amp= \frac{1}{6}\left(1 + 4(1.3066) + 2(1.1412) + 4(1.4916) + 2(1.5538) + 4(1.6066) + 2(1.6529) + 4(1.6944) + 1.7321\right) \\ \amp= 5.9708 \end{align*}
There are certain more relations between the approximation methods we can explore. Given that we are short in time this term, this is where I like to leave it.
What you should get out of this section is to be able to approximate the area under the curve using the midpoint rule, the trapezoidal rule, and Simpson’s rule.