Professional Documents
Culture Documents
Approximations
Computer Arithmetic
Scientific Computing
Approximations
Computer Arithmetic
Outline
Scientific Computing: An Introductory Survey
Chapter 1 Scientific Computing
Prof. Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
Scientific Computing
1 / 46
Introduction
Computational Problems
General Strategy
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
Scientific Computing
Scientific Computing
2 / 46
Introduction
Computational Problems
General Strategy
Well-Posed Problems
exists
is unique
depends continuously on problem data
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
Scientific Computing
3 / 46
Introduction
Computational Problems
General Strategy
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
General Strategy
Scientific Computing
4 / 46
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
Sources of Approximation
Before computation
modeling
empirical measurements
previous computations
During computation
differential ! algebraic
truncation or discretization
rounding
nonlinear ! linear
complicated ! simple
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
Scientific Computing
5 / 46
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
Example: Approximations
Scientific Computing
Relative error :
true value
absolute error
true value
Michael T. Heath
6 / 46
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
Scientific Computing
7 / 46
Michael T. Heath
Scientific Computing
8 / 46
Scientific Computing
Approximations
Computer Arithmetic
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
Scientific Computing
Approximations
Computer Arithmetic
Total error:
f(
x)
f (x) =
f(
x)
f (
x) + f (
x)
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
f (x)
Scientific Computing
Scientific Computing
Approximations
Computer Arithmetic
9 / 46
Michael T. Heath
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
Scientific Computing
Scientific Computing
Approximations
Computer Arithmetic
10 / 46
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
!"
"
!"
f (x + h) f (x)
f (x)
h
exhibits tradeoff between rounding error and truncation
error
0
!%
!"
!$
!"
(/(36+)../.
!#
)../.
!"
!!"
!"
!!%
!"
!!$
Michael T. Heath
Scientific Computing
(.0123(,/1+)../.
!"
!!&
!"
!!#
!"
!!$
!!%
!"
!"
11 / 46
Backward error :
x=x
x, where f (
x) = y
!#
!$
!"
!"
!%
!"
"
!"
Michael T. Heath
Scientific Computing
12 / 46
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
!&
!"
Scientific Computing
Approximations
Computer Arithmetic
y = y
!!"
!"
'()*+',-)
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
Forward error :
./014,15+)../.
!!#
!"
Scientific Computing
Approximations
Computer Arithmetic
!&
!"
As approximation to y =
error
| y| = |
y
y| = |1.4
1.41421 . . . | 0.0142
x| = |1.96
2| = 0.04
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
Scientific Computing
13 / 46
Michael T. Heath
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
Scientific Computing
Approximations
Computer Arithmetic
14 / 46
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
y = f(x) = 1
y = y
y = f(x)
f (x) = 1
x2 /2
cos(x)
x2 /2
Michael T. Heath
Scientific Computing
15 / 46
Michael T. Heath
Scientific Computing
16 / 46
Scientific Computing
Approximations
Computer Arithmetic
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
Scientific Computing
Approximations
Computer Arithmetic
Example, continued
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
For x = 1,
Condition number :
x
= arccos(
y ) = arccos(0.5) 1.0472
Forward error:
y = y
Backward error:
x=x
y 0.5
0.5403 =
x 1.0472
cond =
0.0403
1 = 0.0472
|[f (
x) f (x)]/f (x)|
| y/y|
=
|(
x x)/x|
| x/x|
Scientific Computing
17 / 46
Michael T. Heath
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
Scientific Computing
Approximations
Computer Arithmetic
Condition Number
Scientific Computing
18 / 46
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
relative
relative
= cond
forward error
backward error
Michael T. Heath
Scientific Computing
19 / 46
Scientific Computing
Approximations
Computer Arithmetic
x) f (x)
f 0 (x) x
f (x)
f (x)
Scientific Computing
20 / 46
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
Stability
Algorithm is stable if result produced is relatively
insensitive to perturbations during computation
Michael T. Heath
Michael T. Heath
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
Example: Sensitivity
Scientific Computing
Approximations
Computer Arithmetic
f (x) f 0 (x) x
relative
relative
/ cond
forward error
backward error
Scientific Computing
Approximations
Computer Arithmetic
f (x +
x)
Scientific Computing
21 / 46
Sources of Approximation
Error Analysis
Sensitivity and Conditioning
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
Accuracy
Scientific Computing
22 / 46
Floating-Point Numbers
Floating-Point Arithmetic
Floating-Point Numbers
Number x is represented as
dp
d1
d2
x = d0 +
+ 2 + + p
Scientific Computing
where 0 di
23 / 46
1, i = 0, . . . , p
Michael T. Heath
1
1
1, and L E U
Scientific Computing
24 / 46
Scientific Computing
Approximations
Computer Arithmetic
Scientific Computing
Approximations
Computer Arithmetic
Floating-Point Numbers
Floating-Point Arithmetic
Floating-Point Numbers
Floating-Point Arithmetic
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
Scientific Computing
25 / 46
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
Floating-Point Numbers
Floating-Point Arithmetic
Normalization
Scientific Computing
26 / 46
Floating-Point Numbers
Floating-Point Arithmetic
2(
p 1 (U
1)
L + 1) + 1
U +1 (1
p)
Scientific Computing
27 / 46
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
Floating-Point Numbers
Floating-Point Arithmetic
Scientific Computing
28 / 46
Floating-Point Numbers
Floating-Point Arithmetic
Rounding Rules
If real number x is not exactly representable, then it is
approximated by nearby floating-point number fl(x)
This process is called rounding, and error introduced is
called rounding error
= (0.5)10
Scientific Computing
29 / 46
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
Floating-Point Numbers
Floating-Point Arithmetic
Machine Precision
Scientific Computing
30 / 46
Floating-Point Numbers
Floating-Point Arithmetic
1
2
1 p
1 p
Scientific Computing
24
mach = 2
53
10
10
in single precision
16
in double precision
fl(x) x
mach
x
Michael T. Heath
mach = 2
31 / 46
Michael T. Heath
Scientific Computing
32 / 46
Scientific Computing
Approximations
Computer Arithmetic
Scientific Computing
Approximations
Computer Arithmetic
Floating-Point Numbers
Floating-Point Arithmetic
Floating-Point Numbers
Floating-Point Arithmetic
Scientific Computing
Scientific Computing
Approximations
Computer Arithmetic
33 / 46
Floating-Point Numbers
Floating-Point Arithmetic
Exceptional Values
Scientific Computing
34 / 46
Floating-Point Numbers
Floating-Point Arithmetic
Floating-Point Arithmetic
Addition or subtraction : Shifting of mantissa to make
exponents match may cause loss of some digits of smaller
number, possibly all of them
Michael T. Heath
Scientific Computing
Scientific Computing
Approximations
Computer Arithmetic
Floating-Point Numbers
Floating-Point Arithmetic
Scientific Computing
37 / 46
Floating-Point Numbers
Floating-Point Arithmetic
Scientific Computing
38 / 46
Floating-Point Numbers
Floating-Point Arithmetic
1
X
1
n
n=1
n
X1
k=1
1
k
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
Floating-Point Numbers
Floating-Point Arithmetic
Michael T. Heath
36 / 46
Scientific Computing
Approximations
Computer Arithmetic
Scientific Computing
= 10, p = 6
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
Scientific Computing
39 / 46
Michael T. Heath
Scientific Computing
40 / 46
Scientific Computing
Approximations
Computer Arithmetic
Scientific Computing
Approximations
Computer Arithmetic
Floating-Point Numbers
Floating-Point Arithmetic
Cancellation
Floating-Point Numbers
Floating-Point Arithmetic
Cancellation, continued
Despite exactness of result, cancellation often implies
serious loss of information
For example,
1.92403 102
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
Scientific Computing
Floating-Point Numbers
Floating-Point Arithmetic
Cancellation, continued
Year
1971
1977
1980
1985
1988
Scientific Computing
43 / 46
Floating-Point Numbers
Floating-Point Arithmetic
Potential
14.0
14.02
14.35
14.65
14.84
Total
1.0
1.26
2.13
2.37
2.44
Michael T. Heath
Scientific Computing
44 / 46
Floating-Point Numbers
Floating-Point Arithmetic
i=1
!# 1
2
n
x
i=1
Kinetic
13.0
12.76
12.22
12.28
12.40
Scientific Computing
Approximations
Computer Arithmetic
Michael T. Heath
Floating-Point Numbers
Floating-Point Arithmetic
42 / 46
Scientific Computing
Approximations
Computer Arithmetic
Scientific Computing
Example: Cancellation
ex = 1 + x +
Michael T. Heath
Scientific Computing
Approximations
Computer Arithmetic
45 / 46
Michael T. Heath
Scientific Computing
46 / 46