Truncation errors: using Taylor series to approximation functions - - PowerPoint PPT Presentation
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 = ! + " + # # + $
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,
Approximating functions using polynomials:
π π¦ = π! + π" π¦ + π# π¦# + π$ π¦$ + π% π¦% + β―
π 0 = π!
π" π¦ = π# + 2 π$ π¦ + 3 π% π¦$ + 4 π& π¦% + β―
πβ² 0 = π"
π""(π¦) = 2 π$ + 3Γ2 π% π¦ + (4Γ3)π& π¦$ + β―
πβ²β² 0 = 2 π#
πβ²β²β² 0 = (3Γ2) π! π"# 0 = (4Γ3Γ2) π$
π"""(π¦) = 3Γ2 π% + (4Γ3Γ2)π& π¦ + β― π"'(π¦) = (4Γ3Γ2)π& + β― π()) 0 = π! π)
Taylor Series
π π¦ = π 0 + π" 0 π¦ + π"" 0 2! π¦$ + π""" 0 3! π¦% + β―
Taylor Series approximation about point π¦! = 0
π π¦ = 0
)+,
- π ) (0)
π! π¦)
Demo βPolynomial Approximation with Derivativesβ β Part 1
π π¦ = π! + π" π¦ + π# π¦# + π$ π¦$ + π% π¦% + β―
Taylor Series
π π¦ = π π¦! + π$ π¦! (π¦ β π¦!) + π$$ π¦! 2! (π¦ β π¦!)#+ π$$$ π¦! 3! (π¦ β π¦!)%+ β―
In a more general form, the Taylor Series approximation about point π¦! is given by:
π π¦ = 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
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
&')*+ ,
π & (π¦%) π! (β)& π π¦% + β β 0
&'( ) π & π¦%
π! β & β€ C 5 β)*+
And as β β 0 we write:
Error due to Taylor approximation of degree n
π π¦% + β β 0
&'( ) π & π¦%
π! β & = π(β)*+)
Demo βPolynomial Approximation with Derivativesβ β Part 2
Taylor series with remainder
π π¦% + β β 0
&'( ) π & π¦%
π! β & = 0
&')*+ ,
π & (π¦%) π! (β)&
Let π be (π + 1)-times differentiable on the interval (π¦!, π¦) with π(') continuous on [π¦!, π¦], and β = π¦ β π¦! Then there exists a π β (π¦!, π¦) so that
π π¦% + β β 0
&'( ) π & π¦%
π! β & = π )*+ (π) (π + 1)! (π β π¦%))*+
And since π β π¦! β€ β
π π¦% + β β 0
&'( ) π & π¦%
π! β & β€ π )*+ (π) (π + 1)! (β))*+
Taylor remainder π π¦ β π π¦ = π(π¦)
Demo: Polynomial Approximation with Derivatives
Demo: Polynomial Approximation with Derivatives
Iclicker question
A) B) C) D) E)
Demo βTaylor of exp(x) about 2β
Making error predictions
Demo βPolynomial Approximation with Derivativesβ β Part 3
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 8 π¦ β 2 " β 5 4 π¦ β 2 # + 25 32 π¦ β 2 $ + O((π¦ β 2)%)
Therefore the Taylor polynomial of order 4 is given by
π’ π¦ = 5 2 β 5 2 π¦ β 2 ! + 15 8 π¦ β 2 "
where the first derivative is
π’"(π¦) = β5 π¦ β 2 + 15 2 π¦ β 2 !
1 2 3 4 2 4 6 8
π π¦ π’ π¦
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 (note that the exact value is π" 2.3 = β1.31444
1 2 3 4 2 4 6 8
π π¦ π’ π¦ What happens if we want to use the same method to approximate πβ² 3 ?
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
Iclicker question
Computing integrals using Taylor Series
A function π π¦ is approximated by a Taylor polynomial of order π around π¦ = 0.
π’) = 0
&'( ) π & 0
π! π¦ &
We can find an approximation for the integral β«
. / π π¦ ππ¦ by integrating the
polynomial: Where we can use β«
. / π¦0 ππ¦ = /()* 0-" β .()* 0-"
Demo βComputing PI with Taylorβ
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
Iclicker question
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> ?
A
? How do we choose β? Can we get 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 ππππ¦πππ’ = π0 ππππππ ππ¦ = π0*1 β 2 β (π0β2) β ππ π ππ (β) = πππ‘(ππππ¦πππ’ β ππππππ ππ¦) We want to obtain an approximation for πβ² 1
β ππ π ππ
ππ π ππ < π"" π β 2
truncation error
Demo: Finite Difference
Should we just keep decreasing the perturbation β, in order to approach the limit β β 0 and obtain a better approximation for the derivative?
πβ² π¦ = lim
+β-
π π¦ + β β π(π¦) β
Uh-Oh!
What happened here? π π¦ = π0 β 2 πβ² π¦ = π0 β πβ² 1 β 2.7
πβ² 1 = lim
+β-
π 1 + β β π(1) β
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 π)
ππ π ππ ~π β 2
Truncation error: Rounding error:
ππ π ππ ~ 2π β
Minimize the error 2π β + π β 2 Gives β = 2 π/π