Integration
Integration
Integration
Lecture Notes CE 311K Daene C. McKinney Introduction to Computer Methods Department of Civil, Architectural and Environmental Engineering The University of Texas at Austin
Numerical Integration
Introduction Trapezoid Rule
The primary purpose of numerical integration (or quadrature) is the evaluation of integrals which are either impossible or else very difficult to evaluate analytically. Numerical integration is also essential for the evaluation of integrals of functions available only at discrete points. Such functions often arise in the numerical solution of differential equations or from experimental data taken at discrete intervals. Consider an integrable function f(x) on the interval a b. We wish to evaluate the integral
The function and the division into subintervals are shown in Figure 1. Each of the subintervals will be referred to as a panel. Consider an expanded view of a general region including two
CE311K
DCM 2/8/09
, and
connected by straight lines. These straight lines approximate the function and , and , etc.
Figure 1. Division of interval of integration into a number of panels. Approximating the area of each panel (with endpoints xi-1 and xi) by the area under the straight lines yields
and
CE311K
DCM 2/8/09
Since the true area of each panel has been approximated by the area of a trapezoid, this approximate numerical evaluation of an integral is called the trapezoidal rule. Geometrically, the trapezoidal rule is equivalent to approximating the area of the trapezoid under the straight line connecting the two endpoints of each panel.
CE311K
DCM 2/8/09
By extending equation (6), the trapezoid rule approximation to the integral over the entire interval is
where
and
Reducing x will, in general, provide a more accurate representation of the integral, since a large number of short, connected, straight line segments can better approximate most functions than can a small number of long segments. An estimate of the error from the application of the trapezoidal rule over the interval between a and b is
where have
is the average second derivative over the interval. Using equations (9) and (8), we
The trapezoidal rule is termed a second order method of numerical integration because the error is proportional to .
Example:
Demonstrate the use of the trapezoidal rule with three panels to evaluate
CE311K
DCM 2/8/09
Simpsons 1/3 rule is obtained when a second-order interpolating polynomial is substituted for f(x)
where f2(x) is a second-order Lagrange interpolating polynomial using the three points xi-1, xi, and xi+1
Consider an expanded view of a general region including one panel as shown in Figure 4 where the points f(xi-1), f(xi), and f(xi+1) have been connected by a parabola. This parabola approximates the function f(x) between xi-1 and xi+1.
CE311K
DCM 2/8/09
Figure 4. Two panels for Simpson's rule. Approximating the area of the panel by the area under the parabola yields
The Simpsons rule approximation to the integral over the entire interval is
CE311K
DCM 2/8/09
where f0 = f(x0) = f(a) and fn = f(xn) = f(b). The truncation error from the application of the Simpsons rule over the interval between a and b is
where
Simpsons rule is termed a fourth order method of numerical integration because the error is proportional to .
CE311K
DCM 2/8/09
Multiple Integration
A double integral may be evaluated as an iterated integral; in other words, we may write
where
CE311K
DCM 2/8/09
Now we can evaluate I using any convenient numerical integration formula, say Simpsons rule rule.
Example:
similarly
CE311K
10
DCM 2/8/09
so
Exercises
1. Integrate the following function
(a) analytically (b) Simpsons Rule using n = 4 2. Integrate the following function (a) analytically
and numerically using n = 4 (b) Trapezoid Rule (c) Simpsons Rule. Compute the percent error for both numerical integrations using the analytical value as the true value. 3. Evaluate the integral of the following data using the Trapezoid Rule:
X F(X)
0 1
0.1 7
0.2 4
0.3 3
0.4 5
0.5 2
CE311K
11
DCM 2/8/09
5. (a) What is the advantage or disadvantage of using Simpson's rule rather than the trapezoid rule to numerically integrate a function? (b)What is the major difference between Simpson's rule and the trapezoid rule?
7. Given a set of N concentration measurements Ci at times t, set up the formulas for numerically integrating the following expression using the trapezoid rule:
8. Integration provides a means to compute how much mass enters or leaves a reactor over a specified time period, as in
where
and
are the initial and final times. This formula makes intuitive sense if you recall
the analogy between integration and summation. Thus the integral represents the summation of the product of flow times concentration to give the total mass entering or leaving from If the flow rate is constant, Q can be moved outside the integral. The outflow chemical concentration from a completely mixed reactor is measures as: to .
t, min
10
15
20
30
40
50
60
CE311K
12
DCM 2/8/09
c, mg/m3
10
20
30
40
60
80
70
50
60
For an outflow of Q = 10 m3/min, use Simpsons 1/3 rule to estimate the mass of chemical that exits the reactor from t = 0 to 60 min. Solve the integral using Simpsons rule for the mass entering the reactor. 9. Integrate the function tabulated in the following table using the Trapezoid Rule. X 1.6 1.8 2.0 2.2 2.4 2.6 f(x) 4.953 6.050 7.389 9.025 11.023 13.464 x 2.8 3.0 3.2 3.4 3.6 3.8 f(x) 16.445 20 .086 24.533 29.964 36.598 44.701
If the values in the table are from the exponential function integral and compute the percent error in your integration.
10. Evaluate the following double integral (a) analytically, and (b) using the trapezoid rule with 4 panels.
Compute the percent error in your numerical calculation. 11. (a) Evaluate the following integral analytically. (b) Evaluate the integral numerically using Trapezoid rule, with n = 3 panels (that is, 4 points). (c ) Compute the error between your analytical and approximate results.
CE311K
13
DCM 2/8/09
(a) Evaluate the integral analytically. (b) Evaluate the integral numerically using Simpsons rule, with n = 4 panels (that is, 5 points). (c) Compute the error between your analytical and approximate results. 13. Suppose you are an Architectural Engineer and you are planning to use a large parabolic arch with a shape given by:
where y is the height above the ground and x is in meters. Calculate the total length of the arch by using Simpson's 1/3 rule. (Divide the domain from x=0 to x=30 m into 10 equally spaced intervals.) The total length of the arc is given by
Compute the error in your result. The exact value of the integral is
CE311K
14
DCM 2/8/09