0% found this document useful (0 votes)
170 views41 pages

Section 4 Roundoff and Truncation Error

This document section discusses roundoff and truncation errors that occur in numerical computations. It defines absolute and relative errors, and how errors are approximated since the true value is unknown. It also describes how computers represent numbers in binary format, leading to roundoff errors, and how truncation errors arise from approximating functions with Taylor series. The key sources of errors are finite precision in representations and approximating continuous problems with discrete models.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
170 views41 pages

Section 4 Roundoff and Truncation Error

This document section discusses roundoff and truncation errors that occur in numerical computations. It defines absolute and relative errors, and how errors are approximated since the true value is unknown. It also describes how computers represent numbers in binary format, leading to roundoff errors, and how truncation errors arise from approximating functions with Taylor series. The key sources of errors are finite precision in representations and approximating continuous problems with discrete models.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

SECTION 

4: ROUNDOFF AND 
TRUNCATION ERRORS
MAE 4020/5020 – Numerical Methods with MATLAB
2 Definitions of Error

K. Webb  MAE 4020/5020
True Error
3

 Absolute error – the difference between an 
approximation and the true value

 Relative error – the true error as a percentage of the 
true value

 Both definitions require knowledge of the true value!
 If we had that, why would we be approximating?
K. Webb  MAE 4020/5020
Approximating the Error
4

 Since we don’t know the true value, we can only 
approximate the error
 Often, approximations are made iteratively
 Approximate the error as the change in the 
approximate value from one iteration to the next

K. Webb  MAE 4020/5020
Relative Approximate Error
5

 We don’t know the true value, so we can’t calculate 
the true error – approximate the error
 Relative approximate error – an approximation of 
the error relative to the approximation itself

K. Webb  MAE 4020/5020
Stopping Criterion
6

 For iterative approximations, continue to iterate 
until the relative approximate error magnitude is 
less than a specified stopping criterion

 For accuracy to at least  significant figures set the 
stopping criterion to

K. Webb  MAE 4020/5020
7 Roundoff Error

K. Webb  MAE 4020/5020
Roundoff Errors
8

 Roundoff errors occur due to the way in which 
computers represent numerical values
 Computer representation of numerical values is 
limited in terms of:
 Magnitude – there are upper and lower bounds on the 
magnitude of numbers that can be represented
 Precision – not all numbers can be represented exactly

 Certain types of mathematical manipulations are 
more susceptible to roundoff error than others

K. Webb  MAE 4020/5020
Number Systems – Decimal 
9

 We are accustomed to the decimal number system
 A base‐10 number system
 Ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

 Each digit represents an integer power of 10

7281.36
6 x 10‐2
3 x 10‐1
1 x 10‐0
8 x 101
2 x 102
7 x 103

K. Webb  MAE 4020/5020
Binary Number System
10

 Computers represent numbers in binary format
 A base‐2 number system
 Two digits: 0, 1
 Easy to store binary values in computer hardware – an on or off switch – a  high or low 
voltage
 One digit is a bit – eight bits is a byte
 Each bit represents an integer power of 2

10110101
1 x 20 = 1
0 x 21 = 0
1 x 22 = 4
0 x 23 = 0 = (181)10
1 x 24 = 16
1 x 25 = 32
0 x 26 = 0
1 x 27 = 128
K. Webb  MAE 4020/5020
IEEE Double‐Precision Format
11

 By default, MATLAB uses double‐precision floating 
point to store numeric values ‐ double
 64‐bit binary word

Signed 
Sign bit
Exponent – (e) Mantissa – (f)

11 bits 52 bits

K. Webb  MAE 4020/5020
IEEE Double‐Precision Format
12

 Mantissa
 Only the fractional portion of the mantissa stored
 Bit to the left of the binary point assumed to be 1
 Normalized numbers
 Really a 53‐bit value

 Exponent
 11‐bit signed integer value: ‐1022 … 1023

 Two special cases:
e = 0x000 (i.e. all zeros): zero if f = 0, subnormal #’s if f 0
 e = 0x7FF (i.e. all ones): ∞ if f = 0, NaN if f 0

K. Webb  MAE 4020/5020
Normalized numbers
13

 Leading zeros are removed
 Most significant digit (must be a 1 in binary) moved to 
the left of the binary point
 53rd bit of the mantissa (always 1) needn’t be stored

 Maximum mantissa
1.111……11

Not stored

K. Webb  MAE 4020/5020
Subnormal Numbers
14

 If  , always, then the smallest number that 
could be represented is: 2 .
 If we allow for  , then the most significant bit 
is somewhere to the right of the binary point
 Leading zeros – not normalized … subnormal
 Allows for smaller numbers, filling in the hole around 
zero
 Subnormal numbers represented by setting the 
exponent to zero
 Smallest subnormal number:
2 2
K. Webb  MAE 4020/5020
Doubles – Range 
15

 Maximum value:

1 2 2 .

 Minimum normal value:
2 .

 Minimum subnormal value:
2 2

 Precision – machine epsilon
.

K. Webb  MAE 4020/5020
Roundoff Error – Mathematical Operations
16

Certain types of mathematical operations are more 
susceptible to roundoff errors:
 Subtractive cancellation – subtracting of two nearly‐
equal numbers results in a loss of significant digits
 Large computations – even if the roundoff error from a 
single operation is small, the cumulative error from 
many operations may be significant
 Adding large and small numbers – as in an infinite 
series
 Inner products – (i.e. dot product) very common 

operation – solution of linear systems of equations
K. Webb  MAE 4020/5020
17 Truncation Error

K. Webb  MAE 4020/5020
Truncation Errors
18

 Errors that result from the use of an approximation 
in place of an exact mathematical procedure
 E.g. numerical integration, or the approximation 
derivatives with finite‐difference approximations

 To understand how truncation errors arise, and to 
gain an understanding of their magnitudes, we’ll 
make use of the Taylor Series

K. Webb  MAE 4020/5020
Taylor Series
19

 Taylor’s Theorem – any smooth (i.e., continuously 
differentiable) function can be approximated as a 
polynomial
 Taylor Series

 This infinite series is an equality
 An exact representation of any smooth function as a 
polynomial
 An infinite‐order polynomial – impractical
K. Webb  MAE 4020/5020
Taylor Series Approximation
20

 Can approximate a function as a polynomial by truncating
the Taylor series after a finite number of terms

2! !
where  is the step size

Chapra

K. Webb  MAE 4020/5020
Taylor Series Truncation Error
21

 Can account for error by lumping the  and 
higher‐order terms into a single term, 


2! !

 is the error associated with truncating after  terms

1 !

 is some (unknown) value of  between  and 

K. Webb  MAE 4020/5020
Derivative Mean‐Value Theorem
22

 If  and  are continuous on  , then 


there is a point on this interval,  , where  is the 
slope of the line joining  and 

Chapra

K. Webb  MAE 4020/5020
Truncation Error – Dependence on Step Size
23

1 !

 We don’t know  , so we don’t know 
 We do know it’s proportional to  , where  is the 
step size
 Error is on the order of 

 If  (first‐order approx.), halving the step size 


will quarter the error

K. Webb  MAE 4020/5020
24 Truncation Errors in Practice
• Discretizing equations
• Finite‐difference approximations

K. Webb  MAE 4020/5020
Discretization of Equations
25

 As engineers, many of the mathematical 
expressions we are interested in are differential 
equations
 We know how to evaluate derivatives analytically

 Need an approximation for the derivative operation in 
order to solve numerically
 Discretization – conversion of a continuous 
function, e.g. differentiation, to a discrete 
approximation for numerical evaluation

K. Webb  MAE 4020/5020
Finite Difference Approximations
26

 Recall the definition of a derivative

lim

 Remove the limit to  approximate this numerically

 This is the forward difference approximation
 Uses value at  and forward one step at  to 
approximate the derivative at 

K. Webb  MAE 4020/5020
Discretizing Equations – Example 
27

 A free‐falling object (bungee jumper example from 
the text) can be modeled as 

where  is velocity,  is mass,  is gravitational acceleration, and   is a 


lumped drag coefficient
 This is a non‐linear ordinary differential equation 
(ODE), which can be solved analytically to yield

tanh ∙

K. Webb  MAE 4020/5020
Discretizing Equations – Example 
28

 To solve numerically instead, approximate the 
derivative operation with a finite difference

 Solving for  and using  to denote the time step 


yields

 We’ve transformed the differential equation to a 
difference equation
 An algebraic equation
 Can be solved iteratively – using a loop

K. Webb  MAE 4020/5020
Discretizing Equations – Example 
29

 The term in the square brackets is the original diff. eq., i.e. it is 

 The difference equation is a first‐order Taylor series 
approximation

 Where we know that the error is on the order of the step size 
squared

 Taylor series provides a relation between the step size and 
the accuracy of the numerical solution to the diff. eqn.
K. Webb  MAE 4020/5020
Finite Difference Methods
30

 The preceding example showed
 One method – forward difference – for numerically 
approximating a derivative
 Transformation of a differential equation to a difference 
equation
 How Taylor series can provide an understanding of the 
error associated with an approximation
 Now we’ll take a closer look at three finite 
difference methods and how Taylor series can help 
us understand the error associated with each

K. Webb  MAE 4020/5020
Forward Difference
31

 Can also derive the forward   So, the error term is
difference approximation from 
the Taylor Series

 The forward difference, 
 Solving for 
including error, is

 We’ve already seen that  Error of the forward 
difference approximation is 
on the order of the step 
size
K. Webb  MAE 4020/5020
Forward Difference
32

 Value of the 
function, 
at  and 
forward one 
step at 
used to 
approximate 
the derivative 
Chapra
at 

K. Webb  MAE 4020/5020
Backward Difference
33

 Backward difference uses value of   Again the error is on the order of 
at  and one step backward at  the step size
to approximate the derivative at 

 The backward difference 
 This can also be developed by 
expression, including error, 
expanding the Taylor series backward becomes

 Then solving for 
 Error of the backward 
difference approximation is 
on the order of the step size

K. Webb  MAE 4020/5020
Backward Difference
34

 Now use the 
value of 
at  and 
backward one 
step at  to 
approximate 
the derivative 
at 
 Again, error is
Chapra

K. Webb  MAE 4020/5020
Central Difference
35

 Central difference uses value of   Now, the remainder term is
one step backward at  and ones 
step ahead at  to approximate 
the derivative at   The central difference expression, 
including error, becomes

2
 This can also be developed by  2
subtracting  the backward Taylor 
series from the forward series  Error of the central difference 
approximation is on the order of 
 Second‐order derivative terms 
the step size squared
cancel, leaving
 Central difference method is 
2 more accurate than forward or 
backward
 Uses more information

K. Webb  MAE 4020/5020
Central Difference
36

 Now use the 
value of 
backward one 
step at  and 
forward one step 
at  to 
approximate the 
derivative at 
 Reduced error:
Chapra

K. Webb  MAE 4020/5020
37 Total Numerical Error

K. Webb  MAE 4020/5020
Total Numerical Error
38

 Total numerical error is the sum of roundoff and 
truncation error
 Roundoff error is largely out of your control, and, with 
double precision arithmetic, it is not typically an issue
 Truncation error can be a significant problem, but can 
be reduced by decreasing step size
 Reducing step size reduces truncation error, but 
may also result in subtractive cancellation, thereby 
increasing roundoff error
 Choose step size to minimize total error
 Or, more typically, to reduce truncation error to an 
acceptable level
K. Webb  MAE 4020/5020
Total Numerical Error
39

 Reducing step size reduces truncation error, but may 
also result in subtractive cancellation, thereby 
increasing roundoff error
 Could choose step size 
to minimize total error
 But, more typically, 
reduce step size just 
enough to reduce 
truncation error to an 
acceptable level
Chapra

K. Webb  MAE 4020/5020
Central Difference Error Analysis
40

 First derivative of a function in terms of the central 
difference approximation is

 The last term on the right is the truncation error
 There is also roundoff error associated with each value

were  represents a rounded value, and  is the 


corresponding roundoff error
K. Webb  MAE 4020/5020
Central Difference Error Analysis
41

 Substituting the expressions for the rounded values into 
the expression for the true derivative yields

 Giving a total error of 
Truncation error
Roundoff error

 Truncation error increases with step size
 Roundoff error decreases with step size
K. Webb  MAE 4020/5020

You might also like