truncation errors using taylor series to approximation
play

Truncation errors: using Taylor series to approximation functions - PowerPoint PPT Presentation

Truncation errors: using Taylor series to approximation functions Approximating functions using polynomials: Lets say we want to approximate a function () with a polynomial = ! + " + # # + $


  1. Truncation errors: using Taylor series to approximation functions

  2. Approximating functions using polynomials: Let’s say we want to approximate a function 𝑔(𝑦) with a polynomial 𝑔 𝑦 = 𝑏 ! + 𝑏 " 𝑦 + 𝑏 # 𝑦 # + 𝑏 $ 𝑦 $ + 𝑏 % 𝑦 % + β‹― For simplicity, assume we know the function value and its derivatives at 𝑦 ! = 0 (we will later generalize this for any point). Hence, 𝑔 " 𝑦 = 𝑏 # + 2 𝑏 $ 𝑦 + 3 𝑏 % 𝑦 $ + 4 𝑏 & 𝑦 % + β‹― 3Γ—2 𝑏 % 𝑦 + (4Γ—3)𝑏 & 𝑦 $ + β‹― 𝑔 "" (𝑦) = 2 𝑏 $ + 𝑔 """ (𝑦) = 3Γ—2 𝑏 % + (4Γ—3Γ—2)𝑏 & 𝑦 + β‹― 𝑔 "' (𝑦) = (4Γ—3Γ—2)𝑏 & + β‹― 𝑔 "# 0 = (4Γ—3Γ—2) 𝑏 $ 𝑔 0 = 𝑏 ! 𝑔′′ 0 = 2 𝑏 # 𝑔 ()) 0 = 𝑗! 𝑏 ) 𝑔′ 0 = 𝑏 " 𝑔′′′ 0 = (3Γ—2) 𝑏 !

  3. Taylor Series Taylor Series approximation about point 𝑦 ! = 0 𝑔 𝑦 = 𝑏 ! + 𝑏 " 𝑦 + 𝑏 # 𝑦 # + 𝑏 $ 𝑦 $ + 𝑏 % 𝑦 % + β‹― 𝑔 𝑦 = 𝑔 0 + 𝑔 " 0 𝑦 + 𝑔 "" 0 𝑦 $ + 𝑔 """ 0 𝑦 % + β‹― 2! 3! - 𝑔 ) (0) 𝑦 ) 𝑔 𝑦 = 0 𝑗! )+, Demo β€œPolynomial Approximation with Derivatives” – Part 1

  4. Taylor Series In a more general form, the Taylor Series approximation about point 𝑦 ! is given by: 𝑔 𝑦 = 𝑔 𝑦 ! + 𝑔 $ 𝑦 ! (𝑦 βˆ’ 𝑦 ! ) + 𝑔 $$ 𝑦 ! (𝑦 βˆ’ 𝑦 ! ) # + 𝑔 $$$ 𝑦 ! (𝑦 βˆ’ 𝑦 ! ) % + β‹― 2! 3! - 𝑔 ) (𝑦 ! ) (𝑦 βˆ’ 𝑦 ! ) ) 𝑔 𝑦 = 0 𝑗! )+,

  5. Iclicker question Assume a finite Taylor series approximation that converges everywhere for a given function 𝑔(𝑦) and you are given the following information: 𝑔 1 = 2; 𝑔 & (1) = βˆ’3; 𝑔 && (1) = 4; 𝑔 ' 1 = 0 βˆ€ π‘œ β‰₯ 3 Evaluate 𝑔 4 A) 29 B) 11 C) -25 D) -7 E) None of the above

  6. Demo β€œPolynomial Approximation with Derivatives” – Part 2 Taylor Series We cannot sum infinite number of terms, and therefore we have to truncate . How big is the error caused by truncation? Let’s write β„Ž = 𝑦 βˆ’ 𝑦 ! ) 𝑔 & 𝑦 % , 𝑔 & (𝑦 % ) β„Ž & = 0 (β„Ž) & 𝑔 𝑦 % + β„Ž βˆ’ 0 𝑗! 𝑗! &'( &')*+ ) 𝑔 & 𝑦 % And as β„Ž β†’ 0 we write: β„Ž & ≀ C 5 β„Ž )*+ 𝑔 𝑦 % + β„Ž βˆ’ 0 𝑗! &'( ) 𝑔 & 𝑦 % Error due to Taylor β„Ž & = 𝑃(β„Ž )*+ ) approximation of 𝑔 𝑦 % + β„Ž βˆ’ 0 𝑗! degree n &'(

  7. Taylor series with remainder Let 𝑔 be (π‘œ + 1) - times differentiable on the interval (𝑦 ! , 𝑦) with 𝑔 (') continuous on [𝑦 ! , 𝑦] , and β„Ž = 𝑦 βˆ’ 𝑦 ! ) 𝑔 & 𝑦 % , 𝑔 & (𝑦 % ) β„Ž & = 0 (β„Ž) & 𝑔 𝑦 % + β„Ž βˆ’ 0 𝑗! 𝑗! &'( &')*+ Then there exists a 𝜊 ∈ (𝑦 ! , 𝑦) so that ) 𝑔 & 𝑦 % β„Ž & = 𝑔 )*+ (𝜊) (π‘œ + 1)! (𝜊 βˆ’ 𝑦 % ) )*+ 𝑔 𝑦 % + β„Ž βˆ’ 0 𝑔 𝑦 βˆ’ π‘ˆ 𝑦 = 𝑆(𝑦) 𝑗! &'( And since 𝜊 βˆ’ 𝑦 ! ≀ β„Ž Taylor remainder ) 𝑔 & 𝑦 % β„Ž & ≀ 𝑔 )*+ (𝜊) (π‘œ + 1)! (β„Ž) )*+ 𝑔 𝑦 % + β„Ž βˆ’ 0 𝑗! &'(

  8. Demo: Polynomial Approximation with Derivatives

  9. Demo: Polynomial Approximation with Derivatives

  10. Iclicker question A) B) C) D) E) Demo β€œTaylor of exp(x) about 2”

  11. Demo β€œPolynomial Approximation with Derivatives” – Part 3 Making error predictions

  12. Using Taylor approximations to obtain derivatives Let’s say a function has the following Taylor series expansion about 𝑦 = 2 . 𝑔 𝑦 = 5 2 βˆ’ 5 2 𝑦 βˆ’ 2 ! + 15 𝑦 βˆ’ 2 " βˆ’ 5 4 𝑦 βˆ’ 2 # + 25 32 𝑦 βˆ’ 2 $ + O((𝑦 βˆ’ 2) % ) 8 Therefore the Taylor polynomial of order 4 is given by 𝑒 𝑦 = 5 2 βˆ’ 5 2 𝑦 βˆ’ 2 ! + 15 𝑦 βˆ’ 2 " 𝑒 𝑦 8 8 where the first derivative is 6 4 𝑒 " (𝑦) = βˆ’5 𝑦 βˆ’ 2 + 15 𝑦 βˆ’ 2 ! 2 2 𝑔 𝑦 1 2 3 4

  13. Using Taylor approximations to obtain derivatives We can get the approximation for the derivative of the function 𝑔 𝑦 using the derivative of the Taylor approximation: 𝑒 " (𝑦) = βˆ’5 𝑦 βˆ’ 2 + 15 𝑦 βˆ’ 2 ! 2 For example, the approximation for 𝑔′ 2.3 is 𝑔 " 2.3 β‰ˆ 𝑒 " 2.3 = βˆ’1.2975 𝑒 𝑦 8 6 (note that the exact value is 𝑔 " 2.3 = βˆ’1.31444 4 2 What happens if we want to use the same method to 𝑔 𝑦 approximate 𝑔′ 3 ? 1 2 3 4

  14. Iclicker question The function 𝑔 𝑦 = cos 𝑦 𝑦 # + )*+(#,) ,-#, & ' is approximated by the following Taylor polynomial of degree π‘œ = 2 about 𝑦 = 2Ο€ 𝑒 - 𝑦 = 39.4784 + 12.5664 𝑦 βˆ’ 2Ο€ βˆ’ 18.73922 𝑦 βˆ’ 2𝜌 - Determine an approximation for the first derivative of 𝑔 𝑦 at 𝑦 = 6.1 A) 18.7741 B) 12.6856 C) 19.4319 D) 15.6840

  15. Computing integrals using Taylor Series A function 𝑔 𝑦 is approximated by a Taylor polynomial of order π‘œ around 𝑦 = 0 . ) 𝑔 & 0 𝑦 & 𝑒 ) = 0 𝑗! &'( / 𝑔 𝑦 𝑒𝑦 by integrating the We can find an approximation for the integral ∫ . polynomial: / 𝑦 0 𝑒𝑦 = / ()* . ()* 0-" βˆ’ Where we can use ∫ . 0-" Demo β€œComputing PI with Taylor”

  16. Iclicker question A function 𝑔 𝑦 is approximated by the following Taylor polynomial: 𝑒 . 𝑦 = 10 + 𝑦 βˆ’ 5 𝑦 - βˆ’ 𝑦 ! 2 + 5𝑦 $ 12 + 𝑦 . 24 βˆ’ 𝑦 / 72 " 𝑔 𝑦 𝑒𝑦 Determine an approximated value for ∫ 1% A) -10.27 B) -11.77 C) 11.77 D) 10.27

  17. Finite difference approximation For a given smooth function 𝑔 𝑦 , we want to calculate the derivative 𝑔′ 𝑦 at 𝑦 = 1. Suppose we don’t know how to compute the analytical expression for 𝑔′ 𝑦 , but we have available a code that evaluates the function value: We know that: 𝑔 𝑦 + β„Ž βˆ’ 𝑔(𝑦) 𝑔′ 𝑦 = lim β„Ž 2β†’4 Can we just use 𝑔′ 𝑦 β‰ˆ > ?@A B> ? ? How do we choose β„Ž ? Can we get A estimate the error of our approximation?

  18. For a differentiable function 𝑔: β„› β†’ β„› , the derivative is defined as: 𝑔 𝑦 + β„Ž βˆ’ 𝑔(𝑦) 𝑔′ 𝑦 = lim β„Ž +β†’- Let’s consider the finite difference approximation to the first derivative as 𝑔′ 𝑦 β‰ˆ 𝑔 𝑦 + β„Ž βˆ’ 𝑔 𝑦 β„Ž Where β„Ž is often called a β€œperturbation”, i.e. a β€œsmall” change to the variable 𝑦 . By the Taylor’s theorem we can write: 𝑔 𝑦 + β„Ž = 𝑔 𝑦 + 𝑔 . 𝑦 β„Ž + 𝑔′′(𝜊) β„Ž ! 2 For some 𝜊 ∈ [𝑦, 𝑦 + β„Ž] . Rearranging the above we get: 𝑔 . 𝑦 = 𝑔 𝑦 + β„Ž βˆ’ 𝑔(𝑦) βˆ’ 𝑔′′(𝜊) β„Ž β„Ž 2 + Therefore, the truncation error of the finite difference approximation is bounded by M ! , where M is a bound on 𝑔 .. 𝜊 for 𝜊 near 𝑦 .

  19. Demo: Finite Difference 𝑓𝑠𝑠𝑝𝑠 β„Ž 𝑔 𝑦 = 𝑓 0 βˆ’ 2 We want to obtain an approximation for 𝑔′ 1 𝑒𝑔𝑓𝑦𝑏𝑑𝑒 = 𝑓 0 π‘’π‘”π‘π‘žπ‘žπ‘ π‘π‘¦ = 𝑓 0*1 βˆ’ 2 βˆ’ (𝑓 0 βˆ’2) β„Ž 𝑓𝑠𝑠𝑝𝑠(β„Ž) = 𝑏𝑐𝑑(𝑒𝑔𝑓𝑦𝑏𝑑𝑒 βˆ’ π‘’π‘”π‘π‘žπ‘žπ‘ π‘π‘¦) 𝑓𝑠𝑠𝑝𝑠 < 𝑔 "" 𝜊 β„Ž 2 truncation error

  20. Demo: Finite Difference Should we just keep decreasing the perturbation β„Ž , 𝑔 𝑦 + β„Ž βˆ’ 𝑔(𝑦) 𝑔′ 𝑦 = lim in order to approach the limit β„Ž β†’ 0 and obtain a β„Ž +β†’- better approximation for the derivative?

  21. What happened here? Uh-Oh ! 𝑔 𝑦 = 𝑓 0 βˆ’ 2 𝑔′ 𝑦 = 𝑓 0 β†’ 𝑔′ 1 β‰ˆ 2.7 𝑔 1 + β„Ž βˆ’ 𝑔(1) 𝑔′ 1 = lim β„Ž +β†’- Rounding error! 1) for a β€œvery small” β„Ž ( β„Ž < πœ— ) β†’ 𝑔 1 + β„Ž = 𝑔(1) β†’ 𝑔′ 1 = 0 2) for other still β€œsmall” β„Ž ( β„Ž > πœ— ) β†’ 𝑔 1 + β„Ž βˆ’ 𝑔 1 gives results with fewer significant digits (We will later define the meaning of the quantity πœ— )

  22. 𝑓𝑠𝑠𝑝𝑠~𝑁 β„Ž Truncation error: Minimize the error 2 2πœ— β„Ž + 𝑁 β„Ž 2 𝑓𝑠𝑠𝑝𝑠~ 2πœ— Gives Rounding error: β„Ž = 2 πœ—/𝑁 β„Ž

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