Trapezoid Rule and Simpson s Rule c 2002, 2008, 200 Donald Kreider and Dwigt Lar Trapezoid Rule Many applications of calculus involve definite integrals. If we can find an antiderivative for te integrand, ten we can evaluate te integral fairly easily. Wen we cannot, we turn to numerical metods. Te numerical metod we will discuss ere is called te Trapezoid Rule. Altoug we often can carry out te calculations by and, te metod is most effective wit te use of a computer or programmable calculator. But at te moment let s not concern ourselves wit tese details. We will describe te metod first, and ten consider ways to implement it. f y 2 y 0 y y 3 a = x 0 x x 2 x 3 = b Te general idea is to use trapezoids instead of rectangles to approximate te area under te grap of a function. A trapezoid looks like a rectangle except tat it as a slanted line for a top. Working on te interval [a, b], we subdivide it into n subintervals of equal widt = (b a)/n. Tis gives rise to te partition a = x 0 x x 2 x n = b, were for eac j, x j = a + j, 0 j n. Moreover, we let y j = f(x j ), 0 j n. Tat is, te vertical edges go from te x-axis to te grap of f. Consult te sketc above were we ave sown a finite number of subintervals. If we are going to use trapezoids instead of rectangles as our basic area elements, ten we ave to ave a formula for te area of a trapezoid. y R - y L y R y L Wit reference to te sketc above, te area of a trapezoid consists of te area of te rectangle plus te area of te triangle, or y L + (/2)(y R y L ) = (y L + y R )/2. So, te area is times te average of te lengts of te two vertical edges. Now, we return to te original problem of finding te definite integral of a function f defined on te interval [a, b]. We define te Trapezoid Rule as follows.
Definition: Te n-subinterval trapezoid approximation to b f(x) dx is given by a T n = 2 (y 0 + 2y + 2y 2 + 2y 3 + + 2y n + y n ) = n y 0 + y n + 2 y j 2 j= To see were te formula comes from, let s carry out te process of adding te areas of te trapezoids. Refer to te original sketc, and use te formula we derived for te area of a trapezoid. Note tat wen we add te areas of te trapezoids starting on te left, te area of te first, second, and tird are: 2 (y 0 + y ) 2 (y + y 2 ) 2 (y 2 + y 3 ) So, y 0 and y 3, te first and te last, eac appear once; and all te oter y j s appear exactly twice. We can see from tis example tat tere will be a similar pattern no matter te number of trapezoids: Te first and te last vertical edge appears once, and all oter vertical edges appear two times wen we sum te areas of te trapezoids. Tis is exactly wat te Trapezoid Rule entails in te formula above. Example : Find T 5 for 2 and x j = + j/5, 0 j 5. x dx. We can readily determine tat f(x) = /x, = /5 (so /2 = /0), /5 /5 /5 /5 /5 So, T 5 = ( + ( 5 0 2 + 2 6 + 5 7 + 5 8 + 5 )).0696 9 Example 2: Find T 5 for 0 x2 dx. Tat is, we are going to approximate one-quarter of te area of a circle of radius. Te exact answer is π/4, or approximately.785398635. Note tat = /5, y 0 = and y 5 = 0. Tus, or about.7592622072. T 5 = + 2 0 4 j2 25 j= Simpson s Rule Anoter tecnique for approximating te value of a definite integral is called Simpson s Rule. Wereas te main advantage of te Trapezoid rule is its rater easy conceptualization and derivation, Simpson s rule 2
approximations usually acieve a given level of accuracy faster. Moreover, te derivation of Simpson s rule is only marginally more difficult. Bot rules are examples of wat we refer to as numerical metods. In te Trapezoid rule metod, we start wit rectangular area-elements and replace teir orizontal-line tops wit slanted lines. Te area-elements used to approximate, say, te area under te grap of a function and above a closed interval ten become trapezoids. Simpson s metod replaces te slanted-line tops wit parabolas. Toug two points determine te equation of a line, tree are required for a parabola. We also need to develop a formula for te area of a parabolic-top area-element if te sum of suc areas is to become te Simpson approximation. Suppose we consider a parabola y = Ax 2 + Bx + C wit its axis parallel to te y-axis and passing troug tree equally spaced points (, y L ), (0, y M ), and (, y R ). Ten substituting te tree points into te equation gives tree equations in te tree unknowns A, B, C. y L = A 2 B + C y M = C y R = A 2 + B + C Solving tese tree equations by adding te first to te last, and ten by subtracting te last from te first, yields: 2A 2 = y L + y R 2y M B = y R y L 2 C = y M Next, we compute te area under te parabola y = Ax 2 + Bx + C and above te interval [, ] for te values of A, B, and C we just found: 3
Ax 2 + Bx + C dx = ) (A x3 3 + B x2 2 + Cx = 3 2A3 + 2C ( ) = 3 2A2 + 2C ( ) = 3 (y L + y R 2y M ) + 2y M = 3 (y L + y R 2y M + 6y M ) = 3 (y L + y R + 4y M ) Te above formula olds for te area of a parabolic topped area element wit base of lengt 2 and vertical edges of lengt y L on te left and y R on te rigt. Te eigt at te midpoint is y M. Now, let n be an even positive integer, and suppose we divide an interval [a, b] into n equal parts eac of lengt = b a n. And suppose f is a function defined on [a, b]. As before we label te resulting partition a = x 0 x x 2 x n = b, were for eac j, x j = a + j, 0 j n. And again, we let y j = f(x j ), 0 j n. Tat is, te vertical edges go from te x-axis to te grap of f. Next, start at te left endpoint a of te interval and erect a parabolic-top area-element on te first two subintervals. Te base of tis area-element goes from x 0 to x 2, and we use as vertical sides te lines tat intersect te grap at (x 0, y 0 ) on te left and (x 2, y 2 ) on te rigt. Te point (x, y ) on te grap of f at te midpoint of te interval gives te tird point we need to determine te parabola tat forms te top of te area-element. From te formula we developed above, te area of tis area-element is equal to 3 (y 0 + y 2 + 4y ). If we repeat tis process using te next two subintervals tat go from x 2 to x 4, ten te area of te resulting parabolic-top element will be (from an application of te formula above) 3 (y 2 + y 4 + 4y 3 ). Tus, te sum of te areas of te two parabolic-top elements equals 3 (y 0 + 4y + 2y 2 + 4y 3 + y 4 ). We continue in tis way until we ave calculated te areas of te n 2 parabolic-top area elements and added tem togeter. A pattern begins to emerge in te form of te sum of te areas of te n 2 parabolic-top area-elements. Te sum will equal 3 multiplied by: y 0 + y n, i.e. te sum of te eigts of te leftmost and rigtmost vertical edges; plus 4 times te sum of te odd-indexed eigts; plus 2 times te sum of te even-indexed eigts because tese edges belong to two successive area-elements, one on te left and te oter on te rigt. Tis explains te form of te Simpson s Rule approximation wic we now state Definition: Let n be even. Te n-subinterval Simpson approximation to b f(x) dx is given by a S n = 3 (y 0 + 4y + 2y 2 + 4y 3 + 2y 4 + + 2y n 2 + 4y n + y n ) = (y 0 + y n + 4 y odd + 2 ) y even 3 Example 3: Find S 4 for 2 x dx. Te exact answer is ln 2, or approximately 0.69347806. In Example we found tat T 5 is equal to about 0.0696. If we are to use Simpson s rule for an approximation, ten n as to be even. Terefore, S 4 is a legitimate sum to calculate. Note tat = /4. Te five points of te partition are x 0 =, x = 5/4, x 2 = 3/2, x 3 = 7/4, x 4 = 2. And te corresponding y-values are y 0 =, 4
y = 4/5, y 2 = 2/3, y 3 = 4/7 and y 4 = /2. Tus, S 4 = ( + ) 2 2 + 4 (y + y 3 ) + 2 (y 2 ) = ( + ( 4 2 2 + 4 5 + 4 ) ( )) 2 + 2 7 3 0.6932539683. Note tat S 4 wit a smaller n is a better approximation to te actual value of te integral tan T 5. Example 4: Find S 4 for 0 x2 dx. Te exact answer is π/4, or approximately 0.785398635, onequarter of te area of a circle of radius. In Example 2 we found tat T 5 is equal to about 0.7592622072. If we are to use Simpson s rule for an approximation, ten n as to be even, so S 4 makes sense. Note tat = /4. Te five points of te partition are x 0 = 0, x = /4, x 2 = /2, x 3 = 3/4, x 4 =. And te corresponding y-values are y 0 =, y = /6, y 2 = /4, y 3 = 9/6 and y 4 = 0. Tus, S 4 = 2 ( + 0 + 4 (y + y 3 ) + 2 (y 2 )) = ( ( ) + 0 + 4 5/6 + 7/6 + 2 ) 3/4 2 or about 0.7708987887. Te latter is a better approximation wit a smaller n tan we got wit te Trapezoid rule. Error Comparisons: As we found to be true in te examples, Simpson s rule is indeed muc better tan te Trapezoid rule. As n it generally converges muc more rapidly to te value of te definite integral tan does te Trapezoid rule. We can get a sense of te differences in te rates of convergence of te two metods from te folowing two teorems: T: Suppose te second derivative of f is continuous and ence necessarily bounded by a positine number M 2 on [a, b]. If error Tn = b a f(x) dx T n, ten error Tn M 2(b a) 3 2n 2 T2: Suppose te fourt derivative of f is continuous and ence necessarily bounded by a positive number M 4 on [a, b]. If error Sn = b a f(x) dx S n, ten error Sn M 4(b a) 5 80n 4 Tese teorems imply tat in many situations, as n, error Tn 0 like /n 2 and error Sn 0 like /n 4. Tis explains wy in general we are not surprised to find tat Simpson s rule converges to te value of te integral muc faster tan te Trapezoid rule. Importance of te Trapezoid and Simpson Rules: You migt ask,wat is te point of te Trap and Simp approximations in tis age of computers? Te answer is tat tey are simple to use and give excellent results, surprisingly so even for small n. A little aritmetic can yield a good estimate of a definite integral wit only modest effort. Not bad, e? Applet: Numerical Integration Try it! Exercises: Problems Ceck wat you ave learned! Videos: Tutorial Solutions See problems worked out! 5