Numerical Integration
Contents
Introduction
Numeric integration is used in two general situations:
 we have discrete data and want to integrate it.
 we have an analytic function that we cannot integrate analytically and want to approximate it numerically.
There are many ways to perform numerical integration. We will consider a few here. These are all based on fitting a polynomial function to data and then using what we know about polynomials to obtain the integral.
Midpoint Rule
The midpoint rule approximates the integral of a function over some interval [a,b] by a constant. The best choice for the constant value in general will be the function value at the midopoint, (a+b)/2. In other words, \[\int_{a}^{b} f(x) \mathrm{d}x \approx (ba) f\left(\frac{b+a}{2}\right) \] This is shown pictorially in the figure to the right.
Example
Assume that the following flowrate measurements were taken for a river over a 5day period.
Day 1 2 3 4 5 Flowrate (CFS) 10000 12000 15000 13500 14400
Here the units of flowrate are in cubic feet per second. To get the units consistent, let's convert this into cubic feet per day by multiplying by the number of seconds per day. Then our data becomes
Day 1 2 3 4 5 Flowrate (ft^{3}/day) 8.64x10^{8} 1.04^{9} 1.30x10^{9} 1.17x10^{9} 1.24x10^{9}
We want to estimate the total volume of water that flowed through the river over this 5day period. To do this, we could use the flowrate on day 3 (which is the midpoint of the time period) to find \[\mathrm{Total \; volume} \approx (51) \cdot f(3) = 4 \cdot 1.04\times 10^9 = 5.18\times 10^{9} \mathrm{ft}^3 \]
The figure to the right shows this pictorially. However, we can see that the midpoint rule significantly overestimates the total volume (e.g. the integral) since day 3 happened to be the day where the flowrate was highest.
NOTE: the midpoint rule is not always useful for application to discrete data. This is because often the data is not really available at a "midpoint." Therefore, the trapezoid rule is most often used when discrete data needs to be integrated.
Trapezoid Rule
The trapezoid rule uses a linear approximation of the function over the interval [a,b], as shown in the figure to the right. The integral of this is the area of the trapezoid, \[\int_{a}^{b} \approx \frac{ba}{2} \left[ f(a)+f(b) \right] \]
Example
If we apply the trapezoidal rule to the example previously, we use the endpoints of the interval to find \[\mathrm{Total \; volume} \approx \frac{51}{2} \left[ f(1) + f(5) \right] = 2 \cdot \left[ 8.64\times 10^{8} + 1.24\times 10^{9} \right] = 4.22\times 10^{9} \; \mathrm{ft}^3 \]
The trapezoid rule is depicted in the figure to the right.
Simpson's 1/3 Rule
Error creating thumbnail: Unable to save thumbnail to destination 

Example
Summary of Common Quadrature Formulas
Name  Formula  Comments 

Midpoint Rule  \(\int_{a}^{b} f(x) \mathrm{d} x \approx (ba) f\left(\tfrac{b+a}{2}\right) \) 

Trapezoid Rule  \(\int_{a}^{b} f(x) \mathrm{d} x \approx \tfrac{ba}{2} \left[ f(b)+f(a) \right] \) 

Simpson's 1/3 Rule  \(\int_a^b f(x) \mathrm d x \approx \tfrac{\Delta x}{3} \left[ f(a) +4f\left(\tfrac{a+b}{2}\right) + f(b) \right] \) 

Composite Rules: Quadrature
Error creating thumbnail: Unable to save thumbnail to destination 
