Truncation Errors and the Taylor Series Chapter 4

  • Slides: 9
Download presentation
Truncation Errors and the Taylor Series Chapter 4 1 Copyright © 2006 The Mc.

Truncation Errors and the Taylor Series Chapter 4 1 Copyright © 2006 The Mc. Graw-Hill Companies, Inc. Permission required for reproduction or display.

How does a CPU compute the following functions for a specific x value? cos(x)

How does a CPU compute the following functions for a specific x value? cos(x) sin(x) ex log(x) etc. • Non-elementary functions such as trigonometric, exponential, and others are expressed in an approximate fashion using Taylor series when their values, derivatives, and integrals are computed. • Taylor series provides a means to predict the value of a function at one point in terms of the function value and its derivatives at another point. 2 Copyright © 2006 The Mc. Graw-Hill Companies, Inc. Permission required for reproduction or display.

Taylor Series (nth order approximation): The Reminder term, Rn, accounts for all terms from

Taylor Series (nth order approximation): The Reminder term, Rn, accounts for all terms from (n+1) to infinity. Define the step size as h=(xi+1 - xi), the series becomes: 3 Copyright © 2006 The Mc. Graw-Hill Companies, Inc. Permission required for reproduction or display.

Any smooth function can be approximated as a polynomial. Take x = xi+1 Then

Any smooth function can be approximated as a polynomial. Take x = xi+1 Then f(x) ≈ f(xi) zero order approximation first order approximation Second order approximation: nth order approximation: • Each additional term will contribute some improvement to the approximation. Only if an infinite number of terms are added will the series yield an exact result. • In most cases, only a few terms will result in an approximation that is close enough to the true value for practical purposes Copyright © 2006 The Mc. Graw-Hill Companies, Inc. Permission required for reproduction or display.

Example Approximate the function f(x) = 1. 2 - 0. 25 x - 0.

Example Approximate the function f(x) = 1. 2 - 0. 25 x - 0. 5 x 2 - 0. 15 x 3 - 0. 1 x 4 from xi = 0 with h = 1 and predict f(x) at xi+1 = 1. 5 Copyright © 2006 The Mc. Graw-Hill Companies, Inc. Permission required for reproduction or display.

Example: computing f(x) = ex using Taylor Series expansion Choose x = xi+1 and

Example: computing f(x) = ex using Taylor Series expansion Choose x = xi+1 and xi = 0 Then f(xi+1) = f(x) and (xi+1 – xi) = x Since First Derivative of ex is also ex : (2. ) (ex )” = ex (3. ) (ex)”’ = ex, … (nth. ) (ex)(n) = ex As a result we get: Looks familiar? Maclaurin series for ex 6 Copyright © 2006 The Mc. Graw-Hill Companies, Inc. Permission required for reproduction or display.

Yet another example: computing f(x) = cos(x) using Taylor Series expansion Choose x=xi+1 and

Yet another example: computing f(x) = cos(x) using Taylor Series expansion Choose x=xi+1 and xi=0 Then f(xi+1) = f(x) and (xi+1 – xi) = x Derivatives of cos(x): (1. ) (cos(x) )’ = -sin(x) (2. ) (cos(x) )” = -cos(x), (3. ) (cos(x) )”’ = sin(x) (4. ) (cos(x) )”” = cos(x), …… As a result we get: 7 Copyright © 2006 The Mc. Graw-Hill Companies, Inc. Permission required for reproduction or display.

Notes on Taylor expansion: • Each additional term will contribute some improvement to the

Notes on Taylor expansion: • Each additional term will contribute some improvement to the approximation. Only if an infinite number of terms are added will the series yield an exact result. • In most cases, several terms will result in an approximation that is close enough to the true value for practical purposes • Reminder value R represents the truncation error • The order of truncation error is hn+1 R=O(hn+1), If R=O(h), halving the step size will halve the error. If R=O(h 2), halving the step size will quarter the error. 8 Copyright © 2006 The Mc. Graw-Hill Companies, Inc. Permission required for reproduction or display.

Error Propagation • Let xfl refer to the floating point representation of the real

Error Propagation • Let xfl refer to the floating point representation of the real number x. • Since computer has fixed word length, there is a difference between x and xfl (round-off error) and we would like to estimate the error in the calculation of f(x) : • Both x and f(x) are unknown. • If xfl is close to x, then we can use first order Taylor expansion and compute: Result: If f’(xfl) and Dx are known, then we can estimate the error using this formula Solve from Example 4. 5 p. 95 9 Copyright © 2006 The Mc. Graw-Hill Companies, Inc. Permission required for reproduction or display.