Difference between revisions of "Numerical Integration"

From Sutherland_wiki
Jump to: navigation, search
m (fix a link)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Introduction ==
 
== 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.
  
== Common Quadrature Formulas ==
+
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 ==
  
 +
[[Image:MidpointRule.png|thumb|150px|right|Schematic illustration of the midpoint rule.  The integral is approximated by a rectangle with the height evaluated at (a+b)/2.]]
 +
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,
 +
:<math>\int_{a}^{b} f(x) \mathrm{d}x \approx (b-a) f\left(\frac{b+a}{2}\right) </math>
 +
This is shown pictorially in the figure to the right.
  
=== Midpoint Rule ===
 
  
==== Example ====
+
=== Example ===
 +
Assume that the following flowrate measurements were taken for a river over a 5-day period.
 +
:{| border="1" cellpadding="3" cellspacing="0" style="text-align:center"
 +
|-
 +
! 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
 +
 
 +
:{| border="1" cellpadding="3" cellspacing="0" style="text-align:center"
 +
! Day
 +
|                  1 ||                2 ||                  3 ||                  4 ||                  5
 +
|-
 +
! Flowrate (ft<sup>3</sup>/day)
 +
| 8.64x10<sup>8</sup> || 1.04<sup>9</sup> || 1.30x10<sup>9</sup> || 1.17x10<sup>9</sup> || 1.24x10<sup>9</sup>
 +
|}
 +
 
 +
[[Image:MidpointExample1.png|thumb|250px|right|Application of the midpoint rule to approximate the total volume of fluid over days 1-5.]]
 +
We want to estimate the total volume of water that flowed through the
 +
river over this 5-day period. To do this, we could use the flowrate on
 +
day 3 (which is the midpoint of the time period) to find
 +
:<math>\mathrm{Total \; volume} \approx (5-1) \cdot f(3) = 4 \cdot 1.04\times 10^9 = 5.18\times 10^{9} \mathrm{ft}^3 </math>
 +
 
 +
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 [[Numerical Integration#Trapezoid Rule|trapezoid rule]] is
 +
most often used when discrete data needs to be integrated.
  
 +
== Trapezoid Rule ==
  
 +
[[Image:TrapezoidRule.png|thumb|150px|right|Schematic of the trapezoid rule, where the function is approximated by a linear function.]]
  
=== 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,
 +
:<math>\int_{a}^{b} \approx \frac{b-a}{2} \left[ f(a)+f(b) \right] </math>
  
==== Example ====
 
  
 +
=== Example ===
  
 +
[[Image:TrapezoidExample1.png|thumb|250px|right|The trapezoid rule used to approximate the total volume over days 1-5]]
 +
If we apply the trapezoidal rule to the example previously, we use the
 +
endpoints of the interval to find
 +
:<math>\mathrm{Total \; volume} \approx \frac{5-1}{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 </math>
  
 +
The trapezoid rule is depicted in the figure to the right.
  
=== Simpson's 1/3 Rule ===
+
== Simpson's 1/3 Rule ==
 +
{{Stub|section}}
  
==== Example ====
+
=== Example ===
  
  
  
  
=== Summary of Common Quadrature Formulas ===
+
== Summary of Common Quadrature Formulas ==
  
 
<center>
 
<center>
Line 53: Line 113:
 
|
 
|
 
* Requires three equally spaced points on the interval <math>[a,b]</math>
 
* Requires three equally spaced points on the interval <math>[a,b]</math>
* On the interval <math>[a,b]</math>, we have <math>\Delta x = \tfrac{b-a}{3}</math> and <math>x_i = a + i \Delta x</math>
+
* On the interval <math>[a,b]</math>, we have <math>\Delta x = \tfrac{b-a}{2}</math> and <math>x_i = a + i \Delta x</math>
 
|}
 
|}
 
</center>
 
</center>
 
 
 
  
 
== Composite Rules: Quadrature ==
 
== Composite Rules: Quadrature ==
 +
{{Stub|section}}
  
 
=== Algorithm ===
 
=== Algorithm ===

Latest revision as of 11:11, 23 August 2010

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

Schematic illustration of the midpoint rule. The integral is approximated by a rectangle with the height evaluated at (a+b)/2.

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 (b-a) 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 5-day 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 (ft3/day) 8.64x108 1.049 1.30x109 1.17x109 1.24x109
Application of the midpoint rule to approximate the total volume of fluid over days 1-5.

We want to estimate the total volume of water that flowed through the river over this 5-day 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 (5-1) \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

Schematic of the trapezoid rule, where the function is approximated by a linear function.

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{b-a}{2} \left[ f(a)+f(b) \right]


Example

The trapezoid rule used to approximate the total volume over days 1-5

If we apply the trapezoidal rule to the example previously, we use the endpoints of the interval to find

\mathrm{Total \; volume} \approx \frac{5-1}{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

Warn.jpg
This section is a stub and needs to be expanded.
If you can provide information or finish this section you're welcome to do so and then remove this message afterwards.

Example

Summary of Common Quadrature Formulas

Name Formula Comments
Midpoint Rule \int_{a}^{b} f(x) \mathrm{d} x \approx (b-a) f\left(\tfrac{b+a}{2}\right)
  • Requires function values at interval midpoints f\left(\tfrac{b+a}{2}\right)
  • Requires equally spaced data.
Trapezoid Rule \int_{a}^{b} f(x) \mathrm{d} x \approx \tfrac{b-a}{2} \left[ f(b)+f(a) \right]
  • Can be applied to arbitrarily spaced data.
  • Convenient for tabulated data.
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]
  • Requires three equally spaced points on the interval [a,b]
  • On the interval [a,b], we have \Delta x = \tfrac{b-a}{2} and x_i = a + i \Delta x

Composite Rules: Quadrature

Warn.jpg
This section is a stub and needs to be expanded.
If you can provide information or finish this section you're welcome to do so and then remove this message afterwards.

Algorithm

Examples

Matlab Tools for Quadrature