Mathematics

The Trapezoidal Rule

The Trapezoidal Rule is a numerical method for approximating the definite integral of a function. It involves dividing the interval of integration into smaller subintervals and approximating the area under the curve using trapezoids. By summing the areas of these trapezoids, an estimate of the integral can be obtained, making it a useful tool for numerical integration.

Written by Perlego with AI-assistance

10 Key excerpts on "The Trapezoidal Rule"

  • Book cover image for: Elements of Numerical Analysis
    6.4 Trapezoidal Rule In The Trapezoidal Rule, the function f ( x ) is approximated over the interval ( x 0 , x 1 ) by a straight line (polynomial of degree one) passing through the points ( x 0 , y 0 ) and ( x 1 , y 1 ) , See Fig. 6.2. Figure 6.2. Approximation by trapezium . Numerical Integration • 229 Thus the area under the curve y = f ( x ) is approximated by the area of the trapezium, i . e., x 1 Z x 0 f ( x ) dx = h y 0 + y 1 2 . (6.14) The value of the integral I over ( a , b ) may be obtained repeating the above process for all the n intervals. Now let us discuss it analytically. ( i ) Based on Lagrange’s Method By Lagrange’s method, the equation of the straight line passing through the points ( x 0 , y 0 ) and ( x 1 , y 1 ) is given by, y = P ( x ) = x -x 1 x 0 -x 1 y 0 + x -x 0 x 1 -x 0 y 1 = 1 h [( x -x 0 ) y 1 -( x -x 1 ) y 0 ] , (6.15) with associated error R ( x ) = ( x -x 0 )( x -x 1 ) f 00 ( ξ ) 2! , x 0 ≤ ξ ≤ x 1 . (6.16) The area over the first interval is thus approximated as, x 1 Z x 0 f ( x ) dx = 1 h x 1 Z x 0 [( x -x 0 ) y 1 -( x -x 1 ) y 0 ] dx = 1 2 h ( x -x 0 ) 2 y 1 -( x -x 1 ) 2 y 0 x 1 x 0 = h 2 ( y 0 + y 1 ) . (6.17) This is ‘trapezoidal rule’. The error in trapezoidal rule will be given by integrating (6.16) from x 0 to x 1 , i . e., E = x 1 Z x 0 ( x -x 0 )( x -x 1 ) f 00 ( ξ ) 2 dx = f 00 ( ξ ) 2 · h 3 1 Z 0 p ( p -1 ) dp ∵ dx = hdp 230 • Elements of Numerical Analysis = -h 3 12 f 00 ( ξ ) , x 0 ≤ ξ ≤ x 1 . (6.18) The composite formula for integral I may be obtained by applying The Trapezoidal Rule over all the n intervals and adding, i . e., b = x n Z a = x 0 f ( x ) dx = h 2 [ y 0 + y n + 2 ( y 1 + y 2 + .... + y n -1 )] . (6.19) The upper bound for the error in the composite formula (6.19) may be taken as n times the largest error in any interval, i . e., TE = -nh 3 12 f 00 ( ξ ) , x 0 ≤ ξ ≤ x n (6.20) = -( b -a ) h 2 12 f 00 ( ξ ) .
  • Book cover image for: Mathematical Applications for the Management, Life, and Social Sciences
    Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it. SECTION 13.8 Numerical Integration Methods: The Trapezoidal Rule and Simpson’s Rule 841 Numerical Integration Methods: The Trapezoidal Rule and Simpson’s Rule APPLICATION PREVIEW A pharmaceutical company tests the body’s assimilation of a new drug by administering a 200-milligram dose and collecting the following data from blood samples, where t is time in hours and R(t) gives the assimilation of the drug in milligrams per hour. t 0 0.5 1.0 1.5 2.0 2.5 3.0 R(t) 0.0 15.3 32.3 51.0 74.8 102.0 130.9 The company would like to find the amount of drug assimilated in 3 hours, which is given by 2 3 0 R(t) dt In this section, we develop straightforward and accurate methods for approxi- mating integrals such as this, even when, as with R(t), only function data, rather than a formula, are given. (See Example 4.) We have studied several techniques for integration and have even used tables to evaluate some integrals. Yet some functions that arise in practical problems cannot be integrated by using any formula. For any function f (x) $ 0 on an interval [a, b], however, we have seen that a definite integral can be viewed as an area and that we can usually approximate the area and hence the integral. (See Figure 13.31.) One such approximation method uses rect- angles, as we saw when we defined the definite integral. In this section, we consider two other numerical integration methods to approximate a definite integral: The Trapezoidal Rule and Simpson’s Rule.
  • Book cover image for: Ship Hydrostatics and Stability
    These two methods are sufficient for solving most problems encountered in Naval Architec-ture. The error terms will be given without derivation; however, interpretations of the error expressions will follow their presentation. 3.2 The Trapezoidal Rule Let us consider the function f ( x ) represented in Figure 3.1. We assume that we know the values f ( x 1 ) , f ( x 2 ) , . . . , f ( x 5 ) and we want to calculate the definite integral I = x 5 x 1 f ( x ) d x (3.2) The integral in Eq. (3.2) represents the area under the curve f ( x ) . Let us connect the points f ( x 1 ) , f ( x 2 ) , . . . , f ( x 5 ) by straight line segments (the dashed-dotted Numerical integration in naval architecture 73 f ( x 1 ) Given integrand Trapezoidal approximation f ( x 2 ) f ( x 3 ) f ( x 4 ) f ( x 5 ) x 1 x 2 x 3 x 4 x 5 Figure 3.1 The derivation of The Trapezoidal Rule lines in the figure). We approximate the area under the curve by the sum of the areas of four trapezoids, i.e. the area of the trapezoid with base x 1 x 2 and heights f ( x 1 ) , f ( x 2 ) , plus the area of the trapezoid with base x 2 x 3 and heights f ( x 2 ) , f ( x 3 ) , and so on. We obtain I ≈ ( x 2 − x 1 ) f ( x 1 ) + f ( x 2 ) 2 + ( x 3 − x 2 ) f ( x 2 ) + f ( x 3 ) 2 + · · · (3.3) For constant x -spacing, x 2 − x 1 = x 3 − x 2 = · · · = h , Eq. (3.3) can be reduced to a simpler form: I ≈ h 1 2 f ( x 1 ) + f ( x 2 ) + f ( x 3 ) + · · · + f ( x n − 1 ) + 1 2 f ( x n ) (3.4) We call the intervals [ x 1 , x 2 ] , [ x 2 , x 3 ] , and so on, subintervals . As an example, let us calculate 90 ◦ 0 ◦ sin x d x 74 Ship Hydrostatics and Stability The calculation presented in tabular form is as follows: Angle ( ◦ ) sin x Multiplier Product 0 0 1/2 0 15 0.2588 1 0.2588 30 0.5000 1 0.5000 45 0.7071 1 0.7071 60 0.8660 1 0.8660 75 0.9659 1 0.9659 90 1.0000 1/2 0.5000 Sum – – 3.7979 The calculations were performed with MATLAB and the precision of the display in the short format , i.e.
  • Book cover image for: Fundamentals of Engineering Numerical Analysis
    The geometrical foundation of this formula is that the function f in the interval is approximated by a straight line passing through the end points, and the area under the curve in the interval is approximated by 30 3.2 ERROR ANALYSIS 31 x j x j +1 f(x) Figure 3.1 Trapezoidal rule; approximating f by a straight line between x j and x j + 1 . the area of the resulting trapezoid (see Figure 3.1 ). For the entire interval [ a , b ] The Trapezoidal Rule is obtained by adding the integrals over all sub-intervals: I ≈ h ⎛ ⎝ 1 2 f 0 + 1 2 f n + n − 1 j = 1 f j ⎞ ⎠ , (3.2) where uniform spacing x = h is assumed. If we approximate f in each interval by a parabola rather than a straight line, then the resulting quadrature formula is known as Simpson’s rule. To uniquely define a parabola as a fitting function, it must pass through three points (or two intervals). Thus, Simpson’s formula for the integral from x j to x j + 2 is given by x j + 2 x j f ( x ) dx ≈ x 3 f ( x j ) + 4 f ( x j + 1 ) + f ( x j + 2 ) . (3.3) Similarly, Simpson’s rule for the entire domain with uniform mesh spacing, x = h is given by I ≈ h 3 ⎛ ⎜ ⎜ ⎝ f 0 + f n + 4 n − 1 j = 1 j = odd f j + 2 n − 2 j = 2 j = even f j ⎞ ⎟ ⎟ ⎠ . (3.4) Note that in order to use Simpson’s rule for the entire interval of integration, the total number of points ( n + 1) must be odd (even number of panels). Before we discuss the accuracy of these formulae, notice that they both can be written in the compact form: I = b a f ( x ) dx ≈ n i = 0 w i f ( x i ) (3.5) where w i are the weights. For example, for The Trapezoidal Rule w 0 = w n = h 2 and w i = h for i = 1 , 2 , . . . , n − 1. 3.2 Error Analysis We will now establish the accuracy of these formulas using Taylor series ex-pansions. It turns out that it is easier to build our analysis around the so-called 32 NUMERICAL INTEGRATION x j x j +1 f(x) y j Figure 3.2 Rectangle rule; approximating f in the interval between x j and x j + 1 by its value at the midpoint.
  • Book cover image for: An Introduction to Numerical Methods and Analysis
    • James F. Epperson(Author)
    • 2014(Publication Date)
    • Wiley
      (Publisher)
    322 NUMERICAL INTEGRATION substantiated by a single example. Which adaptive routine works best on a given example will depend on the specifics of the example. (It should be noted that all of the routines integrated our example to the expected accuracy.) 5.8.4 Peano Estimates for the Trapezoid Rule Recall that the trapezoid rule is constructed by exactly integrating a linear polynomial approximation to the integrand. We can use this to derive an interesting error formula, known as a Peano 11 estimate. Consider /(/) = / f{x)dx Ja and Ti(f) = \(b-a)(f(b)+f(a)), the basic trapezoid rule. Since T\ is derived from exactly integrating a linear approximation, it is exact when applied to any and all linear functions: Ά( ) = ( ) for all functions p of the form p(x) = Ax + B. (See Problem 14.) In addition, we can view both / and T\ as linear operators, meaning that I(af + ßg) = al(f)+ßl(g) for constants a and ß, and similarly for T\{af + ßg). (See Problem 15.) Now, for any given integrand /, use Taylor's Theorem to write f{x)=Pi(x) + Ri{x), where pi is the linear Taylor polynomial and R\ is the integral form of the remainder. Since T\ is exact for linear polynomials, we know that I{pi)=Ti(pi). Therefore, Hf)-Ti(f) = /(ρι + Αι)-ϊι(ρι+Αι), = /(ÄO-T^Äi), = f Γ( - t)f"(t)dtdx - 1(6 -a)f{b- t)f"(t)dt. We can interchange the order of integration in the double integral to get pb px pb pb pb I pb \ / / (x-t)f"(t)dtdx = (x-t)f"(t)dxdt= / / (x - t)dx ) f"(t)dt Ja Ja Ja Jt Ja \Jt J I Ja b \(b-tff"(t)dt, 17 Giuseppe Peano (1858-1932) entered the University of Turin, in Italy, in 1876 and graduated with a doctorate in mathematics in 1880. Known primarily for his work in mathematical logic and the foundations of mathematics, he published the development of the Peano kernel in two papers that appeared in Italian journals in 1913-1914.
  • Book cover image for: Numerical Methods for Engineers and Scientists
    • Joe D. Hoffman, Joe D. Hoffman, Steven Frankel(Authors)
    • 2018(Publication Date)
    • CRC Press
      (Publisher)
    The rectangle rule has Numerical Integration 291 Table 6.1 Newton-Cotes Formulas n Formula o Rectangle rule 1 Trapezoid rule 2 Simpson's 1/3 rule 3 Simpson's 3/8 rule poor accuracy, so it is not considered further. The other three rules are developed in this section. Some terminology must be defined before proceeding with the development of the Newton-Cotes formulas. Figure 6.4 illustrates the region of integration. The distance between the lower and upper limits of integration is called the range of integration. The distance between any two data points is called an increment. A linear polynomial requires one increment and two data points to obtain a fit. A quadratic polynomial requires two increments and three data points to obtain a fit. And so on for higher-degree polynomials. The group of increments required to fit a polynomial is called an interval. A linear polynomial requires an interval consisting of only one increment. A quadratic polynomial requires an interval containing two increments. And so on. The total range of integration can consist of one or more intervals. Each interval consists of one or more increments, depending on the degree of the approximating polynomial. 6.3.1 The Trapezoid Rule (6.20) (6.21) The trapezoid rule for a single interval is obtained by fitting a first-degree polynomial to two discrete points, as illustrated in Figure 6.5. The upper limit of integration Xl corresponds to s = I. Thus, Eq. (6.19) gives I (2 )1 M = h t (10 + s ~.fo) ds = h sfo + s2 ~fo 0 where h = fu. Evaluating Eq. (6.20) and introducing ~fo = (fi -10) yields M = h(fo + ~ ~fo) = h[fo + ~ (fi -10)] where M denotes the integral for a single interval. Simplifying yields the trapezoid rule for a single interval: I M=~h(fo+fi) I (6.22) interval n interval 1 1-------range of integration --------t interval 2 • a --~ I I I 1---increment • b x Figure 6.4 Range, intervals, and increments.
  • Book cover image for: Numerical Methods with Chemical Engineering Applications
    This occurs because the higher-order polynomials are increas-ingly curved, so the values of their derivatives, which appear in the equation for R n in Eq. ( 8.2.69 ), are increasing. Second, note that the error for n = 2 and n = 3 begins at m = 4, and the error for n = 4 and n = 5 begins at m = 6. This is the manifestation of the zero value of the odd integral in Eq. ( 8.3.15 ) for n = 2 and a similar integral at the fifth power for n = 4. 8.4 Applications of Trapezoidal Rule 439 Table 8.1 Values of the integral in Eq. ( 8.3.22 ) using Newton–Coates formulas of order n . m n = 1 n = 2 n = 3 n = 4 n = 5 1 1.000 000 1.000 000 1.000 000 1.000 000 1.000 000 2 1.500 000 1.000 000 1.000 000 1.000 000 1.000 000 3 2.000 000 1.000 000 1.000 000 1.000 000 1.000 000 4 2.500 000 1.041 667 1.018 519 1.000 000 1.000 000 5 3.000 000 1.125 000 1.055 556 1.000 000 1.000 000 6 3.500 000 1.239 583 1.109 053 1.002 604 1.001 467 8.4 Applications of Trapezoidal Rule The Trapezoidal Rule in Eq. ( 8.3.7 ) is the simplest of all of the Newton–Coates formulas. Despite its simplicity, The Trapezoidal Rule turns out to be very useful for construct-ing more advanced algorithms for numerical integration. We will consider three such algorithms here. 8.4.1 Multiple Trapezoidal Rule All of the Newton–Coates formulas use a single interpolant over the entire range x ∈ [ a , b ]. However, if you remember that the integral is just the area under the curve, then you can see that you could also break up the integral over x ∈ [ a , b ] into a sum of integrals, I = x 1 x 0 f ( x ) dx + x 2 x 1 f ( x ) dx + · · · + x n x n − 1 f ( x ) dx (8.4.1) Figure 8.5 explains the utility of breaking up the integral. In some cases, you can have a reasonably high degree of curvature to the function or large variations in the curvature. In these cases, you would need to use a very high-order polynomial to get a good inter-polation for the function.
  • Book cover image for: Applied Mathematics for Science and Engineering
    • Larry A. Glasgow(Author)
    • 2014(Publication Date)
    • Wiley
      (Publisher)
    4 Numerical Quadrature

    Introduction

    Definite integrals must be evaluated routinely and for cases in which an antiderivative cannot be found, or for cases in which the analytic process is simply too difficult, a numerical scheme (numerical integration, or quadrature) may be our only recourse. Consider the integral
    (4.1)
    which we know to have the value . Let us consider a plot of the integrand as a function of x, shown in Figure 4.1 .
    Figure 4.1.   Behavior of x2 exp(−x2 ). The value of the integral, eq. (4.1) , is known to be .
    We will conduct an elementary experiment with the graph of this integrand: First, we will count the smaller rectangular regions under the curve and add their areas together to obtain (70)(0.25)(0.025) = 0.4375. Next, we will cut out the region under the curve and weigh it and compare that weight to the average weight per rectangle. For the paper under the curve, we find W = 0.5754 g, and for each box, 0.008003 g. Therefore, the area under the curve is approximately 71.89 rectangular boxes or (71.89)(0.25)(0.025) = 0.4493. Our first estimate is in error by about 1.3% (under) and our second estimate by about 1.4% (over). For many applications, a rough evaluation like this would be acceptable, but suppose it was not. We might have a critically important problem where accuracy was paramount. Therefore, it will be productive for us to review some techniques that may be capable of producing significantly improved estimates.

    Trapezoid Rule

    One of the simpler schemes for making this evaluation is the trapezoid rule; we use a straight-line approximation for f(x) over a finite interval, Δx, and then multiply the average value for f(x) by the width. For example, let f1  = f(x) and f2  = f(x + Δx). Our approximation, therefore, is
    If Δx is sufficiently small, this may work well. We will apply it first to the previous example; notice in the following code that the upper limit for the integral has been set to 8. We conclude that this may be reasonable since (8)2 exp(−8)2  ≅ 1.03 × 10−26 . This is an example of limit truncation
  • Book cover image for: An Introduction to Numerical Computation
    • Wen Shen(Author)
    • 2015(Publication Date)
    • WSPC
      (Publisher)
    m+1). By an algebraic manipulation we get
    This leads to the Recursive Trapezoid Rule:
    Advantages.This algorithm is flexible and efficient.
    1.Flexibility: One can perform the computation up to a level m. If this turns out to be not accurate enough, then one can add one more level to get better approximation.
    2.Efficiency: This formula allows us to compute a sequence of approximations to a definite integral using the trapezoid rule without re-evaluating the integrand at points where it has already been evaluated.
    A very interesting aspect, discussed in the next section, is that this sequence of approximations allows a further development of algorithm, using Richardson’s extrapolation technique. This leads to the Romberg algorithm, providing approximations of high order.

    4.5Romberg Algorithm

    Assume that we have generated a sequence of approximations, with different values of h, using the Composite Trapezoid Rule described in the previous section. We denote these values as
    We now explore how one could combine these numbers in particular ways, and get higher order approximations to the exact integral I(f).
    The particular form of the final algorithm will depend on the error formula. Consider the trapezoid rule. If f admits a Taylor series expansion, then one can prove that the error satisfies the Euler-MacLaurin’s formula
    E(f; h) = I(f) − T(f; h) = a2 h2 + a4 h4 + a6 h6 + · · ·.
    Here an depends on the derivatives f
    (n)
    . Note that only even powers of h show up in the error formula! Due to symmetry of the methods, all terms containing hk , with k odd, are cancelled out!
    When we reduce the grid size h by a half, the error formula becomes
    We now have
    Our goal is to combine the two approximations T(f; h) and to get new approximation which is more accurate. In essence, we wish to cancel the leading error terms, i.e., the ones with h2
  • Book cover image for: An Introduction to Numerical Methods and Analysis
    • James F. Epperson(Author)
    • 2013(Publication Date)
    • Wiley
      (Publisher)
    Handbook of Mathematical Functions [1].
    12. Bessel functions appear in the solution of heat conduction problems in a circular or cylindrical geometry, and can be defined as a definite integral, thus:
    Use Simpson’s rule plus extrapolation to produce values of J0 and J1 that are accurate to within 10−8 over the interval [0, 6] in increments of 1/4. Check your values by looking at a set of tables; for example, Handbook of Mathematical Functions [1].
    13. Apply the trapezoid rule to approximate the integral
    Use Richardson extrapolation to estimate how rapidly your approximations are converging, and comment on your results in light of the theory for the trapezoid rule.
    14. Show that for any function f,
    Comment on the significance of this result in light of this section.

    5.8 SPECIAL TOPICS IN NUMERICAL INTEGRATION

    5.8.1 Romberg Integration

    If we specialize now to the case of the trapezoid rule, we can make much of §5.7 more precise, and, at the same time, develop a very accurate recursive procedure for approximating integrals. A fundamental result is the Euler–Maclaurin formula,11 which we now state, without proof.
    Theorem 5.6 (Euler–Maclaurin Formula) If f is sufficiently differentiable, then, for any N > 0 there exists a set of constants c
    k
    , 1 ≤ kN + 1, such that, for some ξ [a, b], the error in the trapezoid rule satisfies
    (5.17)
    where γ
    k
    = c
    k
    (f
    (2k−1)
    (b) − f
    (2k −1)
    (a)).
    The significance of the Euler–Maclaurin formula is that it allows us to write the error in the trapezoid rule as a series of powers of the mesh spacing h, and then use this series to derive new quadrature rules that are more and more accurate. Note that the series expansion of the error can be carried out as far as f
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.