Professional Documents
Culture Documents
Objectives
• Representation of errors
Lecture 8 Errors in Numerical • Round off errors due to computer
representation of numbers using finite‐length
Analysis word size
Dr. Tony Cahill
Definition of Error Definition of Error
• Numerical errors arise from the use of • Normalized error (ε)
approximations to represent exact
true value - approximation
mathematical operations: 100%
true value
TRUE VALUE = APPROXIMATION + ERROR
or,
ERROR (E) = TRUE VALUE ‐ APPROXIMATION
This is called absolute error
Stopping criteria in numerical analysis Example
1 2 3
x x x
• In numerical methods, a lot of the computations are ex 1 ...
1! 2! 3!
iterative in nature. A typical criteria to terminate the
iteration is when the relative error between the Let’s calculate e, i.e., x=1, step by step:
previous approximation and current approximation is previous present error (εa)
less than a set value: n=1: 1.000000 2.000000 50.000000%
n=2: 2.000000 2.500000 20.000000%
n=3: 2.500000 2.666667 6.250000%
present approximation - previous approximation
a s n=4: 2.666667 2.708333 1.538462%
present approximation n=5: 2.708333 2.716667 0.306748%
n=6: 2.716667 2.718056 0.051099%
n=7: 2.718056 2.718254 0.007299%
n=8: 2.718254 2.718279 0.000912%
1
2/6/2013
Number of significant digits Number of significant digits
• Take the first 5 terms, you get e~ 2.716667, • Take the first 5 terms, you get e~2.716667,
question is: how many digits in this answer is question is: how many digits in this answer is
significant (i.e., the same as the exact significant (i.e., the same as the exact
answer?) answer?)
Actual value of e is 2.718281828… Actual value of e is 2.718281828…
So, the above approximation has only 2 significant digits
Number of significant digits Round‐off error
• Conservative estimate of significant digits: • Numerical round‐off error arises because
to ensure your results have at least n computers cannot represent some numbers
significant digits, make sure your stopping exactly.
criteria is set such that: • This can have significant implication on
numerical methods because some numerical
s 0.5 102 n % manipulations are sensitive to round‐off
errors.
Remember, this is a conservative estimate, the actual
number of significant digits can be more than n.
Number representation in computer Number representation in computer
• Decimal (or base‐10) is what we use daily: • The basic storage unit in a computer is byte,
864.9 10 8*102 6*101 4*100 9*101 which is 8‐bit in size.
• Binary (base‐2) is what computers use: • Integer representation:
101011012 1* 27 0* 26 1* 25 0* 24 1* 23
1* 22 0* 21 1* 20 1 1 1 1 1 1 1 1
17310
This is the maximum integer you can represent using 1‐byte,
Which is equivalent to 255 in base‐10.
If the integer is represented in n‐bits, then the maximum
number is 2^n‐1.
2
2/6/2013
Number representation in computer Number representation in computer
• Floating number representation • Consider a base‐10 representation using 5
– Normalization: a number has to be normalized digits:
before being represented in a computer. Using
decimal number as an example: s0 d0 d1 s1 d2 s 0d 0.d110s1d 2
0.00567810 5.678 103 sign significand exponent
Number representation in computer Number representation in computer
• Consider a base‐10 representation using 5 • Round‐off error: consider 0.03125. How it will
digits: be represented using the system in our
previous example
s0 d0 d1 s1 d2 s 0d1.d 2 10 s1d 0
Max: +9.9x10+9
sign significand exponent
Min: ‐9.9x10+9
Number representation in computer Number representation in computer
• Round‐off error: consider 0.03125. How it will • Machine precision:
– Consider 1.1x10‐1, the next number that can be
be represented using the system in our represented will be 1.2x10‐1. Thus, the step size is
previous example 0.1x10‐1. Now, if you have 1.15x10‐1, it will be rounded
to 1.2x10‐1, thus an error of 0.005, or normalized by
the step size, is 5x10‐2. The relative error due to
round‐off is smaller for any other numbers between
it will be +3.1x10‐2 0.11 and 0.12.
– It can be shown that this maximum relative error is
only affected by the number representation in a
Thus, a round off error is introduced. system. It is formally called machine precision or
machine epsilon (eps).
– For our example, eps=0.05.
(eps=0.5*b‐p, where b is the base and p is the number of bits in the significand)
3
2/6/2013
Number representation in computer Number representation in computer
• Binary number in MATLAB: The IEEE double • Range of the IEEE double precision format:
precision format using 8 bytes: – Max: 2^1024 = 1.7977x10308
– Min: 2^(‐1022)=2.2251x10‐308
– Precision: 2.22x10‐16
• Related MATLAB functions:
– realmax
Signed Mantissa (factional part of the significand)
Exponent (In binary, the first digit of the significand,
– realmin
Sign
(1‐bit) (11‐bit) after normalization is always 1, so no need – eps
to save that).
(52‐bits) – format long/short
Taylor Series Expansion and Truncation Taylor Series Expansion and Truncation
Error Error
• Taylor Series Expansion • Truncation Error
f "( x) f "'( x)
f ( x x) f ( x) f '( x) x x x ...
2 3
f "( x)
f ( x x) f ( x) f '( x)x x
2
2! 3! 2!
f "'( x)
Truncation Error x ... O x
3 3
f(x) 3!
f(x)+f’(x)Δx
f(x+Δx)
x x+Δx