Lec 3
Lec 3
Chang YANG
Autumn semester
1 / 29
References
2 / 29
I. Definition
Numerical analysis is the study of algorithms that use numerical
approximation for the problems of mathematical analysis.
II. Motivations
(i) Experimental study is very expensive. Alternatively, mathematical
models are developed.
(ii) To find the solution of the models: the explicit solution may not exist; or
they exist but they are not appropriate for practical use...
(iii) Propose an approximated solution, calculated by a computer.
3 / 29
Outline
1 Error analysis
4 / 29
Table of contents
1 Error analysis
5 / 29
Sources of error
(i) Errors due to the model, that can be controlled by a proper choice of the
mathematical model.
(ii) Errors in the data, that can be reduced by enhancing the accuracy in the
measurement of the data themselves.
(iii) Truncations errors, arising from having replaced in the numerical model
limits by operations that involve a finite number of steps.
(iv) Round-off errors, arising from limitation of computer.
6 / 29
Measurement of error
7 / 29
Measurement of error
|x − x ∗ |
Er (x ∗ ) = ≤ 1.59 × 10−6 .
|x ∗ |
8 / 29
Measurement of error
Significant Figure
Let x be the exact value, x ∗ be an approximation.
Assume x ∗ = ±10k × 0.a1 a2 . . . an . . . , with ai ∈ {0, . . . , 9} and a1 6= 0.
1
If |x − x ∗ | ≤ 2 × 10k −n , then x ∗ has n significant figures.
Theorem
1
(i) If x ∗ has n significant figures, then Er (x ∗ ) ≤ 2a1 × 101−n .
1
(ii) If Er (x ∗ ) ≤ 2(a1 +1) × 101−n , then x ∗ has at least n significant figures.
9 / 29
Table of contents
1 Error analysis
10 / 29
Represent a real number with basis b
x = ±m × be , with b ≥ 2.
where
Fraction m:
Exponent e:
11 / 29
Standard IEEE (754-1985)
Fraction: 52 bits
12 / 29
Exercises
Exercise 1
Compute
the largest number of F: Xmax .
the smallest positive number of F: Xposmin .
Exercise 2
Propose two algorithms to determine a numerical approximation of Xmax and
Xposmin respectively.
13 / 29
Round-off error
Exercise
Compute the smallest number such that rd(x + 0.5) > 0.5.
Refind this number by a numerical algorithm.
14 / 29
Table of contents
1 Error analysis
15 / 29
Conditioning of a numerical problem
Definition
The conditioning represents the sensibility of result of a numerical problem
with respect of small variations of data.
Well-conditioned: a small variation of data leads a small variation of
result.
Ill-conditioned: a small variation of data leads a large variation of result.
Example: Let f : R → R
Taylor expansion
Conditioning
δf x xf 0 (x)
k= ' .
f δx f (x)
16 / 29
Conditioning of arithmetic operations
Conditioning is determined by
∂f xi
ki = .
∂xi f (x)
Exercise
Compute the conditioning of addition and multiplication operations.
17 / 29
Stability of an algorithm
Definition
The stability of an algorithm refers to propagation of errors during
computational steps, to the precision of the obtained results, to the capacity
of algorithm of not amplify much possible gap.
Exercise
Propose a more stable algorithm.
18 / 29
Complexity of an algorithm
Definition
Number of elementary operations carried out by the algorithm (+, ×, sqrt,
power, . . . )
Pn
Example: Evaluation of polynomial p(x) = i=0 ai x i :
Pn
Number of multiplications: i=0 i = n(n+1)
2 .
Number of additions: n.
algorithmic cost: O(n2 ).
Definition
Polynomial cost: O(nk ).
Exponential cost: O(an ).
Factorial cost: O(n!).
Pn
Example: Evaluation of polynomial p(x) = i=0 ai x i :
Horner’s method: p(x) = a0 + x(a1 + x(a2 + x(. . . an ))).
algorithmic cost?
19 / 29
Table of contents
1 Error analysis
20 / 29
Avoid subtraction of two similar numbers
y = 0.015807437428958.
√ Now, we √
take only four significant figures in
computation, then x + 1 ≈ 31.64, x ≈ 31.62, thus y ≈ y ∗ = 0.02. It rests
only one significant figure.
|y − y ∗ | |0.015807437428958 − 0.02|
Er (y ∗ ) = = = 20.96%.
|y ∗ | 0.02
21 / 29
Avoid divisor with very small absolute value
Example:
x
z=
y
Let x = 2.7182, y = 0.001, the exact z = 2718.2. In the case the divisor has
a turbulence y ∗ = 0.0011, then
x∗ 2.7182
z∗ = ∗
= ≈ 2471.1.
y 0.0011
22 / 29
Avoid large number ’eat’ small number
x 2 − (1 + 10−16 )x + 10−16 = 0.
It is easy to find the two exact solutions are x1 = 1, x2 = 10−16 . By the roots
formulae p
1 + 10−16 ± (1 + 10−16 )2 − 4 × 10−16
x1,2 = .
2
Because
p of round-off error, we have rd(1 + 10−16 ) = 1,
rd( (1 + 10−16 )2 − 4 × 10−16 ) = 1, thus x1 = 1, x2 = 0. Obviously, x2 is
wrong. To correct this fault, we recast x2 as follows
10−16
x2 = = 10−16 . (1)
x1
23 / 29
Simplify complexity of an algorithm
x 255 = x · x 2 · x 4 · x 8 · x 16 · x 32 · x 64 · x 128 .
24 / 29
Simplify complexity of an algorithm
x 255 = x · x 2 · x 4 · x 8 · x 16 · x 32 · x 64 · x 128 .
25 / 29
Use more stable algorithm
R1 xn
Example: Let In = 0 x+5
dx, then compute I20 .
We notice that
1 1
x n + 5x n−1
Z Z
1 n1 1
In + 5In−1 = dx = x n−1 dx = x | = .
0 x +5 0 n 0 n
1
we thus find a recurrence formula In = n − 5In−1 . Moreover,
R1 1
I0 = 0 x+5 dx = ln(x + 5)|10 = ln 65 .
In = n1 − 5In−1 ,
(A)
I0 = ln 56 .
26 / 29
Use more stable algorithm
1 1
< In−1 < , (n > 1).
6n 5n
∗
We thus can use I40 = 12 ( 6×41
1
+ 1
5×41 ) to approximate I40 .
27 / 29
Complementary exercises
Exercise
Calculate Z 1
In = e−1 x n ex dx.
0
In = 1 − nIn−1 .
28 / 29
Complementary exercises
Exercise
How to avoid loss significant figures :
(i) 1 − cos(x), x is near 0.
√ √
(ii) ( 1 + x 2 − 1 − x 2 )−1 , x is near 0.
(iii) x − sin(x), x is near 0.
Exercise
Assume x1∗ = 1.216, x2∗ = 3.654 have 3 significant figures, then find the
relative error bound of x1∗ x2∗ .
29 / 29