# Calculus: Integrals II

## Midpoint Method

Left and right Riemann sums are handy thanks to their easy formulation and calculation, but they suffer from a noticeable problem: the error caused by underestimating or overestimating the integral. While using more rectangles to estimate the value under the curve may be nice, this can be a pain to do out by hand. Computers can easily solve a single integral one time by just adding more samples, but many applications require many integrals to be solved quite quickly, and users don't like waiting around for their work to process. Wouldn't it be great if we could reduce the error in a way that didn't involve adding more triangles?

Good news - there is! You may have thought of it yourself, even before seeing the title of this section. Rather than anchor each rectangle to the function by its top left or right corner, anchor it in the middle. This way, the amount under-estimated on one side might be offset by an amount over-estimated on the other. As a matter of fact, the midpoint method is generally more accurate, a property that can be demonstrated mathematically. So handy is this technique that it has its own name - the midpoint method. (Deriving error bounds, which quantify the accuracy of estimates such as Riemann sums, is left to a later section.)

Here's the formula for estimating an integral using the midpoint method:

$$\int\limits_{a}^{b} f(x) \, dx \approx \sum\limits_{i=0}^{N-1} f(a + \Delta x(i+0.5)) \, \Delta x$$

Notice that the $(i+0.5)$ term anchors the rectangle halfway (at this midpoint) between the left and right sides of the region. See the following picture for a nice visualization of the approach:

## Problems

1. Estimate $\displaystyle\int\limits_{0}^{2} 4x + 5 \, dx$   where   $N=4$

Step 1: Calculate $\Delta x$

$\Delta x = \dfrac{b - a}{N} \\ \Delta x = \dfrac{2-0}{4} \\ \Delta x = \dfrac{1}{2} \\$

Step 2: Calculate sum:

$\displaystyle\int\limits_{0}^{2} 4x + 5 \, dx \approx \displaystyle\sum\limits_{i=0}^{N-1} f(0+(i+0.5)\cdot\Delta x) \, \Delta x \\ \displaystyle\int\limits_{0}^{2} 4x + 5 \, dx \approx \Delta x \displaystyle\sum\limits_{i=0}^{3} f((i+0.5)\cdot\Delta x) \\ \displaystyle\int\limits_{0}^{2} 4x + 5 \, dx \approx \dfrac{1}{2} \left( \left(4\dfrac{1}{4} + 5\right) + \left(4\dfrac{3}{4} + 5\right) + \left(4\dfrac{5}{4} + 5\right) + \left( 4\dfrac{7}{4} + 5 \right) \right) \\ \displaystyle\int\limits_{0}^{2} 4x + 5 \, dx \approx \dfrac{1}{2} \left( 6 + 8 + 10 + 12 \right) \\ \displaystyle\int\limits_{0}^{2} 4x + 5 \, dx \approx 18 \\$
2. Estimate $\displaystyle\int\limits_{-1}^{1} x^2 \, dx$   where   $N=5$

Step 1: Calculate $\Delta x$

$\Delta x = \dfrac{b - a}{N} \\ \Delta x = \dfrac{1-(-1)}{5} \\ \Delta x = \dfrac{2}{5} \\$

Step 2: Calculate sum:

$\displaystyle\int\limits_{-1}^{1} x^2 \, dx \approx \displaystyle\sum\limits_{i=0}^{N-1} f(-1 + (i+0.5)\cdot\Delta x) \, \Delta x \\ \displaystyle\int\limits_{-1}^{1} x^2 \, dx \approx \Delta x \displaystyle\sum\limits_{i=0}^{4} f(-1 + (i+0.5)\cdot\Delta x) \\ \displaystyle\int\limits_{-1}^{1} x^2 \, dx \approx \dfrac{2}{5} \left(\left(-\dfrac{4}{5}\right)^2 + \left(\dfrac{-2}{5}\right)^2 + (0)^2 + \left(\dfrac{2}{5}\right)^2 + \left(\dfrac{4}{5}\right)^2 \right) \\ \displaystyle\int\limits_{-1}^{1} x^2 \, dx \approx \dfrac{2}{5} \left( \dfrac{16}{25} + \dfrac{4}{25} + 0 + \dfrac{4}{25}+ \dfrac{16}{25} \right) \\ \displaystyle\int\limits_{-1}^{1} x^2 \, dx \approx \dfrac{2}{5} \left( \dfrac{40}{25} \right) \\ \displaystyle\int\limits_{-1}^{1} x^2 \, dx \approx \dfrac{16}{25} \\$

3. Estimate $\displaystyle\int\limits_{0}^{\pi} \sin(x) \, dx$   where   $N=4$

Step 1: Calculate $\Delta x$

$\Delta x = \dfrac{b - a}{N} \\ \Delta x = \dfrac{\pi-0}{4} \\ \Delta x = \dfrac{\pi}{4} \\$

Step 2: Calculate sum:

$\int\limits_{0}^{\pi} \sin(x) \, dx \approx \displaystyle\sum\limits_{i=0}^{N-1} f(-1 + (i+0.5)\cdot\Delta x) \, \Delta x \\ \displaystyle\int\limits_{0}^{\pi} \sin(x) \, dx \approx \displaystyle\sum\limits_{i=0}^{3} f(0 + (i+0.5)\cdot\Delta x) \\ \displaystyle\int\limits_{0}^{\pi} \sin(x) \, dx \approx \dfrac{\pi}{4} \left(\sin\left(\dfrac{\pi}{8}\right) + \sin\left(\dfrac{3\pi}{8}\right) + \sin\left(\dfrac{5\pi}{8}\right) + \sin\left(\dfrac{7\pi}{8}\right) \right) \\ \displaystyle\int\limits_{0}^{\pi} \sin(x) \, dx \approx \dfrac{\pi}{4} \left( \dfrac{\sqrt{2-\sqrt{2}}}{2} + \dfrac{\sqrt{2+\sqrt{2}}}{2} + \dfrac{\sqrt{2-\sqrt{2}}}{2} + \dfrac{\sqrt{2-\sqrt{2}}}{2} \right) \\ \displaystyle\int\limits_{0}^{\pi} \sin(x) \, dx \approx \dfrac{\pi}{4} \left( \sqrt{2-\sqrt{2}} + \sqrt{2+\sqrt{2}} \right) \\$
4. Estimate $\displaystyle\int\limits_{0}^{2\pi} \cos(2\theta) \, d\theta$   where   $N=8$

Step 1: Calculate $\Delta \theta$

$\Delta \theta = \dfrac{b - a}{N} \\ \Delta \theta = \dfrac{2\pi - 0}{8} \\ \Delta \theta = \dfrac{\pi}{4} \\$

Step 3: Calculate sum:

$\displaystyle\int\limits_{0}^{2\pi} \cos(2\theta) \, d\theta \approx \displaystyle\sum\limits_{i=0}^{N-1} f(0 + (i+0.5)*\Delta \theta) \Delta \theta \\ \displaystyle\int\limits_{0}^{2\pi} \cos(2\theta) \, d\theta \approx \Delta \displaystyle\sum\limits_{i=0}^{7} f(0 + (i+0.5)*\Delta \theta) \\ \phantom{0} \\ \displaystyle\int\limits_{0}^{2\pi} \cos(2\theta) \, d\theta \approx \dfrac{\pi}{4} \left( \cos\left(2\cdot\dfrac{\pi}{8}\right) + \cos\left(2\dfrac{3\pi}{8}\right) + \cos\left(2\dfrac{5\pi}{8}\right) + \cos\left(2\dfrac{7\pi}{8}\right) + \\ \cos\left(2\dfrac{9}{8}\right) + \cos\left(2\dfrac{11\pi}{8}\right) + \cos\left(2\dfrac{13\pi}{8}\right) + \cos\left(2\dfrac{15\pi}{8}\right) \right) \\ \phantom{0} \\ \displaystyle\int\limits_{0}^{2\pi} \cos(2\theta) \, d\theta \approx \dfrac{\pi}{4} \left( \cos\left(\dfrac{\pi}{4}\right) + \cos\left(\dfrac{3\pi}{4}\right) + \cos\left(\dfrac{5}{4}\right) + \cos\left(\dfrac{7\pi}{4}\right) + \\ \cos\left(\dfrac{9}{4}\right) + \cos\left(\dfrac{11\pi}{4}\right) + \cos\left(\dfrac{13\pi}{4}\right) + \cos\left(\dfrac{15\pi}{4}\right) \right) \\ \phantom{0} \\ \displaystyle\int\limits_{0}^{2\pi} \cos(2\theta) \, d\theta \approx \dfrac{\pi}{4} \left( \dfrac{\sqrt{2}}{2} - \dfrac{\sqrt{2}}{2} - \dfrac{\sqrt{2}}{2} + \dfrac{\sqrt{2}}{2} + \dfrac{\sqrt{2}}{2} - \dfrac{\sqrt{2}}{2} - \dfrac{\sqrt{2}}{2} + \dfrac{\sqrt{2}}{2} \right) \\ \displaystyle\int\limits_{0}^{2\pi} \cos(2\theta) \, d\theta \approx \dfrac{\pi}{4} ( 0 ) \\ \displaystyle\int\limits_{0}^{2\pi} \cos(2\theta) \, d\theta \approx 0$

5. Estimate $\displaystyle\int\limits_{-2}^{2} x^3 + 2x\, dx$   where   $N=7$

Step 1: Calculate $\Delta x$

$\Delta x = \dfrac{b - a}{N} \\ \Delta x = \dfrac{2-(-2)}{7} \\ \Delta x = \dfrac{4}{7} \\$

Step 2: Calculate sum:

$\displaystyle\int\limits_{-2}^{2} x^3 + 2x \, dx \approx \displaystyle\sum\limits_{i=0}^{N-1} f(-2+(i+0.5)\cdot\Delta x) \, \Delta x \\ \displaystyle\int\limits_{-2}^{2} x^3 + 2x \, dx \approx \Delta x \sum\limits_{i=0}^{6} f(-2+(i+0.5)\cdot\Delta x) \\ \phantom{0} \\ \displaystyle\int\limits_{-2}^{2} x^3 + 2x \, dx \approx \dfrac{4}{7} \left( \left( \left(\dfrac{-12}{7}\right)^3 + 2\dfrac{-12}{7} \right) + \left( \left(\dfrac{-8}{7}\right)^3 + 2\dfrac{-8}{7} \right) + \left( \left(\dfrac{-4}{7}\right)^3 + 2\dfrac{-4}{7} \right) + \\ \left( 0^3 + 2\cdot0 \right) + \left( \left(\dfrac{4}{7}\right)^3 + 2\dfrac{4}{7} \right) + \left( \left(\dfrac{8}{7}\right)^3 + 2\dfrac{8}{7} \right) + \\ \left( \left(\dfrac{12}{7}\right)^3 + 2\dfrac{12}{7} \right) \right) \\ \phantom{0} \\ \displaystyle\int\limits_{-2}^{2} x^3 + 2x \, dx \approx \dfrac{4}{7} \left( \left( \left(\dfrac{-12}{7}\right)^3 + 2\dfrac{-12}{7} \right) + \left( \left(\dfrac{-8}{7}\right)^3 + 2\dfrac{-8}{7} \right) + \left( \left(\dfrac{-4}{7}\right)^3 + 2\dfrac{-4}{7} \right) + \\ \left( \left(\dfrac{4}{7}\right)^3 + 2\dfrac{4}{7} \right) + \left( \left(\dfrac{8}{7}\right)^3 + 2\dfrac{8}{7} \right) + \left( \left(\dfrac{12}{7}\right)^3 + 2\dfrac{12}{7} \right) \right) \\$

Rather than calculate this all out, observe that there's a great deal of symmetry here. Notice that each positive term is negated by a corresponding negative term.

$\displaystyle\int\limits_{-2}^{2} x^3 + 2x \, dx \approx \dfrac{4}{7}(0) \\ \displaystyle\int\limits_{-2}^{2} x^3 + 2x \, dx \approx 0$
6. Estimate $\displaystyle\int\limits_{1}^{2} \dfrac{2}{x} \, dx$   where   $N = 5$

A calculator may be of service for this problem.

Step 1: Calculate $\Delta x$

$\Delta x = \dfrac{b - a}{N} \\ \Delta x = \dfrac{2-1}{5} \\ \Delta x = \dfrac{1}{5} \\$

Step 2: Calculate sum:

$\displaystyle\int\limits_{1}^{2} \dfrac{2}{x} \, dx \approx \sum\limits_{i=0}^{N-1} f(1 + (i+0.5)\Delta x) \, \Delta x \\ \displaystyle\int\limits_{1}^{2} \dfrac{2}{x} \, dx \approx \Delta x \sum\limits_{i=0}^{4} f(1 + (i+0.5)\Delta x) \\ \phantom{0} \\ \displaystyle\int\limits_{1}^{2} \dfrac{2}{x} \, dx \approx \dfrac{1}{5} \left( \dfrac{2}{1+\frac{1}{10}} + \dfrac{2}{1+\frac{3}{10}} + \dfrac{2}{1+\frac{5}{10}} + \dfrac{2}{1+\frac{7}{10}} + \dfrac{2}{1+\frac{9}{10}} \right) \\ \phantom{0} \\ \displaystyle\int\limits_{1}^{2} \dfrac{2}{x} \, dx \approx \dfrac{1}{5} \left( \dfrac{20}{11} + \dfrac{20}{13} + \dfrac{20}{15} + \dfrac{20}{17} + \dfrac{20}{19} \right) \\ \phantom{0} \\ \displaystyle\int\limits_{1}^{2} \dfrac{2}{x} \, dx \approx \dfrac{1}{5} \left( \dfrac{958756}{138567} \right) \\ \phantom{0} \\ \displaystyle\int\limits_{1}^{2} \dfrac{2}{x} \, dx \approx \dfrac{958756}{692835} \\$

7. Estimate $\displaystyle\int_{-4}^{-1} 3x^4 + 7x + 2 \, dx$   where   $N=6$

A calculator may be of service for this problem.
Step 1: Calculate $\Delta x$

$\Delta x = \dfrac{b - a}{N} \\ \Delta x = \dfrac{-1-(-4)}{6} \\ \Delta x = \dfrac{3}{6} \\ \Delta x = \dfrac{1}{2} \\$

Step 2: Calculate sum:

$\displaystyle\int_{-4}^{-1} 3x^4 + 7x + 2 \, dx \approx \sum\limits_{i=0}^{N-1} f(-4+(i+0.5)*\Delta x) \, \Delta x \\ \displaystyle\int_{-4}^{-1} 3x^4 + 7x + 2 \, dx \approx \Delta x \sum\limits_{i=0}^{5} f(-4+(i+0.5)*\Delta x) \\ \phantom{0} \\ \displaystyle\int_{-4}^{-1} 3x^4 + 7x + 2 \, dx \approx \dfrac{1}{2} \left( \left( 3\left(\dfrac{-15}{4}\right)^4 + 7\left(\dfrac{-15}{4}\right) + 2 \right) + \left( 3\left(\dfrac{-13}{4}\right)^4 + 7\left(\dfrac{-13}{4}\right) + 2 \right) + \\ \left( 3\left(\dfrac{-11}{4}\right)^4 + 7\left(\dfrac{-11}{4}\right) + 2 \right) + \left( 3\left(\dfrac{-9}{4}\right)^4 + 7\left(\dfrac{-9}{4}\right) + 2 \right) + \\ \left( 3 \left(\dfrac{-7}{4}\right)^4 + 7 \left(\dfrac{-7}{4}\right) + 2 \right) + \left( 3\left(\dfrac{-5}{4}\right)^4 + 7\left(\dfrac{-5}{4}\right) + 2 \right) \right) \\ \phantom{0} \\ \displaystyle\int_{-4}^{-1} 3x^4 + 7x + 2 \, dx \approx \dfrac{1}{2} \left( \left( \dfrac{151875}{256} - \dfrac{105}{4} + 2 \right) + \left( \dfrac{85683}{256}-\dfrac{91}{4} + 2 \right) + \left( \dfrac{58564}{256} - \dfrac{77}{4} + 2 \right) + \\ \left( \dfrac{19683}{256} - \dfrac{63}{4} + 2 \right) + \left( \dfrac{7203}{256} - \dfrac{49}{4} + 2 \right) + \left( \dfrac{1875}{256} - \dfrac{35}{2} + 2 \right) \right) \\ \phantom{0} \\ \displaystyle\int_{-4}^{-1} 3x^4 + 7x + 2 \, dx \approx \dfrac{1}{2} \left( \dfrac{143217}{128} \right) \\ \phantom{0} \\ \displaystyle\int_{-4}^{-1} 3x^4 + 7x + 2 \, dx \approx \dfrac{143217}{256} \\$
8. Estimate $\displaystyle\int\limits_{0}^{8} 2^{x} \, dx$   where   $N=4$
Step 1: Calculate $\Delta x$

$\Delta x = \dfrac{b - a}{N} \\ \Delta x = \dfrac{8 - 0}{4} \\ \Delta x = 2 \\$

Step 3: Calculate sum:

$\displaystyle\int\limits_{0}^{8} 2^{x} \, dx \approx \sum\limits_{i=0}^{N-1} f(0 + (i+0.5)*\Delta x) \, \Delta x \\ \displaystyle\int\limits_{0}^{8} 2^{x} \, dx \approx \Delta x \sum\limits_{i=0}^{3} f(0 + (i+0.5)*\Delta x) \\ \phantom{0} \\ \displaystyle\int\limits_{0}^{8} 2^{x} \, dx \approx 2 \left( 2^1 + 2^3 + 2^5 + 2^7 \right) \\ \displaystyle\int\limits_{0}^{8} 2^{x} \, dx \approx \left( 2^2 + 2^4 + 2^6 + 2^8 \right) \\ \phantom{0} \\ \displaystyle\int\limits_{0}^{8} 2^{x} \, dx \approx 340 \\$
9. Estimate $\displaystyle\int\limits_{0}^{8} 2^{x} \, dx$   where   $N=8$
Step 1: Calculate $\Delta x$
$\Delta x = \dfrac{b - a}{N} \\ \Delta x = \dfrac{8 - 0}{8} \\ \Delta x = 1 \\$

Step 3: Calculate sum:

$\displaystyle\int\limits_{0}^{8} 2^{x} \, dx \approx \sum\limits_{i=0}^{N-1} f(0 + (i+0.5)*\Delta x) \, \Delta x \\ \displaystyle\int\limits_{0}^{8} 2^{x} \, dx \approx \Delta x \sum\limits_{i=0}^{7} f(0 + (i+0.5)*\Delta x) \\ \phantom{0} \\ \displaystyle\int\limits_{0}^{8} 2^{x} \, dx \approx 1 \left( 2^{1/2} + 2^{3/2} + 2^{5/3} + 2^{7/2} + 2^{9/2} + 2^{11/2} + 2^{13/2} + 2^{15/2} \right) \\ \displaystyle\int\limits_{0}^{8} 2^{x} \, dx \approx 2^{1/2} + 2^1\cdot2^{1/2} + 2^2\cdot2^{1/2} + 2^3\cdot2^{1/2} + 2^4\cdot2^{1/2} + 2^5\cdot2^{1/2} + 2^6\cdot2^{1/2} + 2^7\cdot2^{1/2} \\ \displaystyle\int\limits_{0}^{8} 2^{x} \, dx \approx \sqrt{2} + 2\sqrt{2} + 4\sqrt{2} + 8\sqrt{2} + + 16\sqrt{2} + + 32\sqrt{2} + + 64\sqrt{2} + 128\sqrt{2} \\ \phantom{0} \\ \displaystyle\int\limits_{0}^{8} 2^{x} \, dx \approx 255\sqrt{2} \\$
10. Estimate $\displaystyle\int\limits_{a}^{b} C \, dx$   where   $N=N_{0} \geq 1$.

Based on what you know about geometry, what is the exact solution? Does the midpoint method produce an exact result?

Step 1: Calculate $\Delta x$

$\Delta x = \dfrac{b - a}{N} \\ \Delta x = \dfrac{b - a}{N_{0}} \\$

Step 2: Calculate sum:

$\displaystyle\int\limits_{a}^{b} C \, dx \approx \sum\limits_{i=1}^{N} C \, \Delta x \\ \approx \Delta x C \sum\limits_{i=1}^{N_0} 1 \\ \phantom{0} \\ \approx \dfrac{b-a}{N_0} C \left( N_{0} \right) \\ \phantom{0} \\ \approx C(b - a) \\$

The graph is a rectangle, and geometry tells us that the area of a rectangle is $\text{width}*\text{height}$. Here, the height of the rectangle is $C$ and the width is $b-a$. We can see that the result of the Riemann sum is exact:

$\displaystyle\int\limits_{a}^{b} C \, dx = \sum\limits_{i=1}^{N_0} C \, \Delta x = C(b-a) \\$

This shouldn't be surprising. The midpoint method uses little rectangles to estimate the area under a curve. In this case, however, the curve being split up is itself a rectangle.