# Understanding the trapezoidal rule

Walk through an example using the trapezoid rule, then try a couple of practice problems on your own.
By now you know that we can use Riemann sums to approximate the area under a function. Riemann sums use rectangles, which make for some pretty sloppy approximations. But what if we used trapezoids to approximate the area under a function instead?
Key idea: By using trapezoids (aka the "trapezoid rule") we can get more accurate approximations than by using rectangles (aka "Riemann sums").

# An example of the trapezoid rule

Let's check it out by using three trapezoids to approximate the area under the function $f(x) = 3 \ln(x)$ on the interval $[2, 8]$.
Here's how that looks in a diagram when we call the first trapezoid $T_1$, the second trapezoid $T_2$, and the third trapezoid $T_3$:
Recall that the area of a trapezoid is $h \left(\dfrac{b_1 + b_2}{2}\right)$ where $h$ is the height and $b_1$ and $b_2$ are the bases.

## Finding the area of $T_1$

We need to think about the trapezoid as if it's lying sideways.
The height $h$ is the $2$ at the bottom of $T_1$ that spans $x = \greenD 2$ to $x = \maroonD 4$.
The first base $b_1$ is the value of $3 \ln(x)$ at $x = \greenD 2$, which is $3 \ln (\greenD 2)$.
The second base $b_2$ is the value of $3 \ln(x)$ at $x = \maroonD 4$, which is $3 \ln (\maroonD 4)$.
Here's how all of this looks visually:
Let's put this all together to find the area of $T_1$:
$T_1 = h \left(\dfrac{b_1 + b_2}{2}\right)$
$T_1 = 2 \left(\dfrac{3\ln(\greenD2) + 3\ln(\maroonD4)}{2}\right)$
Simplify:
$T_1 = 3(\ln(\greenD 2) + \ln(\maroonD 4))$

## Finding the area of $T_2$

Let's find the height and both of the bases:
$h = 2$
$b_1 = 3 \ln(4)$
$b_2 = 3 \ln(6)$
Plug in and simplify:
$T_2 = 3(\ln(4) + \ln(6))$

## Find the area of $T_3$

$T_3 =$
$T_3 = 3(\ln(6) + \ln(8))$

## Finding the total area approximation

We find the total area by adding up the area of each of the three trapezoids:
$\text{Total area} = T_1 + T_2 + T_3$
$\text{Total area} = 3\big(\ln2+2\ln 4+ 2\ln 6+\ln 8\big)$
You should pause here and walk through the algebra to make sure you understand how we got this!

# Practice problem

Choose the expression that uses four trapezoids to approximate the area under the function $f(x) = 2 \ln(x)$ on the interval $[2, 8]$.
The area of a trapezoid is given by
$\qquad\displaystyle A=\dfrac12\Big(B_1+B_2\Big)\cdot h$
where $~B_1~$ and $~B_2~$ are the lengths of the vertical bases and $~h~$ is the height (which is horizontal in this case).
$\displaystyle T_1=\dfrac12\big(2\ln2+2\ln3.5\big)\cdot \dfrac32=\dfrac32\Big(\ln2+\ln3.5\Big)$
$T_2=\dfrac12\big(2\ln3.5+2\ln5\big)\cdot \dfrac32=\dfrac32\Big(\ln3.5+\ln5\Big)$
$\displaystyle T_3=\dfrac12\big(2\ln5+2\ln6.5\big)\cdot \dfrac32=\dfrac32\Big(\ln5+\ln6.5\Big)$
$\displaystyle T_4=\dfrac12\big(2\ln6.5+2\ln8\big)\cdot \dfrac32=\dfrac32\Big(\ln6.5+\ln8\Big)$
$\dfrac32\ln2~+~3\ln 3.5~+~3\ln 5~+~3\ln 6.5~+~\dfrac32\ln8\,$
Simplify:
$\dfrac32\big(\ln2+2\ln 3.5+ 2\ln 5+2\ln 6.5+\ln 8\big)\,$

# Challenge problem

Choose the expression that uses three trapezoids to approximate the area under the function $f$ on the interval $[-1, 5]$.
$\qquad\displaystyle A=\dfrac12\Big(B_1+B_2\Big)\cdot h$
where $~B_1~$ and $~B_2~$ are the lengths of the vertical bases and $~h~$ is the height (which is horizontal in this problem).
$T_1=\dfrac12\Big(f(-1)+f(1)\Big)\cdot 2=f(-1)+f(1)$
$T_2=\dfrac12\Big(f(1)+f(3)\Big)\cdot 2=f(1)+f(3)$
$T_3=\dfrac12\Big(f(3)+f(5)\Big)\cdot 2=f(3)+f(5)$
$f(-1)+2\cdot f(1)+ 2\cdot f(3)+f(5)\,$