0% found this document useful (0 votes)
13 views

CH 04

Uploaded by

wjdalscks0204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

CH 04

Uploaded by

wjdalscks0204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Chapter 4.

Roundoff and
Truncation Errors

Prof. Kiho Park

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

• True fractional relative error =


(true value - approximation)/(true value)
• Normalizes the error using the best available estimate of
the true value.
a = 100 x (approx. error)/(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

• A range of integers for a 16-bit computer


(0111 111) 2 214  213   2 1 0 15
…  2  2  2 32,767 2  1
(0000 000) 2 0
(1111 111) 2 214  213   2 1 0
…  2  2  2  32,767  (2  1)
15

(1000 000) 2  32, 768


-32768 ≤ integer ≤ 32767 (-2 to 2 -1)
15 15

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.

0.005678 5.678  10 3


(not 0.005678 10 0 )
Numerical Methods 8
Roundoff Errors: Floating-Point
Representation
• Example 4.2: Suppose a hypothetical base-10 computer with a
5-digit word size.
– one digit: the sign (s1)
– two digits: the exponent, one of them for its sign (so, do)
– two digits: mantissa (d1, d2)

s1 d1.d 2  10s d
0 0

• Roundoff errors: 2  5 0.03125  3.110  2 0.031


0.03125  0.031
0.008
0.03125
Numerical Methods 9
Roundoff Errors: Floating-Point
Representation
• By default, MATLAB has adopted the IEEE double-
precision format in which eight bytes (64 bits) are
used to represent floating-point numbers:

n = ±(1+f) x 2e

– The sign is determined by a sign bit


– The mantissa f is determined by a 52-bit binary number
– The exponent and its sign e is determined by an 11-bit
binary number

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.764110 3 normalize  0.1000 10 0
0.0001103

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.000000110 4
0.400000110 4

• Smearing - Smearing occurs whenever the individual


terms in a summation are larger than the summation
itself.
– e.g. (x+10-20) - x = 10-20 mathematically,
but, in MATLAB, when x=1, (x+10-20)-x = 0 !
Numerical Methods 12
Truncation Errors
• Truncation errors are those that result from using an
approximation in place of an exact mathematical
procedure.
– e.g.
dv v vti1 vti 
 
dt t ti1  ti



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 i1 )  f (x i )
f (x i )   O(h)
h

• Backward difference approx.

' f (x i )  f (x i 1 )
f (x i )   O(h)
h
• Centered difference approx.

' f (x i1 )  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

You might also like