Numerical Integration
Total Page:16
File Type:pdf, Size:1020Kb
Chapter 5 Numerical integration In this chapter, we study how to approximate the definite integral of some smooth functions. An idea is to use an interpolating polynomial F (x) to evaluate the integral. Thus we have b b f(x) dx F (x) dx. ≈ Za Za Our purpose is how to design such an interpolation so that the error is mini- mized. 5.1 Closed Newton-Cotes Formulas We would like to design a quadrature for the following integral: b f(x) dx. Za One point formula: If F (x) is a constant interpolation at x0, then the above integral is approximated by (b a)f(x ) called a rectangle rule. One can − 0 show that there exist ξ0 and ξ0 in [a, b] such that the following hold. 2 b (b a) b+a (b a)f(x0)+ −2 f ′(ξ0), if x0 = 2 f(x) dx = − 3 6 (5.1) (b a) b+a a (b a)f(x )+ − f (ξ ), if x = . Z − 0 24 ′′ 1 0 2 Thus one point formula is exact for constant polynomial(except mid point rule), so it is called a 0-th order method. 1 2 CHAPTER 5. NUMERICAL INTEGRATION Two point formula-trapezoidal rule: b b a (b a)3 f(x) dx = − (f(a)+ f(b)) − f ′′(ξ). (5.2) 2 − 12 Za This is exact for linear polynomials, hence it is a first order method. Newton-Cotes Rules Assume we have nodes x , ,x in [a, b] are equally spaced. We use an 0 · · · n interpolating polynomial p(x) to replace the integral. b b n n f(x) dx p(x) dx = cip(xi)= cif(xi). a ≈ a Z Z Xi=0 Xi=0 For example, if we use the Lagrange interpolating polynomial, we have n pn(x)= f(xi)Ln,i(x), (5.3) Xi=0 where n (x xj) Ln,i(x)= − , 0 i n. (xi xj) ≤ ≤ i=i Y6 − We let b n b n f(x) dx f(xi) Ln,i(x) dx = Bn,if(xi), a ∼ a Z Xi=0 Z Xi=0 where b Bn,i = Ln,i(x) dx. Za This is the Newton-Cotes formula. If x0 = a and xn = b, then we say it is a closed Newton-Cotes formula. Otherwise, it is called an open Newton-Cotes formula. Mid point rule is an open Newton-Cotes formula. Three point formula-Simpson rule Use an interpolation at three equally spaced points x0,x1,x2 : Let x2 x2 f(x) dx p (x) dx, (5.4) ≈ 2 Zx0 Zx0 5.1. CLOSED NEWTON-COTES FORMULAS 3 where p2(x) is the Lagrange interpolation. For simplicity, we assume x0 = h, x = 0 and x = h. Then − 1 2 x(x h) (x + h)(x h) (x + h)x p = f(x ) − + f(x ) − + f(x ) . 2 0 2h2 1 h2 2 2h2 − Integrating, we obtain h 1 2 2 = 2 (f0 2f1 + f2)x + ( hf0 + hf2)x + 2h dx h 2h − − Z− 1 h3 = (f 2f + f ) + 4h3f 2h2 3 0 − 1 2 1 h = (f + 4f + f ). 3 0 1 2 Hence we get the following rule, called the Simpson’s rule x2 h f(x) dx (f(x ) + 4f(x )+ f(x )) s (f). (5.5) ∼ 3 0 1 2 ≡ 1 Zx0 One can readily check that this is exact for a polynomial up to degree three, even if we used a quadratic polynomial approximation. Hence this is a third order method. In fact one can show that x2 h h5 f(x) dx = (f(x ) + 4f(x )+ f(x )) f (4)(ξ ), ξ [x ,x ]. (5.6) 3 0 1 2 − 90 1 1 ∈ 0 2 Zx0 Similar phenomenon arises for all even n. Derive formula for n = 3 and n = 4. Error of numerical integration We consider Newton-Cotes formula. We assume the following situation: Let a x0 <x1 < <xn b, xi xi 1 = h and consider an approximation ≤ · · · ≤ − − of b f(x)dx by some quadrature based on the data (x ,f(x ), , (x ,f(x )). a 0 0 · · · n n UseR Taylor formula with remainder: (n) (n+1) f (x0) n f (ξ) n+1 f(x)= f(x )+ f ′(x )(x x )+ + (x x ) + (x x ) 0 0 − 0 · · · n! − 0 (n + 1)! − 0 or Newton’s interpolating polynomial pn(f)= f(x0)+f[x0,x1](x x0)+ +f[x0,x1, ,xn](x x0) (x xn 1). − · · · · · · − · · · − − 4 CHAPTER 5. NUMERICAL INTEGRATION By the error formula, we have f(x)= p (f)+ f[x ,x , ,x ,x](x x ) (x x ). n 0 1 · · · n − 0 · · · − n Integrating the error term of Newton’s formula we have n n b b f (n+1)(ξ) E(f)= f[x0,x1, ,xn,x] (x xi)dx = (x xi)dx. a · · · − a (n + 1)! − Z Yi=0 Z Yi=0 Since the term n (x x ) does not change sign on each subinterval (x ,x ), i=0 − i s s+1 we can use meanQ value theorem to see the above quantity is (n+1) ¯ xs+1 n (n+1) ¯ f (ξs) f (ξs) n+2 (x xi)dx = O(h ), (n + 1)! xs − (n + 1)! × Z Yi=0 for some ξ¯ (x ,x ). A more precise error formula is as follows:(See s ∈ s s+1 Issacson-Keller) Theorem 5.1.1. The error by Newton-Cotes formula is n f (n+2)(ξ¯) b (x x ) (x x )dx, if n is even (n + 2)! − 0 − i Za i=0 E(f)= (n+1) b n Y (5.7) f (ξ¯) (x xi)dx, if n is odd. (n + 1)! − Za i=0 Y As noted earlier, we have one higher order of accuracy for even n. Semi-Simpson rule If n is odd, we can approximate xn−1 f(x) dx Zx0 by Simpson’s rule, but to apply Simpson’s rule to xn f(x) dx Zx0 we split the integral into two parts: xn xn−1 xn f(x) dx = f(x) dx + f(x) dx Zx0 Zx0 Zxn−1 5.1. CLOSED NEWTON-COTES FORMULAS 5 and we can apply Simpson’s rule to the first integral. But how to approximate the second integral (we need the same order method)? One idea is to add an extra point, say xn 2 and use a quadratic interpo- − lation: (x xn 1)(x xn) (x xn 2)(x xn) (x xn 2)(x xn 1) p2(x)= fn 2 − − − +fn 1 − − − +fn − − − − . − ( h)( 2h) − (h)( h) (2h)(h) − − − Change of variable: x xn 1 = th gives − − (t 1)(t 2) t(t 1) p2(x)= fn 2 − − fn 1t(t 2) + fn − . − 2 − − − 2 Thus xn 2 (t 1)(t 2) t(t 1) f(x) dx h fn 2 − − fn 1t(t 2) + fn − dt ≈ − 2 − − − 2 Zxn−1 Z1 h = ( f(xn 2) + 8f(xn 1) + 5f(xn)). 12 − − − x1 Ex. Derive an integration rule for x0 f(x) dx using the data at x0,x1 and x (assume h = x x = x x .) 2 1 − 0 2 − 1 R Composite Simpson’s rule If the domain is large, divide it by even number of intervals and applying Simpson’s rule to a pair of subintervals, one can find a more accurate approx- imation. Let x = a + ih, h = (b a)/2n. Then i − b x2 x4 x2n f(x) dx = f(x) dx + f(x) dx + + f(x) dx. · · · Za Zx0 Zx2 Zx2n−2 If Simpson’s rule is used for each integral, we obtain n b h f(x) dx [f(x2i 2) + 4f(x2i 1)+ f(x2i)]. a ∼ 3 − − Z Xi=1 To avoid repetitions it is rearranged as n n h f(x0) + 2 f(x2i 2) + 4 f(x2i 1)+ f(x2n) . 3 " − − # Xi=2 Xi=1 6 CHAPTER 5. NUMERICAL INTEGRATION 5.2 Open Newton-Cotes Formulas b We consider approximation of integral a f(x)dx by interpolating at n + 1 interior points R x = a + h, x = a + 2h, ,x = a + (n + 1)h. 0 1 · · · n Here h = (b a)/(n+2).This rule is useful when we cannot use or do not want − to use end points. 3 (1) n = 0 : b f(x)dx 2hf(x ). Error: h f (ξ) a ≈ 0 3 ′′ R 3 (2) n = 1 : b f(x)dx 3h (f(x )+ f(x )). Error: 3h f (ξ) a ≈ 2 0 1 4 ′′ R 5 (3) n = 2 : b f(x)dx 4h (2f(x ) f(x ) + 2f(x )). Error: 14h f (4)(ξ) a ≈ 3 0 − 1 2 45 R Notice that even cases are more accurate. How to find the coefficients? One way is to integrate the Lagrange inter- polation b n f(x) dx wif(xi), (5.8) a ∼ Z Xi=0 where b wi = Ln,i(x) dx. Za Another method is to let the formula (5.8) be exact for all monomials xi, (i = 0, 1, ,n.) For n = 3 · · · b 5h f(x) dx (11f(x )+ f(x )+ f(x ) + 11f(x )) (5.9) ∼ 24 0 1 2 3 Za Remark 5.2.1. In general, open Cotes rules are used much less than the closed rule. However, there are instances where end points not available. 5.3 Gaussian quadrature-unequal intervals We now consider a quadrature with unequal intervals. Check that the quadra- ture 1 . 1 1 f(x) dx = f( )+ f( ) 1 − 3 3 Z− r r 5.3. GAUSSIAN QUADRATURE-UNEQUAL INTERVALS 7 is exact up to degree 3.