CH 04
CH 04
Roundoff and
Truncation Errors
Numerical Methods 1
Errors: Accuracy and Precision
• Accuracy refers to how closely
a computed or measured
value agrees with the true
value.
– Inaccuracy (bias): systematic
deviation from the truth
• Precision refers to how closely
individual computed or
measured values agree with
each other.
– Imprecision (uncertainty): the
magnitude of the scatter
Numerical Methods 2
Errors: Definitions
• True error (Et) = true value - approximation
Numerical Methods 3
Errors: Definitions
• For iterative processes:
a = 100% x (present approx. - previous approx.)
/(present approx.)
• Stopping criterion: whether the absolute value of the
percent relative error is lower than a pre-specified
tolerance (s)
Numerical Methods 4
Errors: Example 4.1
• A Maclaurin series expansion for ex:
2 3 4 n
x x x x x
e 1 x
2! 3! 4! n!
• Estimate e0.5 and compute the true and approximation
percent relative errors when each new term is added.
Terms Result et % ea %
1 1 39.3
2 1.5 9.02 33.3
3 1.625 1.44 7.69
4 1.645833333 0.175 1.27
: : : :
True value = 1.648721270700128….
Numerical Methods 5
Roundoff Errors
• Roundoff errors arise because digital computers
cannot represent some quantities exactly.
• Two major facets of roundoff errors involved in
numerical calculations:
– Digital computers have size and precision limits on their
ability to represent numbers.
– Certain numerical manipulations are highly sensitive to
roundoff errors.
Numerical Methods 6
Roundoff Errors: Computer Number
Representation
• The binary representation of the decimal integer
-173 on a 16-bit computer:
(10101101) 2 27 25 23 2 2 20 128 32 8 4 1
(173)10
Numerical Methods 7
Roundoff Errors: Floating-Point
Representation
• Fractional quantities are typically represented in
computers using floating-point format:
s be
s = the significand
b = the base of the number system being used
e = the exponent
– This is done so computer memory is not wasted on storing
useless non-significant zeros.
s1 d1.d 2 10s d
0 0
n = ±(1+f) x 2e
Numerical Methods 10
Roundoff Errors: Arithmetic
Manipulations of Computer Numbers
• Assume a hypothetical decimal computer with a 4-
digit mantissa and a 1-digit exponent
1.557 0.04341 ?
0.1557 101 0.004341 101 0.160041 101 (?)
0.1600 101
– Subtractive cancellation
0.7642 103
0.764110 3 normalize 0.1000 10 0
0.0001103
Numerical Methods 11
Roundoff Errors: Floating-Point
Representation
• Large computations : Even though an individual
roundoff error could be small, the cumulative effect
over the course of a large computation can be
significant.
• Adding a large and a small number 0.4000 10 4
0.000000110 4
0.400000110 4
Numerical Methods 13
Truncation Errors: The Taylor Series
• The Taylor theorem states that any smooth function can be
approximated as a polynomial. The Taylor series provides a
means to express this idea mathematically.
f ' ' xi 2 f (3) xi 3 f ( n ) xi n
f xi 1 f xi f ' xi h h h ... h Rn
2! 3! n!
f ( n 1) () n 1
Rn h
(n 1)!
Numerical Methods 14
Truncation Errors: The Taylor Series
• Example 4.3: Use Taylor series expansions with n = 0 to 6 to
approximate f(x) = cos x at xi+1 = p/3 on the basis of the value of
f(x) and its derivatives xi=p/4
f ( xi ) 2
– 2nd order approximation: f ( xi 1 ) f ( xi ) f ( xi )h h
2!
2
cos( / 4)
f cos sin
3 4 4 12 2 12
0.707106781
0.521986659
0.497754491
Numerical Methods 15
Truncation Errors: Numerical
Differentiation
• Forward difference approx.
' f (x i1 ) f (x i )
f (x i ) O(h)
h
' f (x i ) f (x i 1 )
f (x i ) O(h)
h
• Centered difference approx.
' f (x i1 ) f (x i 1 )
f (x i ) O(h 2 )
2h
Numerical Methods 16
Total Numerical Errors
• The total numerical error is the summation of the truncation
and roundoff errors.
Numerical Methods 17
Summary
• Accuracy vs. precision
• Learning how to quantify error
• Roundoff errors occur because digital computers have a
limited ability to represent numbers.
– floating-point numbers have limits on their range and precision
• Truncation errors occur when exact mathematical
formulations are represented by approximations.
– Taylor series to estimate truncation errors
Numerical Methods 18