rectangle
play

Rectangle ------- ------- Rule ------- ------- . . . . ------- - PDF document

Numerical Integration Introduction There are two types of integrals: indefinite integral and definite integral. If we can find an anti-derivative F ( x ) of a function f , and F is an elementary function, then we can compute b I = a f ( x ) dx


  1. Numerical Integration Introduction There are two types of integrals: indefinite integral and definite integral. If we can find an anti-derivative F ( x ) of a function f , and F is an elementary function, then we can compute � b I = a f ( x ) dx = F ( b ) − F ( a ) . Maple and Mathematica can do symbolic integration (when possible). However often it is not possible to obtain such an F ( x ) for f ( x ). e.g. the case of f ( x ) = e − x 2 . When symbolic integration is not feasible, we can use numerical integration , to approximate an integral by something which is much easier to compute . � b One important interpretation for the definite integral a f ( x ) dx is it is the area between the graph of f and the x -axis on this interval (here the area may be negative). Rectangle Rule ------- Rectangle ------- ------- Rule ------- ------- . . . . ------- ------- ------- ------- ........ ------- ------- ........ ------- ------- ........ ------- ------- ------- a |< h >| b Partition [ a, b ] into n equal subintervals [ x i , x i +1 ], i = 0 , 1 , . . . , n − 1, all with width h = ( b − a ) /n . Each rectangle touches the graph of f at its top left corner. The area of the rectangle over [ x i , x i +1 ] is hf ( x i ) = hf ( a + ih ) . The total area of the n rectangle panels is n − 1 � I R = h f ( a + ih ) . i =0 � b This is an approximation of I = a f ( x ) dx and it is called the (left composite) rectangle rule (for n equal subintervals). Note that f is evaluated at n discrete points. 1

  2. Error Analysis of the Rectangle Rule Tools for error analysis: The Mean-Value-Theorem • for sum: Let q ( x ) be continuous on [ a, b ]. If p ( z i ) ≥ 0 for i = 1 , . . ., n , then n n � � p ( z i ) q ( z i ) = q ( z ) p ( z i ) , some z ∈ [ a, b ] , i =1 i =1 • for integrals: Let q ( x ) and p ( x ) be continuous with p ( x ) ≥ 0. Then � b � b a p ( x ) q ( x ) dx = q ( z ) a p ( x ) dx, some z ∈ [ a, b ] Theorem : Let f ′ be continuous on [ a, b ]. Then for some z ∈ [ a, b ], I − I R = 1 2( b − a ) hf ′ ( z ) = O ( h ) . Proof : We first show when h = b − a , it is true, i.e., I − I R = 1 2( b − a ) 2 f ′ ( z ) , for some z ∈ [ a, b ] ( ∗ ) For every x ∈ [ a, b ], the Taylor series expansion gives f ( x ) = f ( a ) + ( x − a ) f ′ ( z x ) , for some z x ∈ [ a, b ] . Then � b I − I R = a f ( x ) dx − f ( a )( b − a ) � b � b = a f ( x ) dx − a f ( a ) dx � b = a [ f ( x ) − f ( a )] dx � b a ( x − a ) f ′ ( z x ) dx = � b f ′ ( z ) = a ( x − a ) dx (MVT for integral) 1 2( b − a ) 2 f ′ ( z ) . = Now let [ a, b ] be divided into n equal subintervals by x 0 , x 1 , . . . , x n with spacing h = ( b − a ) /n . Applying ( ∗ ) to subinterval [ x i , x i +1 ], we have � x i +1 f ( x ) dx − f ( x i ) h = ( x i +1 − x i ) 2 f ′ ( z i ) = h 2 2 f ′ ( z i ) , 2 x i 2

  3. for some z i ∈ [ x i , x i +1 ]. So we have � b n − 1 � I − I R = a f ( x ) dx − h f ( x i ) i =0 n − 1 � x i +1 n − 1 � � = f ( x ) dx − h f ( x i ) x i i =0 i =0 n − 1 1 2 h 2 · f ′ ( z i ) � = i =0 f ′ ( z ) · 1 2 nh 2 = (MVT for sum) 1 2( b − a ) hf ′ ( z ) . = Midpoint Rule ...... Midpoint ...... ...... ...... ...... Rule ....... ...... ...... ....... ...... ...... ...... ....... ...... . a b | < h > | , We make the midpoint of the top of each rectangle intersect the graph. The midpoint rule : n − 1 where h = b − a � I M = h f [ a + ( i + 1 / 2) h ] , . n i =0 Since part of the rectangle usually lies above the graph of f and part below , the midpoint rule is more accurate than the rectangle rule. It can be proven that for some z ∈ [ a, b ] I − I M = 1 24( b − a ) h 2 f ′′ ( z ) = O ( h 2 ) . (Try to prove it by yourself) 3

  4. Trapezoid Rule Consider trapezoid-shaped panels : Trapezoid Rule a+2h . . . a+h a The trapezoid rule: n − 1 I T = 1 f ( a + ih ) , with h = b − a � 2 h [ f ( a ) + f ( b )] + h . n i =1 It can be shown that for some z ∈ [ a, b ] I − I T = − 1 12( b − a ) h 2 f ′′ ( z ) = O ( h 2 ) . Q Prove both the midpoint and trapezoid rules give the exact integral if f is linear . Recursive Trapezoid Rule Suppose [ a, b ] is divided into 2 n equal subintervals. Then the trapezoid rule is 2 n − 1 I T (2 n ) = 1 � 2 h [ f ( a ) + f ( b )] + h f ( a + ih ) . i =1 where h = ( b − a ) / 2 n . The trapezoid rule for 2 n − 1 equal subintervals is 2 n − 1 − 1 I T (2 n − 1 ) = 1 ˜ h [ f ( a ) + f ( b )] + ˜ f ( a + i ˜ � h h ) . 2 i =1 4

  5. h = ( b − a ) / 2 n − 1 = 2 h . It is easy to show the following recursive formula where ˜ 2 n − 1 I T (2 n ) = 1 2 I T (2 n − 1 ) + h � f [ a + (2 i − 1) h ] . i =1 After computing I T (2 n − 1 ) we can compute I T (2 n ) by this recursive formula without reeval- uating f at the old points. Simpson’s Rule There is no need for straight edges: Simpson’s Rule a+2h . . . a+h a Each panel is topped by a parabola . There are an even number of panels with width h = ( b − a ) /n . The top boundary of the first pair of panels is the quadratic which interpolates ( a, f ( a )), ( a + h, f ( a + h )), ( a + 2 h, f ( a + 2 h )). The next interpolates ( a + 2 h, f ( a + 2 h )), ( a + 3 h, f ( a + 3 h )), ( a + 4 h, f ( a + 4 h )), and so on. The area of the first 2 panels can be shown to be h 3 [ f ( a ) + 4 f ( a + h ) + f ( a + 2 h )] Q: How would you obtain this ?? Summing the areas of the pairs h 3[ f ( a ) + 4 f ( a + h ) + f ( a + 2 h )] , h 3[ f ( a + 2 h ) + 4 f ( a + 3 h ) + f ( a + 4 h )] , · · · · · ·· · · h 3[ f ( b − 2 h ) + 4 f ( b − h ) + f ( b )] , 5

  6. leads to Simpson’s rule ( h = b − a n ): I S = h 3[ f ( a ) + 4 f ( a + h ) + 2 f ( a + 2 h ) + 4 f ( a + 3 h ) + · · · +4 f ( b − 3 h ) + 2 f ( b − 2 h ) + 4 f ( b − h ) + f ( b )] . It can be shown for some z ∈ [ a, b ] I − I S = − 1 180( b − a ) h 4 f (4) ( z ) = O ( h 4 ) . Q: What is the highest degree polynomial for which the rule is exact in general ?? Adaptive Simpson’s Method Motivation and ideas of an adaptive integration method: A function may varies rapidly on some parts of the interval [ a, b ], but varies little on other parts. It is not very efficient to use some panel width h everywhere on [ a, b ]. But on the other hand, it is not known in advance on which part of the integral f varies rapidly. We can consider an adaptive integration method. The basic idea is we divide [ a, b ] into 2 subintervals and then decide whether each of them is to be divided into more subintervals. This procedure is continued until some specified accuracy is obtained throughout the whole interval [ a, b ]. A framework of an adaptive method: function numI = adapt ( f, a, b, ǫ, · · · ) Compute the integral from a and b in two ways and call the values I 1 and I 2 (assume I 2 is better than I 1 ) Estimate the error in I 2 based on | I 2 − I 1 | if | the estimated error | ≤ ǫ , then numI = I 2 (or numI = I 2 + the estimated error) else c = ( a + b ) / 2 numI = adapt ( f, a, c, ǫ/ 2 , · · · ) + adapt ( f, c, b, ǫ/ 2 , · · · ) end This will guarantee | I − numI | < ∼ ǫ . Now we want to fill in details for Simpson’s method. 6

  7. • Defining I 1 and I 2 : Simpson’s rule for n = 2 gives I = I 1 + E 1 , where I 1 = b − a [ f ( a ) + 4 f ( a + b ) + f ( b )] , 6 2 E 1 = − 1 180( b − a )( b − a ) 4 f (4) ( z ) . 2 Simpson’s rule for n = 4 gives I = I 2 + E 2 , where I 2 = b − a 12 [ f ( a ) + 4 f ( a + b − a ) 4 +2 f ( a + b − a ) + 4 f ( a + 3( b − a ) ) + f ( b )] , 2 4 E 2 = − 1 180( b − a )( b − a ) 4 f (4) (˜ z ) . 4 • Estimating the error in I 2 : z ) in E 2 . (a reasonable assumption if f (4) does We assume f (4) ( z ) in E 1 is equal to f 4 (˜ not vary much on [ a, b ]). Then we observe E 1 = 16 E 2 . Since I = I 1 + E 1 = I 2 + E 2 , we have I 2 − I 1 = E 1 − E 2 = 16 E 2 − E 2 = 15 E 2 . This gives an error estimate in I 2 : E 2 = 1 15( I 2 − I 1 ) . 7

  8. Adaptive Simpson’s algorithm: function numI = adapt simpson ( f, a, b, ǫ, level, level max ) h ← b − a c ← ( a + b ) / 2 I 1 ← h [ f ( a ) + 4 f ( c ) + f ( b )] / 6 level ← level + 1 d ← ( a + c ) / 2 e ← ( c + b ) / 2 I 2 ← h [ f ( a ) + 4 f ( d ) + 2 f ( c ) + 4 f ( e ) + f ( b )] / 12 if level ≥ level max , then numI ← I 2 else if | I 2 − I 1 | ≤ 15 ǫ , then (or numI ← I 2 + 1 numI ← I 2 15 ( I 2 − I 1 )) else numI ← adapt simpson ( f, a, c, ǫ/ 2 , level, level max ) + adapt simpson ( f, c, b, ǫ/ 2 , level, level max ) end end 8

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend