Truncation errors: using Taylor series to approximation functions
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) π !
Taylor Series Taylor Series approximation about point π¦ ! = 0 π π¦ = π ! + π " π¦ + π # π¦ # + π $ π¦ $ + π % π¦ % + β― π π¦ = π 0 + π " 0 π¦ + π "" 0 π¦ $ + π """ 0 π¦ % + β― 2! 3! - π ) (0) π¦ ) π π¦ = 0 π! )+, Demo βPolynomial Approximation with Derivativesβ β Part 1
Taylor Series In a more general form, the Taylor Series approximation about point π¦ ! is given by: π π¦ = π π¦ ! + π $ π¦ ! (π¦ β π¦ ! ) + π $$ π¦ ! (π¦ β π¦ ! ) # + π $$$ π¦ ! (π¦ β π¦ ! ) % + β― 2! 3! - π ) (π¦ ! ) (π¦ β π¦ ! ) ) π π¦ = 0 π! )+,
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
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 &'(
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 π! &'(
Demo: Polynomial Approximation with Derivatives
Demo: Polynomial Approximation with Derivatives
Iclicker question A) B) C) D) E) Demo βTaylor of exp(x) about 2β
Demo βPolynomial Approximation with Derivativesβ β Part 3 Making error predictions
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
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
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
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β
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
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?
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 π¦ .
Demo: Finite Difference ππ π ππ β π π¦ = π 0 β 2 We want to obtain an approximation for πβ² 1 ππππ¦πππ’ = π 0 ππππππ ππ¦ = π 0*1 β 2 β (π 0 β2) β ππ π ππ (β) = πππ‘(ππππ¦πππ’ β ππππππ ππ¦) ππ π ππ < π "" π β 2 truncation error
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?
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 π )
ππ π ππ ~π β Truncation error: Minimize the error 2 2π β + π β 2 ππ π ππ ~ 2π Gives Rounding error: β = 2 π/π β
Recommend
More recommend