Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Chapter 4

Truncation Errors and the Taylor Series

“These notes are only to be used in class presentations”

Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
How does a CPU compute the following functions for a specific x value?

cos(x) sin(x) ex log(x) etc.

Truncation error results from using an approximation in


place of an exact mathematical procedure.

•Non-elementary functions such as trigonometric, exponential, and others are


expressed in an approximate fashion using Taylor series when their values,
derivatives, and integrals can be 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 McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Taylor’s theorem: If a function f and its (n+1) derivatives are
continuous on an interval containing x and x0, then the value of the
function at x is given by,

f ( x)  Pn ( x)  Rn ( x)
f ' ( x0 ) f " ( x0 ) f ( n) ( x0 )
Pn ( x)  f ( x0 )  ( x  x0 )  ( x  x0 )   
2
( x  x0 ) n
1! 2! n!

Pn (x) : nth Taylor polynomial for f about x0

n (k ) The infinite series obtained by


f ( x0 )
Pn ( x)   (x  x0 ) k taking the limit of Pn (x) is the
k 0 k! Taylor’s series for f about x0

3
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
f ( n1) ( )  : a value of x that lies
Rn ( x)  ( x  x0 ) ( n1)
(n  1)! somewhere between x0 and x.

Rn (x): The Lagrange Remainder term


•It accounts for all terms from (n+1) to infinity
•It is the truncation error

4
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Any smooth function can be approximated as a polynomial.

Let h  x  x0 : step size


f ( x)  f ( x0 ) Zero order approximation

f ( x)  f ( x0 )  f ' ( x0 )h First order approximation


f ' ( x0 ) f " ( x0 ) 2
f ( x)  f ( x0 )  h h Second order approximation
1! 2!
f ' ( x0 ) f " ( x0 ) 2 f ( n ) ( x0 ) n nth order approximation
f ( x)  f ( x0 )  h h  h
1! 2! n!
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.

f ' ( x0 ) f " ( x0 ) 2 f ( n ) ( x0 ) n f ( n1) ( ) n1


f ( x)  f ( x0 )  h h  h  h
 1!  2 ! n !   (n  1)!
 
Pn ( x ) Rn ( x )
5
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example 4.1
Use zero through fourth order Taylor series expansions to approximate the
function f(x) = 1.2 - 0.25x - 0.5x2 - 0.15x3 - 0.1x4
from x0 = 0 with h = 1. That is to predict f(x) at x = 1.

Order n f (n) (x) f(1) t


(%)
0 1.2 - 0.25x - 0.5x2 - 0.15x3 - 0.1x4 1.2 500
1 -0.25 - x - 0.45x2 - 0.4x3 0.95 375
2 -1 – 0.9 x - 1.2x2 0.45 125
3 -0.9 – 2.4 x 0.3 50
4 -2.4 0.2 0

nth order Taylor series expansion will be exact for an nth order polynomial

6
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example 4.2
Use Taylor series expansion with n=0 to 6 to approximate f(x) = cos x
at x= /3 on the basis of the value of f(x) and its derivatives at x0= /4.

In this course, all angles are assumed to be in radian unless you are told otherwise.

Order f(n)(x) f(/3) t


n (%)

0 cos x 0.707106781 41.4


1 - sin x 0.521986659 4.4
2 - cos x 0.497754491 0.449
3 sin x 0.499869147 2.62 x 10-2
4 cos x 0.500007551 1.51 x 10-3
5 - sin x 0.500000304 6.08 x 10-5
6 - cos x 0.499999988 2.40 x 10-6

For other differentiable and continuous functions such as exponential and


trigonometric, finite number of terms will not give an exact estimate.
7
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
How many terms are required to get “close enough” to the exact solution is
based on the remainder term of the expansion.

f ( n 1) () ( n 1) There are two drawbacks:


Rn ( x )  h • ξ isn’t exactly known
(n  1)! • (n+1)th derivative must be determined.
But we can control h (step size)
The order of truncation error is hn+1  Rn=O(hn+1),
If R=O(h), halving the step size will halve the error.
If R=O(h2), halving the step size will quarter the error.

In order to decrease truncation error;


Add more terms to the Taylor series
Reduce the step size

In most cases, if h is sufficiently small only a few terms will result in an


approximation that is close enough to the true value for practical purposes. 8
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Taylor’s Inequaltiy

This inequality is used to bound the error terms associated with Taylor
polynomials and hence, have an analytic bound on the error of approximation.

Taylor Inequality: Suppose the function f and the first n+1


derivatives of f can be integrated, then

M n1

Rn ( x)  x  x0
(n  1)!

where 
M  max f ( n 1) ( ) : x0    x 
9
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example 4.3

a)Determine 2nd Taylor polynomial for the function f(x) about x0=0.
x
f ( x)  e cos( x)
b) Use this polynomial to approximate f(0.5)
c) Use Taylor inequality to find the error bound for the truncation
error and find an interval for the actual function value.
Note: x is in radians.

Answer: a) f ( x)  1  x
b) f (0.5)  1.5
c) R2 (0.5)  0.0932
1.4068  f (0.5)  1.5932
Actual value : f (0.5)  1.4469

10
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example 4.4

Use Taylor series expansion for


x 1
f x  
x 1
about x0=1 to calculate f(1.1) with an error less than 10-3.
Answer:

2nd order approximation is used.


f ( x0 )( x  x0 ) 2
f ( x)  f ( x0 )  f ( x0 )( x  x0 ) 
2!
f (1.1)  0.0475
x 1
True value f (1.1)   0.047619
x  1 x 1.1
Et  0.047619  0.0475  0.000119  103
11
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Error Propagation
Errors in numbers can propagate through mathematical functions

Functions of a single variable


•Suppose f(x) is dependent on a single independent variable x
•Assume ~
x is an approximation of x
~
x  x~
x estimate of the error of x

•The effect of the discrepancy between x and ~


x on the value of the function.

f ( ~
x )  f ( x)  f ( ~
x) an estimate of the error of the function

12
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
If ~
x is close to x and f(x) is continuous and differentiable, Taylor series expansion
of f(x) around ~ x
f ( ~
x )( x  ~
x )2
f ( x)  f ( ~
x )  f ( ~
x )( x  ~
x)  
2!
f ( x)  f ( ~
x)  f ( ~
x )( x  ~
x ) 1st order estimate

f ( ~
x )  f ( x)  f ( ~
x )  f ( ~
x ) ~
x

13
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example 4.5

x ~  0.01
Given a value of ~ x  2.5 with an error of
estimate the resulting error in the function f ( x )  x
3

Answer:

f ( ~
x )  0.1875
f (~x )  15.625
f ( x)  15.625  0.1875

14
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Functions of more than one variable
For n independent variables ~
x1, ~
x2 , ~
xn having errors
~
x1, ~
x2 ,~
xn

~ ~ ~ f ~ f ~ f ~
f ( x1, x2  xn )  x1  x2    xn
x1 x2 xn

15
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
16
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example 4.6

The velocity of the falling parachutist can be computed by

v(t ) 
gm
c
1 e( c / m )t

Use a first-order error analysis to estimate the error of velocity at
t=6s, if g=9.8 m/s2 and m=50±2 kg and c=12.5 ±1.5 kg/s.

Answer:
v(c~, m
~ )  0.2733
v~  30.4533
v  30.4533  0.2733
17
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Stability and Condition
•The condition of a mathematical problem-relates to its sensitivity to
changes in its input values.
•A computation is numerically unstable if the uncertainty of the input
values is grossly magnified by the numerical method.
Condition number provides a measure for how an uncertainty in x affects f(x)
f ( ~
x )( x  ~
x)
The relative error of f(x):
f (~x)
x~x
The relative error of x: ~
x

A condition number is the ratio of relative errors of f(x) and x.

~
x f ( ~
x) =1 relative errors of x and f(x) are equal
CN  >1 the error is amplified
f (~x) <1 the error is attenuated
18
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example 4.7 Evaluate and interpret the condition numbers for

a) f ( x)  x2  1  x for ~
x  300
b) f ( x)  e x
for ~
x  10

Answer:

a )  0.999994 well  conditioned


b) 10 ill  conditioned

Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Total Numerical Error

The total numerical error is the summation of the truncation and round-off
errors.
•The only way to minimize round-off errors is to increase the number of
significant figures of the computer. The round-off errors will increase due to
subtractive cancellation or due to an increase in the number of computations
in an analysis.
•The truncation errors can be reduced by decreasing the step size. A
decrease in step size can lead to subtractive cancellation or to an increase in
computation.

The truncation errors decrease as the round-off errors increase.

20
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
• Determine an appropriate step size for a particular computation.

• Identify the point of diminishing returns where round-off error


begins to negate the benefits of step-size reduction. 21
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

You might also like