Integration

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Numerical Methods for Civil Engineers

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

We divide the interval

into n equal subintervals each of width x, where

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

panels as shown in Figure 2. In Figure 2, the points

, and

have been between

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.

Figure 2. View of 2 panels.

We have employed the subscript notation that given by

. The integral over the two panels is

From equations (3) and (4), this integral can be approximated by

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

The trapezoidal rule using 3 panels yields


CE311K 4 DCM 2/8/09

The correct answer is 2.0.

Figure 3. Example of Trapezoid Rule with 4 panels.

Simpsons Rule (1/3)


Simpsons rule is a numerical integration technique which is based on the use of parabolic arcs to approximate f(x) instead of the straight lines employed in the trapezoid rule. Even higher order polynomials, such as cubics, can also be used to obtain more accurate results. Consider the integral of a function f(x) over an interval a b

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

This expression can be integrated and simplified to

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

is the average second derivative over the interval. So, we have

Simpsons rule is termed a fourth order method of numerical integration because the error is proportional to .

Example: Demonstrate the use of the Simpsons rule with n = 4 to evaluate

Simpsons rule with n = 4 yields

CE311K

DCM 2/8/09

Figure 5. Example of Simpsons-1/3 Rule with 2 panels.

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

4. Integrate the following function using the Trapezoid Rule with n = 5:

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?

6. How would you begin to numerically approximate the double integral:

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.

, find the true value of the

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

12. Consider the following integral:

(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

14. Evaluate the integral

using Simpsons 1/3 rule with 6 function evaluations.

Compute the error in your result. The exact value of the integral is

CE311K

14

DCM 2/8/09

You might also like