22
Truncation errors: using Taylor series to approximate functions

Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

Truncation errors: using Taylor series to approximate functions

Page 2: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

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) (,

!/5 0 = (4×3×2) (-

!///(#) = 3×2 (, + (4×3×2)(- # +⋯!/5(#) = (4×3×2)(- +⋯

or f" '

ei ! ai

L4ai=f"Yi!T

f "

fixCi - it x Ci - r ) x. . . x1) ai

Page 3: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

Taylor SeriesTaylor Series approximation about point !" = 0

% ! =&'()

*+' !'

% ! = +" + +- ! + +. !. + +/ !/ + +0 !0 + ⋯

⇒fas÷÷÷÷TI→ approximate function values

→ approximate derivatives

→ estimating errors

Page 4: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

Taylor Series

! " = ! "$ + !& "$ (" − "$) +!&& "$2! (" − "$),+

!&&& 03! (" − "$)/+⋯

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

! " =1234

5 ! 2 ("$)6! (" − "$)2

Page 5: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

Example: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 ∀ 0 ≥ 3

Evaluate ! 4 _fI x) = f Go) t f'

ED G - Xo ) tf "z G - xo5tfHMake x = A and Xo = I

f- (4) = fu ) t f 'Ll) C4 - D t ft ) (4 - D'

= 2 t f - 3) ( 4- Dt 2414-D2

= 2 - 9 t 18 ⇒/fl4)=HJ

Page 6: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

Taylor SeriesWe cannot sum infinite number of terms, and therefore we have to truncate.

How big is the error caused by truncation? Let’s write ℎ = # − #%x = ht Xo

-

ffxoth)=fGDtf'GDhtf¥hit h't -- -

t÷t"fh+÷i.

hi

exact - -

truncated part what we are neglecting(Taylor approximation error

ffx) of degree n )

thx )

Page 7: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

Taylor series with remainderLet ! be (# + 1)-times differentiable on the interval ('(, ') with !(*)continuous on ['(, '], and ℎ = ' − '(error = exact - approximation

error = fat - tn Cx ) = ¥÷, f"f hi

ht 2

=f h

" "

+ f"o ) h + . . .

( ht2) !

-dominant term when h → o Cor x → to )

error f M h" "

or error = O I hit'

)

Page 8: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

Taylor series with remainderLet ! be (# + 1)-times differentiable on the interval ('(, ') with !(*)continuous on ['(, '], and ℎ = ' − '(error = exact - approximation

Remainder Theorem : Rnlx) =FG ) - tncx )

=÷:S . ii

/RnH=fII,Its*1-where BE ( Xo ,

x )

}since 15-xd E h

iris it'ttII¥D

Page 9: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

Graphical representation:

tix )f f' Go)=d¥ → dy = f

'

GD ( x - Xo )

\•Ferrier t

,=f Gd t f' Go )( X - Xo ) V

A

go.ua#iIIdYerror=fCD-tiCDa--Remainder

YI [email protected] )I I

f' GD'

i !/error=0(h#tangentatxoi

, -I I

" !>

supposeinterval is reduced by half .

% Xwhat happens to the error ?

÷ ÷ '¥¥I

Page 10: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

Example:Given the function

! " = 1(20" − 10)

Write the Taylor approximation of degree 2 about point "* = 0

found

Given the function : FG ) = 120X - LO

write the Taylor approximation of degree 2 about to = o

¥47joking;tho ) =

. 's

G) =

-1204%1726,492=¥g÷o ,

f' 'lol = -9%7=-45

ftdxk-f-shx-EIE.TT trackf"z x'I errors OH )

-

Page 11: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

-3- to

. .

µ-

Z10-1

-

y= ax

!error log

bogeys-

- liogcatbwlogcx)

Islope !b=bfg:fg:

= III. =3

,→ error -

- ou 's r

Page 12: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

Example:Given the function

! " = −"% + 1

Write the Taylor approximation of degree 2 about point "( = 0

IDENT

AH = ft xo) tf'GDC x - xD tf "f ( x - * It - - -

f- ( o ) = I

f-' G) = ¥C- x 't 15

"

= - X ( I - Ej" '

→ ft Co) = o

f"

A) = C I- Ej"

EH - a - xD" "

→ f''

to ) = -

A

thx) = I - zcx5 or /tdD=I-I

Page 13: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

! " = −"% + 1error = tz - Hx )

O

{t2

¥

"

good"

approximation close to xo = o

! '

error increases when x moves away from to

-use log-hog plot to better visualize what is happening

Close to to.

Page 14: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

error = thx ) - far )

f- G) =NETT

- no-5

thx ) = t - %

-1-0-9IRat s

ITHI.li/⇐

Olli)

3 !

here h =X - Xo =

X

Let's get Big-0 of error from the plot !

sbr-tfggfj.bg:7?-=-.s.IL--4

→ error -

- och" )

what happened here !

→ I"

G) = o hence the next term that is not

zero is f'

*G)

Page 15: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

Example:

A)B)C)D)E)

Demo “Taylor of exp(x) about 2”

IDEMOJ

error = e' I ¥75'ta÷5t - -- ]

t#error = Off-29 )

* ef.MG - 24as x → 2

,

e becomessmaller

* e E M x"

} all are valid options !as × → 2 ,

ears does not

show asymptoticbehavior

- this is .

tightestbound .

Page 16: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

Finite difference approximationFor 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:

Can we find an approximation for the derivative with the available information? YES !

Caldasf'

G) = ¥¥fffGth)h-f#)

Can we simply use f'G) a fCxth)h-f# and make

h small ? How do we choose h ?

what is the error ?

Page 17: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

f : IR → IR and f is smooth I h : small change#tur baton )K

to X .

- Taylor Series :

f- ( x the) = HHtf

!x) h tfz h 't.. . Cjcest replaced to with x )

f- ( x th ) flex ) tf'

G) h . to Chi )

ffxth ) - f G)=

f'

G) to Ch ) → f'G) =fGth) - Och)

: - -

-error

he extract -

fdf¥f¥fFITTED# F. D. approx )

/errordue\to FD approx

⇒ et = 01h )-

Page 18: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

Demo: Finite Difference

! " = $% − 2

(!$")*+ = $%

(!),,-." = $%/0 − 2 − ($%−2)ℎ

$--.-(ℎ) = )45((!$")*+ − (!),,-.")

We want to obtain an approximation for !′ 1

$--.- < !99 : ℎ2

truncation error

IE IE's

Page 19: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

Demo: Finite Difference

! " = $% − 2

(!$")*+ = $%

(!),,-." = $%/0 − 2 − ($%−2)ℎ

$--.-(ℎ) = )45((!$")*+ − (!),,-.")

We want to obtain an approximation for !′ 1

ℎ $--.-

$--.- < !99 : ℎ2

truncation error

Demo

I I

↳ absolute error !

Page 20: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

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+→,$ & + ℎ − $(&)

~ error =Och )

I

Page 21: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

Uh-Oh!What happened here?

! " = $% − 2

!′ " = $% → !′ 1 ≈ 2.7

!′ 1 = lim1→2

! 1 + ℎ − !(1)ℎ①

-managing:Freeman.

D very small h Chiao"

)

f- ( Ith ) - to ) →starts increasing

losingprecision due to cancelation !

2) even smaller Chf to- "

) → f C Ith ) = fu ) → If = O

I machine epsilon C because we are adding

h to I.

If another FP number,

than this would

be the gap .

Page 22: Truncation errors: using Taylor series to approximate ...Let’s say we want to approximate a function !(#)with a polynomial For simplicity, assume we know the function value and its

!""#"~%ℎ2Truncation error:

Rounding error: !""#"~2(ℎ

I

I

'

-8I 10

in

h =

Eh⇒ HIE

h -- NI

f- ( Ith ) - fu ) h =NIF

- -8h he to