Professional Documents
Culture Documents
Numerical Methods
Fiorella Sgallari
University of Bologna, Italy
Faculty of Engineering
Department of Mathematics - CIRAM
Numerical Methods
Numerical Methods:
Algorithms that are used to obtain numerical
solutions of a mathematical problem.
Why do we need them?
1. No analytical solution exists,
2. An analytical solution is difficult to obtain
or not practical.
Number Representation
Normalized Floating Point Representation
Rounding and Chopping
Well-posedness and Condition Number of a Problem
Stability of Numerical Methods
Error sources
1. Simplified mathematical model
2. Errors in data
1. Systematic errors due to instruments
2. Random errors
3. Rounding in data and computation
4. Discretization error
These errors are introduced when an infinite procedure is
approximated by a finite procedure.
• Derivatives by finite differences
• Integrals by quadrature formulas
± 3 1 2 . 4 5
sign integral fractional
part part
0.003221x104 no
x = ± 0 . a 1 a 2 .... × β p
0 ≤ a i ≤ β − 1, a1 ≠ 0
p 1
x = ± m × β , ≤ m < 1
β
± 0. 1 b2 b3 ... × 2 p
sign mantissa exponent
b1 ≠ 0 ⇒ b1 = 1
(0.1)10 = (0.000110011001100...) 2
F(β
β, t, L, U) =
{x ∈ ℜ = ± ( a 1β
−1
+ a2β −2
+ ... a t β −t
)β p
}∪ {0}
0 ≤ a i ≤ β − 1, a1 ≠ 0
Card(F(β
β, t, L, U) ) = 2 (β β t-1 (U-L+1) +1
β-1)β
The floating-point numbers are not equally spaced along the real line
Ex: Card{1,2,3,4}=4
Numerical Methods F. Sgallari Dept. Mathematics-CIRAM, Universityof Bologna 11
F(2,3,-1,2)
x x
β=10 t=4
X=0.3798165 x = fl ( x ) = 0.3798
rounding
y=0.1265873
y = fl ( y ) = 0.1266
p p
Let x = mβ , x = fl ( x ) = m β
Absolute Error
x − fl (x)
Relative Error
x − fl ( x)
x
Numerical Methods F. Sgallari Dept. Mathematics-CIRAM, Universityof Bologna 17
Sia x = mβ p , x = fl ( x ) = m β p
Chopping Rounding
Absolute Error
p− t 1 p−t
x − fl ( x ) < β x − fl ( x ) ≤ β
2
Relative Error
x − fl ( x ) x − fl ( x ) 1 1− t
≤ β 1− t ≤ β
x x 2
Numerical Methods F. Sgallari Dept. Mathematics-CIRAM, Universityof Bologna 18
Machine precision-roundoff unit
β 1− t chopping
x − fl ( x )
≤ eps eps = 1 1− t
x β rounding
2
fl(1+eps)>1
We say the estimate is correct to n decimal digits if
Rel. Error ≤ 10− n
We say the estimate is correct to n decimal digits rounded if
1
Rel. Error ≤ × 10− n
2
1 8 23
Exponent p* Mantissa m
p* = p + 127, 0 ≤ p* ≤ 255
Segno (0/1) ‘m has 24 bit , the first 1 is implicit’
1− 24
1 1−t 2
eps = 2 = = 5.9605e - 008
2 2
Double precision 64 bit base 2
1 1−t 21−53
eps = 2 = = 1.1102e - 016
2 2
Matlab uses IEEE arithmetic with double precision
zero
0/1 0 0
NaN=not a number
0/1 111.....1111 ≠0
Infinite (overflow)
0/1 111.....1111 0
x + (y + z) = (x + y) + z
This is due to the fact that after the difference fl(x1)-fl(x2)=0.000302 and
floating point representation we have three zeros at the end of mantissa.
Relative error ~ 10-3
x2-6.433 x + 0.009474 = 0
x − fl ( x ) 36%
≅ 0.357
x
Error in b Error in ∆
Numerical Methods F. Sgallari Dept. Mathematics-CIRAM, Universityof Bologna 27
Example
a2+b x + c = 0
2
−b± b − 4 ac
x1, 2 =
2a
Numerical canc .error in x1 if ∆ ≈ b , or in x2 if ∆ ≈ −b
To avoid this:
c c
x1 ⋅ x2 = → x2 =
a x1
If b 2 ≈ 4ac it is useful to use great precision
Numerical Methods F. Sgallari Dept. Mathematics-CIRAM, Universityof Bologna 28
Condition Number of a Problem –
Stability of Numerical Methods
x f y Numerical algorithm: ψ
Perturbed data:
~
x = x + δx
x f ( x) = y
Propagation of errors? ~
x f (~x) = ~y
ψ ( ~x ) = ψ~
~
f ( x) − f ( x ) ~
x−x
≤K
f ( x) x
A Problem is called ill-conditioned if K(d) is “big” for any admissible
datum d (the precise meaning of “small” and “big” is going to change
depending on the considered problem).
integration by parts:
1
∫x
0
n x −1
e dx = [n x −1 1
x e 0
] 1
− ∫ nx
0
n −1 x −1
e dx
Recursive formula
1
En = 1 − nEn−1 n = 2, 3, ... E1 =
e
while x9ex-1>0
in (0,1)
1
E1 = , E1 = E1 + δ , δ ≈ 4.412 ⋅ 10−7
e
When computing E2 such error is multiplied by –2,
E 2 = 1 − 2 E1 = 1 − 2 E1 − 2δ = E 2 − 2δ
When computing E3 by –3, and so on.
At the end E9 by (-2)(-3)…(-9). So
n −1
E n = 1 − nE n −1 = E n + ( −1) n !δ
9!* 4.412 ⋅ 10 −7 ≅ 1.1601
Numerical Methods F. Sgallari Dept. Mathematics-CIRAM, Universityof Bologna 34
Example: unstable algorithm
1 − En
E n −1 = n = ...., 3, 2
n
∫x dx ≤ ∫ x =
n x −1 n
En = e =
0 0 n + 1 0 n +1
En → 0 approximate E20 = 0
n →∞
1 − En
E n −1 = n = ...., 3, 2 E 20 = 0
n
1
E20 = 0 Initial Error ≈
21
1
1 − E20 1 − E20 − 21
E19 = = =
20 20
1 − E20 1 1 1
= − ≈ ≅ 0.0024
20 20 ⋅ 21 20 21
β=2 t=90
α)=x20-α
p(x,α α x19+….=0 α parameter
∂ p( x , α ) ∂ x ∂ p( x , α )
+ =0
∂x ∂α ∂α
19
∂x ∂p( x, α ) / ∂α x
=− = 20
∂α ∂p( x,α ) / ∂x
∑∏
20
j =1 ( x − j)
j ≠i
19 i =1
∂x i
= 20
i =1, 2 ,...,19 , 20
∂α x =i ∏ j =1 (i − j )
j ≠i
Measure unity
FLOP (floating point operation)
Hypothesis:
Execution time for 1 multiplication about 10-6 seconds (old computer)