The average concentration of a substance As was done in Section 19.9, determine the work per- Compute work as described in Sec. 19.9, but use the

19.21 As specified in the following table, a manufactured spherical particle has a density that varies as a function of the distance from its center r = 0: r , mm 0.12 0.24 0.36 0.49 ρ gcm 3 6 5.81 5.14 4.29 3.39 r , mm 0.62 0.79 0.86 0.93 1 ρ gcm 3 2.7 2.19 2.1 2.04 2 Use numerical integration to estimate the particle’s mass in g and average density in gcm 3 . 19.22 As specified in the following table, the earth’s density varies as a function of the distance from its center r ⫽ 0: r , km 1100 1500 2450 3400 3630 ρ gcm 3 13 12.4 12 11.2 9.7 5.7 r , km 4500 5380 6060 6280 6380 ρ gcm 3 5.2 4.7 3.6 3.4 3 Use numerical integration to estimate the earth’s mass in met- ric tonnes and average density in gcm 3 . Develop vertically stacked subplots of top density versus radius, and bottom mass versus radius. Assume that the earth is a perfect sphere. 497 Numerical Integration of Functions CHAPTER OBJECTIVES The primary objective of this chapter is to introduce you to numerical methods for integrating given functions. Specific objectives and topics covered are • Understanding how Richardson extrapolation provides a means to create a more accurate integral estimate by combining two less accurate estimates. • Understanding how Gauss quadrature provides superior integral estimates by picking optimal abscissas at which to evaluate the function. • Knowing how to use MATLAB’s built-in functions quad and quadl to integrate functions.

20.1 INTRODUCTION

In Chap. 19, we noted that functions to be integrated numerically will typically be of two forms: a table of values or a function. The form of the data has an important influence on the approaches that can be used to evaluate the integral. For tabulated information, you are limited by the number of points that are given. In contrast, if the function is available, you can generate as many values of f x as are required to attain acceptable accuracy. At face value, the composite Simpson’s 13 rule might seem to be a reasonable tool for such problems. Although it is certainly adequate for many problems, there are more effi- cient methods that are available. This chapter is devoted to three such techniques, which capitalize on the ability to generate function values to develop efficient schemes for numerical integration. The first technique is based on Richardson extrapolation, which is a method for combining two numerical integral estimates to obtain a third, more accurate value. The computational algorithm for implementing Richardson extrapolation in a highly efficient manner is called Romberg integration. This technique can be used to generate an integral estimate within a prespecified error tolerance. 20 The second method is called Gauss quadrature. Recall that, in Chap. 19, values of f x for the Newton-Cotes formulas were determined at specified values of x. For exam- ple, if we used the trapezoidal rule to determine an integral, we were constrained to take the weighted average of f x at the ends of the interval. Gauss-quadrature formulas employ x values that are positioned between the integration limits in such a manner that a much more accurate integral estimate results. The third approach is called adaptive quadrature. This techniques applies composite Simpson’s 13 rule to subintervals of the integration range in a way that allows error esti- mates to be computed. These error estimates are then used to determine whether more refined estimates are required for a subinterval. In this way, more refined segmentation is only used where it is necessary. Two built-in MATLAB functions that use adaptive quad- rature are illustrated.

20.2 ROMBERG INTEGRATION

Romberg integration is one technique that is designed to attain efficient numerical integrals of functions. It is quite similar to the techniques discussed in Chap. 19 in the sense that it is based on successive application of the trapezoidal rule. However, through mathematical manipulations, superior results are attained for less effort.

20.2.1 Richardson Extrapolation

Techniques are available to improve the results of numerical integration on the basis of the integral estimates themselves. Generally called Richardson extrapolation, these methods use two estimates of an integral to compute a third, more accurate approximation. The estimate and the error associated with the composite trapezoidal rule can be rep- resented generally as I = I h + Eh where I = the exact value of the integral, I h = the approximation from an n-segment application of the trapezoidal rule with step size h = b − an, and Eh = the truncation error. If we make two separate estimates using step sizes of h 1 and h 2 and have exact val- ues for the error: I h 1 + Eh 1 = I h 2 + Eh 2 20.1 Now recall that the error of the composite trapezoidal rule can be represented approxi- mately by Eq. 19.21 [with n = b − ah]: E ∼ = − b − a 12 h 2 ¯ f ′′ 20.2 If it is assumed that ¯ f ′′ is constant regardless of step size, Eq. 20.2 can be used to deter- mine that the ratio of the two errors will be Eh 1 Eh 2 ∼ = h 2 1 h 2 2 20.3 This calculation has the important effect of removing the term ¯ f ′′ from the computation. In so doing, we have made it possible to utilize the information embodied by Eq. 20.2