Ch1 Introduction To Numerical Methods
Ch1 Introduction To Numerical Methods
I. Introduction
1.1 Why Numerical Method?
Example 1. y
T/y=0 (insulated)
Steady state heat conduction
D C
Governing equation:
2
T= 0 T=T 1 Heat flow
T/x
=0
How do we determine the heat flow
from wall AB to wall AD?
Possible solutions: A
B x
1. Experiment T=T2 > T 1
2. Analytical solution
3. Numerical solution
y
T/y=0 (Insulated)
Example 2
. D C
Steady state heat conduction G
Example 3.
Unsteady state heat conduction in a non-simple geometry:
T
= T
t
yn yn+1
t
... t
t1 t2 tn t n+1
Questions:
Why the solution blows up for t=0.5?
How to detect/prevent numerical instability (blowing up) in general?
How to improve accuracy (c.f. the case with t=0.05)?
How to get solution efficiently if a large system is solved?
0.5
0.6
y
0.6
0.4
0.7
0.8
0.2
0.9
0.0
0.0 0.2 0.4 0.6 0.8 1.0
x
Steady Temperature with a Block
1.0
0.1
0.8 0.2
0.3
0.6 0.4
y
0.4 0.5
0.6 0.7
0.8
0.9
0.2
0.0
0.0 0.2 0.4 x 0.6 0.8 1.0
a b x
x x
f(a)
a b x
1.2.3 Integral Mean Value Theorem (IMVT)
Let w(x) be nonnegative and integrable on [a, b] and let f(x) be
continuous on [a, b]. Then
b b
w(x) f(x) dx = f() w(x) dx (2)
a a
(This figure shows the approximation of f(x) using 0th, 1st, & 2nd
order Taylor series expansions.)
-1 x3 x5 x 7 x9
tanh (x) = x + + + + + ... ,
3 5 7 9
x2 x3
ln (1+x) = x - + +… |x|< 1
2 3
1+ x 2x3 2x5 2x 7
ln = 2x + + + + ... |x|<1
1− x 3 5 7
1
+ Dn+1f(x, y) |x0+ ,y0+ (8)
(n + 1)!
where D + and 0≤ ≤1.
x y
2 3 1/ 2
Example: Consider f(x, y) = ln[ 1 + x + xy + y ]
Find its Taylor series expansion near x=y=0.
Solution: Method 1.
1 2 3
f(x, y) = ln[ 1 + 2 x + x + xy + y ] , f(0, 0)=0
2
f 2 + 2x + y f
= , (0,0) = 1 ;
x 2[1 + 2 x + x 2 + xy + y 3 ] x
f x + 3y2 f
= , (0,0) = 0 ;
y 2[1 + 2 x + x 2 + xy + y 3 ] y
2 f 2[1 + 2 x + x 2 + xy + y 3 ] − (2 + 2 x + y )( 2 + 2 x + y )
= ,
x 2 2[1 + 2 x + x 2 + xy + y 3 ]2
2 f
(0,0) = −1 ;
x 2
2 f 6 y[1 + 2 x + x 2 + xy + y 3 ] − ( x + 3 y 2 )( x + 3 y 2 )
= ,
y 2 2[1 + 2 x + x 2 + xy + y 3 ]2
2 f 1 + 2 x + x 2 + xy + y 3 − ( x + 3 y 2 )( 2 + 2 x + y )
= .
xy 2[1 + 2 x + x 2 + xy + y 3 ]2
2 f 1
(0,0) =
xy 2
1 1
Thus, f(x, y) ~ 0 + x + 0 • y + (−1) x 2 + xy + 0 • y 2 +…
2 2
1 1
= x − x 2 + xy + ...
2 2
Method II:
Let = 2 x + x 2 + xy + y 3
2 3
Note: ln (1+) = - + +…
2 3
1
ln[ 1 + 2 x + x 2 + xy + y 3 ]
2
1 2 3 1 2 3 2
= {[ 2 x + x + xy + y ] - [2 x + x + xy + y ] + …}
2 2
1 2 1 1
=x+ x + xy − (4 x 2 ) + ... = x − 1 x 2 + 1 xy + ...
2 2 4 2 2
(This approach is much simpler!)
1 x n (n+1)(t) dt = ( x − x0 ) n +1 (n+1)
Rn+1(x) = (x − t) f f ( ) (5)
n! x (n + 1)!
0
between x and x0.
= 0.15625
• The reason for having |L| <U is so that the reciprocal of the
smallest number, 1/2L, will not overflow. Although it is true that
the reciprocal of the largest number will underflow, underflow is
usually less serious than overflow.
B t L U Total
(mantissa) Length
IEEE SP 2 23 -126 127 32
IEEE DP 2 52 -1022 1023 64
1/10 = 1/24+1/25+1/28+1/29+1/212+1/213+…
= 0.0001100110011001100110011001100....
(=2-126-1= 5.877x10-39)
If x<xL underflow, i.e. computer may treat x as 0.
(~2127=1.7x1038)
If x> BEmax overflow;
computer treat x as "∞", Inf., or "NaN =Not a Number "
Ariane Rocket
On June 4, 1996 an
unmanned Ariane 5 rocket
was launched.
The rocket was on course for 36 seconds and then veered off
and crashed
The internal reference system was trying to convert a 64-bit
floating point number to a 16-bit integer.
This caused an overflow which was sent to the onboard
computer.
The on-board computer interpreted the overflow as real flight
data and bad things happened.
The destroyed rocket and its cargo were valued at $500 million.
The rocket was on its first voyage, after a decade of
development costing $7 billion.
added 1 to 7th 6.
* Example: T = 3.1415926535897932...
If A = 3.14159
then |roundoff error| = |A - T| = 0.00000265358979...
< 0.000005
A | round off error |
3.14 0.00159... < 0.005
3.142 0.00040... < 0.0005
3.1416 0.0000073 < 0.00005
Note: x = 5.2468 ~ 5.247, or x ~ 5.25 but x ≠ 5.3.
If you want to keep one decimal, then x ~ 5.2.
i.e. round off is not transitive.
Chopping:
M
This can cause skew in summuation of x j !!!
j =1
-- accuracy or precision
chopping: mach = B1-t ( = 21-23 = 2.384 x 10-7 for B=2, t=23)
1
rounding: mach = 2 B1-t (= 2-23 = 1.192x 10-7 for B=2, t=23)
Note: if x< mach then, 1+ x = 1 in machine computation.
1.E+00
f(x)=exp(x) abs(f'-1)
1.E-01
1.E-02 f'(0)=[exp(h)-1]/h
1.E-03
1.E-04
1.E-05
decreasing
1.E-06 increasing truncation error
1.E-07
due to
roundoff error
1.E-08
1.E-09
1.E-15 1.E-13 1.E-11 1.E-09 1.E-07 1.E-05 1.E-03 1.E-01 1.E+01
h
1.E-02 f'(0)=[exp(h)-1]/h
1.E-03
1.E-04
1.E-05
decreasing
1.E-06 increasing truncation error
1.E-07
due to
roundoff error
1.E-08
1.E-09
1.E-15 1.E-13 1.E-11 1.E-09 1.E-07 1.E-05 1.E-03 1.E-01 1.E+01
h
1.E+00
abs(f'-1)
1.E-01
1.E-02 abs(f2'-1)
1.E-03 R+TE1
1.E-04 R+TE2
1.E-05
1.E-06
1.E-07
1.E-08
1.E-09
1.E-10
1.E-11
h
1.E-12
1E-15 1E-13 1E-11 1E-09 1E-07 1E-05 0.001 0.1 10
= xT + yT - . (29)
Relative error:
xT yT − x A y A
Rel.( xA yA) = = + − . (30)
xT yT yT xT xT yT
Assuming «1 and «1, we obtain
xT yT
Rel.( xA yA) + = Rel.( xA) + Rel.( yA). (31)
yT xT
132 − 168 1 1
Improvement: rA = = =
13 + 168 13 + 168 13 + 12.961
= 0.038519 with 5 significant digits.
0.038518603... − 0.038519
= Rel. (rA ) = = -1.03x10-5
0.038518603...
= Error(fA) yA ( x A ) y A −1 Error(xA)
+ ( x A ) y A logxA Error(yA)
16
15
2000000
4000000
6000000
8000000
10000000
12000000
14000000
16000000
18000000
Clearly, the result based on summation using single
precision and adding from large to small values are most
unsatisfactory (since it is already converged).