Numerical Analysis: Trapezoidal and Simpson's Rule -.: Mathematical Sciences : UTEP

Numerical Analysis: Trapezoidal and Simpson's Rule -.: Mathematical Sciences : UTEP

Numerical Analysis: Trapezoidal and Simpson's Rule Natasha S. Sharma, PhD Numerical Analysis: Trapezoidal and Simpson's Rule Natasha S. Sharma, PhD Mathematical question we are interested in numerically answering Numerical Analysis: How to we evaluate Trapezoidal and Simpson's Rule Z b Natasha S. I = f (x) dx? Sharma, PhD a Calculus tells us that if F(x) is the antiderivative of a function f (x) on the interval [a; b], then Z b b I = f (x) dx = F (x)ja = F (b) − F (a): a Practically, most integrals cannot be evaluated using this approach. For example, Z 1 dx 5 0 1 + x has a complicated antiderivative and it easier to adopt a numerical method to approximate this integral. Numerical Integration: A General Framework Numerical Analysis: Trapezoidal If you cannot solve a problem, then replace it with a \near-by" and Simpson's Rule problem that you can solve! Natasha S. Our problem: Sharma, PhD Z b Evaluate I = f (x) dx: a To do so, many of the numerical schemes are based on replacing f (x) with some approximate function f~(x) so that Z b I ≈ f~(x) dx = ~I : a Example: f~(x) could be an easy to integrate function approximating f (x). Numerical Integration: A General Framework Numerical Analysis: Then, the approximation error in this case is Trapezoidal and Simpson's Rule Z b Natasha S. E = I − ~I = f (x) − f~(x) dx Sharma, PhD a ≤ (b − a) max jf (x) − f~(x)j a≤x≤b The inequality above tells us that the approximation error E depends on: 1 the maximum error in the approximating f (x) that is maxa≤x≤b jf (x) − f~(x)j, and 2 (b − a), the width of the interval. Next Goal: How to choose f~(x)? Polynomial Approximations to f (x) Numerical Analysis: Trapezoidal and Simpson's Rule Natasha S. Sharma, PhD Goal Choose an approximation f~(x) to f (x) that is easily integrable and a good approximation to f (x). Two natural candidates: 1 Taylor polynomials approximating f (x). One caveat: We need f (x) to have derivatives at \a" to exist of a higher order to improve the approximation! 2 Interpolating polynomials approximating f (x). Example Numerical Analysis: Trapezoidal and Simpson's Example Rule Consider evaluating Natasha S. 1 Sharma, PhD Z 2 I = ex dx 0 Use the Taylor expansion to approximate f (x) = ex2 . That is, t2 tn tn+1 f (x) = 1 + t + + ··· + + ec ; t = x2; 2! n! (n + 1)! | {z } remainder term Rn(x) where c is an unknown number between 0 and t = x2. Solution Numerical Solution: Analysis: Trapezoidal and Simpson's Z 1 x4 x2n Rule I = 1 + x2 + + ··· + dx Natasha S. 0 2! n! Sharma, PhD Z 1 x2(n+1) + ec dx: 0 (n + 1)! Taking n = 3, we have 1 1 1 I = 1 + + + + E = 1:4571 + E; 3 10 42 R 1 x2(n+1) c where E = 0 (n+1)! e dx and we need a bound on this \remainder" term. e Z 1 e 0 < E ≤ x8 dx = = 0:0126: 24 0 216 Using Interpolating Polynomials Numerical Analysis: Trapezoidal and Simpson's In spite of the simplicity of the above example, it is generally Rule Natasha S. more difficult to do numerical integration by constructing Sharma, PhD Taylor polynomial approximations than by constructing polynomial interpolates. Thus, we construct the function f~(x) as the polynomial interpolating f (x) such that Z b Z b f (x) dx ≈ f~(x) dx: a a Case I: Use linear interpolating polynomial p1(x) approximating f (x) at two points. We pick a and b. Using Linear Interpolating Polynomails Numerical Analysis: Trapezoidal ~ and Simpson's f (x) = p1(x) where Rule Natasha S. (b − x)f (a) + (x − a)f (b) Sharma, PhD p (x) = : 1 b − a Thus, Z b Z b f (x) dx ≈ p1(x) dx a a Z b (b − x)f (a) + (x − a)f (b) dx a b − a b − ah i = f (a) + f (b) ≡ T (f ) 2 1 Trapezoidal Rule Numerical Analysis: Definition (Trapezoidal Rule) Trapezoidal and Simpson's Rule The integration rule Natasha S. Sharma, PhD Z b b − ah i f (x) dx ≈ f (a) + f (b) = T1(f ) a 2 is called the trapezoidal rule. Example using Trapezoidal Rule Numerical Analysis: Example Trapezoidal and Simpson's Evaluate Rule Z π=2 Natasha S. sin x dx Sharma, PhD 0 using the trapezoidal rule. Z π=2 π h i sin x dx ≈ sin 0 + sin(π=2) 0 4 = π=4 ≈ 0:785: Since we know the true value R π=2 I = 0 sin x dx = − cos(π=2) + cos(0) = 1, Z π=2 sin x dx − T1(f ) = 1 − 0:785 = 0:215: 0 How to improve the accuracy of the integration rule? Numerical Analysis: Trapezoidal An intuitive solution is to improve the accuracy of f (x) by and Simpson's Rule applying the Trapezoidal rule on smaller subintervals of [a; b] Natasha S. instead of applying it to the original interval [a; b] that is apply Sharma, PhD it to integrals of f (x) on smaller subintervals. For example, let a+b c = 2 then, Z b Z c Z b f (x) dx = f (x) dx + f (x) dx a a c c − ah i b − c h i ≈ f (a) + f (c) + f (c) + f (b) 2 2 hh i = f (a) + 2f (c) + f (b) ≡ T (f ); 2 2 b−a where h = 2 . Testing on the previous example Numerical Analysis: Example Trapezoidal and Simpson's Evaluate Rule Z π=2 Natasha S. I = sin x dx Sharma, PhD 0 using the three point trapezoidal rule. Compute the approximation error I − T2(f ). Please use the Fundamental theorem of calculus to directly calculate I . Z π=2 π h i sin x dx ≈ sin 0 + 2 sin(π=4) + sin(π=2) 0 8 ≈ 0:9481: Z π=2 sin x dx − T2(f ) ≈ 1 − 0:9481 = 0:0519: 0 General Trapezoidal Rule Tn(f ) Numerical Analysis: Trapezoidal and Simpson's Rule 1 We saw the trapezoidal rule T1(f ) for 2 points a and b. Natasha S. 2 The rule T (f ) for 3 points involves three equidistant Sharma, PhD 2 a+b points: a, 2 and b. 3 We observed the improvement in the accuracy of T2(f ) over T1(f ) so inspired by this, we would like to apply this rule to n + 1 equally spaced points a = x0 < x1 < x2 ··· xn = b with the space between any two points being denoted by h that is h = xi+1 − xi ; i = 0; ··· ; n: General Trapezoidal Rule Tn(f ) Numerical Analysis: Trapezoidal and Simpson's Rule Natasha S. Definition Sharma, PhD h1 f (b)i I ≈ h f (a) + f (x ) + ··· f (x ) + ≡ T (f ) 2 1 n−1 2 n 1 The subscript \n" refers to the number of subintervals being used; 2 the points x0; x1; ··· xn are called the numerical integration node points. Performance of Tn(f ) Numerical Analysis: Trapezoidal and Simpson's R π=2 Rule f (x) = sin x we want to approximate I = 0 f (x) dx using Natasha S. the trapezoidal rule Tn(f ) Sharma, PhD n Tn(f ) I − Tn(f ) Ratio 1 0.785 2.15e-1 { 2 0.948 5.18e-2 4.13 4 0.987 1.29e-2 4.03 8 0.997 3.21e-3 4.01 16 .999 8.03e-04 4.00 Note that the errors are decreasing by a constant factor of 4. Why do we always double n? How to improve the accuracy of the integration rule? Numerical An intuitive solution is to improve the accuracy of f (x) by Analysis: Trapezoidal using a better interpolating polynomial say a quadratic and Simpson's Rule a+b b−a polynomial p2(x) instead. Let c = 2 and h = 2 then, the Natasha S. Sharma, PhD quadratic polynomial is (x − c)(x − b) (x − a)(x − b) p (x) = f (a) + f (c) 2 (a − c)(a − b) (c − a)(c − b) (x − a)(x − c) + f (b): (b − a)(b − c) Z b Z b f (x) dx ≈ p2(x) dx a a hh i = f (a) + 4f (c) + f (b) ≡ S (f ): 3 2 This is called Simpson's rule. Simpson's rule applied to the previous example Numerical Analysis: Trapezoidal Example and Simpson's Rule Evaluate Natasha S. Z π=2 Sharma, PhD sin x dx 0 using the Simpson's rule. Z π=2 π=2h i sin x dx ≈ sin 0 + 4 sin(π=4) + sin(π=2) 0 3 ≈ 1:00227 Z π=2 sin x dx − S2(f ) = −0:00228: 0 General Simpson's Rule Sn(f ) Numerical Analysis: Trapezoidal and Simpson's Rule Natasha S. Sharma, PhD Definition hh I ≈ f (a) + 4f (x ) + 2f (x ) + 4f (x ) + 2f (x ) + 4f (x ) ··· 3 1 2 3 4 5 i ··· 4f (xn−1) + f (b) ≡ Sn(f ) Performance of Sn(f ) Numerical Analysis: Trapezoidal and Simpson's Rule Natasha S. For f (x) = sin x we want to approximate I = R π=2 f (x) dx Sharma, PhD 0 using the Simpson's rule Sn(f ) n Sn(f ) I − Sn(f ) Ratio 2 1.00227 -2.28e-3 { 4 1.00013 -1.35e-4 16.94 8 1.00000 -8.3e-6 16.22 16 1.00000 -5.17e-7 16.06 Error Formulas: Trapezoidal Rule Numerical Analysis: Trapezoidal and Simpson's Rule Theorem Natasha S.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    28 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us