Chapter 4
Chapter 4
Chapter 4
Roundoff and
Truncation Errors
Chapter Objectives
• Understanding the distinction between accuracy
and precision.
• Learning how to quantify error.
• Learning how error estimates can be used to
decide when to terminate an iterative calculation.
• Understanding how roundoff errors occur because
digital computers have a limited ability to represent
numbers.
• Understanding why floating-point numbers have
limits on their range and precision.
1
2/24/2020
Objectives (cont)
• Recognizing that truncation errors occur when
exact mathematical formulations are represented
by approximations.
• Knowing how to use the Taylor series to estimate
truncation errors.
• Understanding how to write forward, backward, and
centered finite-difference approximations of the first
and second derivatives.
• Recognizing that efforts to minimize truncation
errors can sometimes increase roundoff errors.
2
2/24/2020
Error Definitions
• True error (Et): the difference between the
true value and the approximation.
• Absolute error (|Et|): the absolute difference
between the true value and the
approximation.
• True fractional relative error: the true error
divided by the true value.
• Relative error (t): the true fractional relative
error expressed as a percentage.
Error Definitions
𝐸𝑡 = true value − approximation
3
2/24/2020
4
2/24/2020
5
• For the storage drum, 𝜀𝑡 = 50000 × 100 = 0.01%
5
• For the beaker, 𝜀𝑡 = 250 × 100 = 2.0%
10
5
2/24/2020
approximate error
ε𝑎 = × 100%
approximation
11
12
6
2/24/2020
𝜀𝑠 = 0.5 × 102−𝑛 %
13
𝑥
𝑥2 𝑥3 𝑥𝑛
𝑒 = 1 +𝑥 + + +⋯+
2 3! 𝑛!
14
7
2/24/2020
15
Terms Result t % a %
1 1 39.3 -
2 1.5 9.02 33.3
3 1.625 1.44 7.69
4 1.645833333 0.175 1.23
5 1.648437500 0.0172 0.158
6 1.648697917 0.00142 0.0158
16
8
2/24/2020
17
Roundoff Errors
• Roundoff errors arise because digital
computers cannot represent some quantities
exactly.
• They are important to engineering and
scientific problem solving because they can
lead to erroneous results.
• In certain cases, they can actually lead to a
calculation going unstable and yielding
obviously erroneous results.
18
9
2/24/2020
Roundoff Errors
• There are two major aspects of roundoff
errors involved in numerical calculations:
19
20
10
2/24/2020
Base 2 system
• The signed magnitude method, employs the
first bit of a word to indicate the sign, with a 0
for positive and a 1 for negative.
• The remaining bits are used to store the
number.
• For example, the integer value of 173 is
represented in binary as 10101101.
21
Base 2 system
• If such a scheme is employed, there clearly
is a limited range of integers that can be
represented.
• Again assuming a 16-bit word size, if one bit
is used for the sign, the 15 remaining bits
can represent binary integers from 0 to
111111111111111. The upper limit can be
converted to a decimal integer, as in:
1 × 214 + 1 × 213 + ⋯ + 1 × 21 + 1 × 20 = 32,767
22
11
2/24/2020
Base 2 system
23
Base 2 system
24
12
2/24/2020
Implications of Floating-Point
Representation
• Example 4.2: Suppose that we had a
hypothetical base-10 computer with a 5-digit
word size. Assume that one digit is used for
the sign, two for the exponent, and two for
the mantissa. For simplicity, assume that one
of the exponent digits is used for its sign,
leaving single digit for its magnitude.
25
𝑠1 . 𝑑1 . 𝑑2 × 10𝑠0 𝑑0
26
13
2/24/2020
27
28
14
2/24/2020
29
30
15
2/24/2020
31
32
16
2/24/2020
33
Truncation Errors
• Truncation errors are those that result from
using an approximation in place of an exact
mathematical procedure.
• Example 1: approximation to a derivative
using a finite-difference equation:
𝑑𝑣 ∆𝑣 𝑣 𝑡𝑖+1 − 𝑣 𝑡𝑖
≅ =
𝑑𝑡 ∆𝑡 𝑡𝑖+1 − 𝑡𝑖
34
17
2/24/2020
35
𝑓 (𝑛+1) 𝑥𝑖 𝑛+1
𝑅𝑛 = ℎ
𝑛+1 !
36
18
2/24/2020
Truncation Error
• In general, the 𝑛th order Taylor series
expansion will be exact for an nth order
polynomial.
• In other cases, the remainder term 𝑅𝑛 is of
the order of ℎ𝑛+1 , meaning:
▪ The more terms are used, the smaller the error,
and
▪ The smaller the spacing, the smaller the error for
a given number of terms.
37
38
19
2/24/2020
• True value:
𝜋 𝜋
𝑓 = cos = 0.5
3 3
• Zero-order Approximation:
𝜋 𝜋 𝜋
𝑓 ≅𝑓 = cos = 0.707106781
3 4 4
0.5 − 0.707106781
𝜀𝑡 = × 100% = 41.4%
0.5
39
• First-order Approximation:
𝜋 𝜋 ′
𝜋
𝑓 ≅𝑓 + 𝑓 4 .ℎ
3 4
𝜋 𝜋 𝜋
= cos − sin = 0.521986659
4 4 12
0.5 − 0.521986659
𝜀𝑡 = × 100% = 4.40%
0.5
40
20
2/24/2020
41
The derivative mean-value theorem states that if a function 𝑓(𝑥) and its first derivative are
continuous over an interval from 𝑥𝑖 to 𝑥𝑖+1 , then there exists at least one point on the function
that has a slope, designated by 𝑓′(ξ ), that is parallel to the line joining f (xi) and f (xi+1).
zero order: 𝑅0 = 𝑓 ′ ℎ
𝑓 ′′ 2
first-order: 𝑅1 = ℎ
2!
42
21
2/24/2020
43
• Recall that:
𝑓 (𝑛+1) 𝑛+1 𝑣 ′′ 2
𝑅𝑛 = ℎ hence 𝑅1 = 𝑡𝑖+1 − 𝑡𝑖
𝑛+1 ! 2!
44
22
2/24/2020
Numerical Differentiation
• The first order Taylor series can be used to
calculate approximations to derivatives:
▪ Given: f (x i+1) = f (x i ) + f (x i )h + O(h )
' 2
f (x i+1 ) - f (x i )
▪ Then: f ' (x i ) = + O(h)
h
• This is termed a “forward” difference because
it utilizes data at 𝑖 and 𝑖 + 1 to estimate the
derivative.
45
Differentiation (cont)
• There are also backward and centered difference
approximations, depending on the points used:
• Forward:
f (x i+1 ) - f (x i )
f ' (x i ) = + O(h)
h
• Backward:
f (x i ) - f (x i-1)
f ' (x i ) = + O(h)
h
• Centered:
f (x i+1 ) - f (x i-1)
f ' (x i ) = + O(h 2 )
2h
46
23
2/24/2020
Finite-Difference Approximations of
Derivatives
• Example 4.4:
Use forward and backward difference approximations of
O(h) and a centered difference approximation of O(h2) to
estimate the first derivative of:
𝑓 𝑥 = −0.1𝑥 4 − 0.15𝑥 3 − 0.5𝑥 2 − 0.25𝑥 + 1.2
at x = 0.5 using a step size h = 0.5. Repeat the
computation using h = 0.25. Note that the derivate can be
calculated directly as:
𝑓′ 𝑥 = −0.4𝑥 3 − 0.45𝑥 2 − 1.0𝑥 − 0.25
and can be used to compute the true value as
f ′(0.5)= – 0.9125
47
48
24
2/24/2020
49
50
25
2/24/2020
51
Other Errors
• Blunders - errors caused by malfunctions of
the computer or human imperfection.
• Model errors - errors resulting from
incomplete mathematical models.
• Data uncertainty - errors resulting from the
accuracy and/or precision of the data.
52
26