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

β–Ά
truncation errors using taylor series to approximation
SMART_READER_LITE
LIVE PREVIEW

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 = ! + " + # # + $


slide-1
SLIDE 1

Truncation errors: using Taylor series to approximation functions

slide-2
SLIDE 2

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 = 𝑗! 𝑏)

slide-3
SLIDE 3

Taylor Series

𝑔 𝑦 = 𝑔 0 + 𝑔" 0 𝑦 + 𝑔"" 0 2! 𝑦$ + 𝑔""" 0 3! 𝑦% + β‹―

Taylor Series approximation about point 𝑦! = 0

𝑔 𝑦 = 0

)+,

  • 𝑔 ) (0)

𝑗! 𝑦)

Demo β€œPolynomial Approximation with Derivatives” – Part 1

𝑔 𝑦 = 𝑏! + 𝑏" 𝑦 + 𝑏# 𝑦# + 𝑏$ 𝑦$ + 𝑏% 𝑦% + β‹―

slide-4
SLIDE 4

Taylor Series

𝑔 𝑦 = 𝑔 𝑦! + 𝑔$ 𝑦! (𝑦 βˆ’ 𝑦!) + 𝑔$$ 𝑦! 2! (𝑦 βˆ’ 𝑦!)#+ 𝑔$$$ 𝑦! 3! (𝑦 βˆ’ 𝑦!)%+ β‹―

In a more general form, the Taylor Series approximation about point 𝑦! is given by:

𝑔 𝑦 = 0

)+,

  • 𝑔 ) (𝑦!)

𝑗! (𝑦 βˆ’ 𝑦!))

slide-5
SLIDE 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

slide-6
SLIDE 6

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

slide-7
SLIDE 7

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 𝑔 𝑦 βˆ’ π‘ˆ 𝑦 = 𝑆(𝑦)

slide-8
SLIDE 8

Demo: Polynomial Approximation with Derivatives

slide-9
SLIDE 9

Demo: Polynomial Approximation with Derivatives

slide-10
SLIDE 10

Iclicker question

A) B) C) D) E)

Demo β€œTaylor of exp(x) about 2”

slide-11
SLIDE 11

Making error predictions

Demo β€œPolynomial Approximation with Derivatives” – Part 3

slide-12
SLIDE 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 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

𝑔 𝑦 𝑒 𝑦

slide-13
SLIDE 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 (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 ?

slide-14
SLIDE 14

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

slide-15
SLIDE 15

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”

slide-16
SLIDE 16

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

slide-17
SLIDE 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> ?

A

? How do we choose β„Ž? Can we get estimate the error of our approximation?

slide-18
SLIDE 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 𝑦.

slide-19
SLIDE 19

Demo: Finite Difference

𝑔 𝑦 = 𝑓0 βˆ’ 2 𝑒𝑔𝑓𝑦𝑏𝑑𝑒 = 𝑓0 π‘’π‘”π‘π‘žπ‘žπ‘ π‘π‘¦ = 𝑓0*1 βˆ’ 2 βˆ’ (𝑓0βˆ’2) β„Ž 𝑓𝑠𝑠𝑝𝑠(β„Ž) = 𝑏𝑐𝑑(𝑒𝑔𝑓𝑦𝑏𝑑𝑒 βˆ’ π‘’π‘”π‘π‘žπ‘žπ‘ π‘π‘¦) We want to obtain an approximation for 𝑔′ 1

β„Ž 𝑓𝑠𝑠𝑝𝑠

𝑓𝑠𝑠𝑝𝑠 < 𝑔"" 𝜊 β„Ž 2

truncation error

slide-20
SLIDE 20

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

+β†’-

𝑔 𝑦 + β„Ž βˆ’ 𝑔(𝑦) β„Ž

slide-21
SLIDE 21

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 πœ—)

slide-22
SLIDE 22

𝑓𝑠𝑠𝑝𝑠~𝑁 β„Ž 2

Truncation error: Rounding error:

𝑓𝑠𝑠𝑝𝑠~ 2πœ— β„Ž

Minimize the error 2πœ— β„Ž + 𝑁 β„Ž 2 Gives β„Ž = 2 πœ—/𝑁