Professional Documents
Culture Documents
Chapter 1 - Introduction
Chapter 1 - Introduction
Engineering Analyses
of Numerical Methods
Lecture 1
Syllabus
Introduction
1.1 Why Numerical Method?
Example 1
Possible solutions:
1. Experiment A B
T=T2
2. Analytical solution -- possible for this geometry
3. Numerical solution -- solving elliptic PDE
1.1 Why Numerical Method?
y
D
Represent the field by a series of nodes. C j=Ny
2T 2T
Use central differences for the second order derivatives + =0
x 2 y2
…
Ti,j
A system of linear algebraic equations for Ti,j j
…
Solve the system of equations to get Ti,j
Dy … …
Plot contour, compute flux,… Dx
x
j=1
A i B
i=1 i=Nx
Ti,j+1
Ti,j-1
1.1 Why Numerical Method?
Example 2
T(x, y) =? T=T1<T2
T/x=0
Possible solutions:
1. Experiment
A B
2. Analytical solution? -- not possible for this geometry T=T2
Example 3 D T/y=0 C
T
t
= a 2 T T=T1<T2
T/x=0
2. Analytical solution -- not possible for this geometry
3. Numerical solution -- solving parabolic PDE
A B
T=T2
Also need to discretize in time
Cautions:
Tn • NO numerical method is completely trouble free in all situations.
• NO numerical method is completely error free.
• NO numerical method is optimal for all situations.
• Be careful about:
t ACCURACY, EFFICIENCY, & STABILITY.
t1 t2 tn
1.1 Why Numerical Method?
3 0.125 0 -1 0.4
-640
0.3
4 0.0625 0 1 256
0.2
5 0.03125 0 -1 -1024 0.1
6 0.0156250 0 1 2048 0
7 0.0078125 0 -1 … -0.1
0 0.5 1 1.5 t
Comments: ok inaccurate oscillate blow up
“minimum” m m
a x b x
x x
Then for any number z in the interval [m, M], there is at least one point x in [a, b] for which
f(x) = z.
In particular, there are points and in [a, b] for which
m = f( x ) and M = f(𝑥).
ҧ
EGM 6341
Engineering Analyses
of Numerical Methods
Lecture 2
Math preliminary
1.2 Mathematical Preliminary
f(a)
Let w(x) be nonnegative (w≥0) and integrable on [a, b] and Graphical interpretation of the theorem
let f(x) be continuous on [a, b].
Then
b
b
a
w(x) f(x) dx = f(x)
a
w(x) dx (2)
Let f(x) have n+1 continuous derivatives on [a, b] for some n≥0
and let x, x0[a, b]. Then y=f(x)
f(x) = Pn(x) + R n+1(x) (3)
where
f ( x0 )
Pn ( x) = f ( x0 ) + f ( x0 )( x − x0 ) + ( x − x0 ) 2 [ ]
2!
a b x
f ( x0 ) ( x − x0 ) n ( n ) x0
+ ( x − x0 ) + ...
3
f ( x0 ) (4)
3! n!
x
1
Rn+1(x) = ( x − t ) f(n+1)(t) dt
n
(5)
n! x
0
x
1
n ! x
(IMVT) = f (n+1)(x) ( x − t ) n
dt (x between x0 & x)
0
n +1
( x − x0 )
= (n + 1)! f (n+1)(x) (5’)
= truncation error of the expansion = T.E.
Taylor Series illustration
f ( x0 ) f ( x0 )
f ( x) = f ( x0 ) + f ( x0 )( x − x0 ) + ( x − x0 ) +
2
( x − x0 )3 + ...
2! 3!
1.4
0th order
1.2 f ( x) ~ f ( x0 )
1
True f ( x) ~ f ( x0 ) + f ( x0 )( x − x0 )
0.8
0.6 f(x)
f ( x0 )
0.4
zero f ( x) = f ( x0 ) + f ( x0 )( x − x0 ) + ( x − x0 ) 2
1st Order
2!
f(x)
0.2 2nd Order
0
-0.1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1
Truncation Error in Taylor Series Expansion
Taylor series expansion
( x − x0 ) 2 ( x − x0 )3
f ( x) = f ( x0 + x − x0 ) = f ( x0 ) + ( x − x0 ) f ( x0 ) + f ( x0 ) + f ( x0 ) + ....
2! 3!
x3 x5 x 7 x9
f ( x) = sin x = x − + − + + ....
3! 5! 7! 9!
Examples: Truncation Error in Taylor Series Expansion
Taylor series expansion of f(xi+1) & f(xi-1) based on f(xi)
( x − x0 ) 2 ( x − x0 )3
f ( x) = f ( x0 + x − x0 ) = f ( x0 ) + ( x − x0 ) f ( x0 ) + f ( x0 ) + f ( x0 ) + ....
2! 3!
( x − a)2 ( x − a )3
or f ( x) = f (a + x − a) = f (a) + ( x − a) f ( a) + f ( a) + f ( a) + ....
2! 3!
xi-1 xi+1
x Set x0=a=xi, let x = xi+1, h= x – a = xi+1 – a =>
a=xi
h2 h3
f ( xi +1 ) = f ( xi + h) = f ( xi ) + hf ( xi ) + f ( xi ) + f ( xi ) + ....
2! 3!
h2 h3
f ( xi −1 ) = f ( xi − h) = f ( xi ) − hf ( xi ) + f ( xi ) − f ( xi ) + ....
2! 3!
Soln. For f(x) = sin(x) f ′(x) = cos(x), f ″(x) = -sin(x), f ‴(x) = -cos(x), f (4)(x) = sin(x)
@ x0 =0, f ′(0) =1, f ″(0) = 0, f ‴(0) = -1, f (4)(0) = 0
0.012
Integration by parts =>
𝑥 𝑥
11 4ቚ
𝑥 1 0.01
R4
R4(x) = [sin( 𝑥 − 𝑧) 𝑧 + න 𝑧 4 cos( 𝑥 − 𝑧) 𝑑𝑧] = න cos( 𝑢)(𝑥 − 𝑢)4 𝑑𝑢 sin(x)-P3(x)
3! 4 0 4!
0 0 0.008
𝑥
1 x5
(IMVT=>) = cos( 𝜉) න(𝑥 − 𝑢)4 𝑑𝑢
4!
= cos(x ) 0.006
0 5! 0.004
5
x
Hence sin(x) = x – x3/3! + 5! cos(x ) for x between 0 and x. 0.002
x
Since cos(x) ~1 for small |x| so that R4 ~x5/5! 0
0 0.2 0.4 0.6 0.8 1 1.2
1.2 Mathematical Preliminary
n
f(x0+x, y0+h) = f(x0, y0) +
1 m
D f ( x, y ) +
1 Dn+1f(x, y) |x0+qx ,y0+qh (8)
m =1 m! x
0 , y0
(n + 1)!
where D =x +h
x y
𝜕 2 𝜕 2 𝜕 2
𝐷2 = 𝜉2 2 + 2𝜉𝜂 + 𝜂2 2
𝜕𝑥 𝜕𝑥𝜕𝑦 𝜕𝑦
𝜕𝑓 2 + 2𝑥 + 𝑦 𝜕𝑓
Sol: f(0, 0) = 0, = (0,0) = 1;
𝜕𝑥 2[1 + 2𝑥 + 𝑥 2 + 𝑥𝑦 + 𝑦 3 ] 𝜕𝑥
𝜕𝑓 𝑥 + 3𝑦 2 𝜕𝑓
= (0,0) = 0
𝜕𝑦 2[1 + 2𝑥 + 𝑥 2 + 𝑥𝑦 + 𝑦 3 ] 𝜕𝑦
𝜕 2 𝑓 2[1 + 2𝑥 + 𝑥 2 + 𝑥𝑦 + 𝑦 3 ] − (2 + 2𝑥 + 𝑦)(2 + 2𝑥 + 𝑦) 𝜕2 𝑓
= (0,0) = −1
𝜕𝑥 2 2 1 + 2𝑥 + 𝑥 2 + 𝑥𝑦 + 𝑦 3 2 𝜕𝑥 2
1 1
Thus, f(x, y) ~ 0 + 𝑥 + 0 • 𝑦 + (−1)𝑥 2 + 𝑥𝑦 + 0 • 𝑦 2
2 2
1 1
= 𝑥 − 2 𝑥 2 + 2 𝑥𝑦+. . .
1.2 Mathematical Preliminary
i. Periodic functions
p=2L
note: f(x+2L) = f(x) -5L -3L p -L 0 L -3L x
Errors
Blunders
It is not included in the approximation; but we need to understand Rn+1(x) in order to understand TE.
What about roundoff error? first look into floating point arithmetic
1.4 Floating Point Arithmetic
1.4.1 Anatomy of a floating-point number
• A floating point number x is represented in scientific notation as “ ”
x = .d1d 2 d3 d p Be ; x=±
𝑑1
𝐵
𝑑 𝑑 𝑑p
+ 𝐵22 + 𝐵33 + ⋯ + 𝐵𝑝 𝐵𝑒
= sign
B = number base: 2 or 10 or 16; it is fixed for a given computing device
d1d2 ... dp = mantissa or fractional part of significand; d1 ≠ 0; 0≤di ≤B-1, i=1, 2...p
• To store “E”, the exponent is stored with 127 added to it "biased with 127".
none of the 8 bits is used to store the sign of the exponent E. Thus for single precision,
• Thus the actual exponent e is equal to “E” – 127.
• Since “E”=255 is for X =NaN, the largest “E” is 254 U= 254-127 = 127 -126=L ≤ e ≤ U=127
• If “E”=0 and F ≠ 0, then X =(-1)** S * 2 ** (-126) * (0.F)
These are "unnormalized" values. Thus for DOUBLE precision,
That is why L = -126 for the lower bound of e. -1022 ≤ e ≤ U=1023
• If “E”=0, F = 0, and S = 1, then V=-0
• If “E”=0, F = 0, and S = 0, then V=0
IEEE Standard
S EE…EEEE FFFFFFFFF…FFFFFFFFFFF
01 11 12 63
B m L U Total
(mantisa) Length
Rounding:
e.g. xT = 2/3 = 0.66666666...
To keep 4 decimal points,
rounding to nearest → xA =0.6667 5th 6 > 5/10 (half of the base—10)
added 1 to 4th 6
Chopping:
e.g. x = 2/3 = 0.666666666...
To keep 4 decimal points,
chopping → xA =0.6666
i.e. chop everything off after 4th decimal.
* Example: Chopping xT = 25.24685 to 3 decimals
Solution: xA = 25.246 regardless the magnitude of the next number “8”.
• In Excel: e = 1.67E-15
n x=1/2^n y=1+x y-1
45 2.8422E-14 1.0000000000000300 2.8422E-14
46 1.4211E-14 1.0000000000000100 1.4211E-14
47 7.1054E-15 1.0000000000000100 7.1054E-15
Significant Digits
Propagation of Errors
1.5 Significant Digits
Definition: XA has m significant digits w.r.t. XT if the error |XT -XA | has magnitude ≤5 in the (m +1)th digits counting from
the left of the first non-zero digit in XT.
Examples:
1. XT = 3 . 1 7 2 8 6
1 2 3 4 56
If XA = 3.17, then | XT -XA| = 0.0 0 286 < 0. 0 0 5
1 2 3 4 m + 1= 4 m =3
Example: Truncation error & roundoff error in computing f ′(x0) using forward difference method
>> dx=logspace(-15,-0.5,20001);
Matlab results
>> fp=(exp(2+dx)-exp(2))./dx;
>> err=(abs(fp-exp(2)))';
>> plot(log10(dx),log10(err))
Log10(err)
Log10(dx)
Truncation + Roundoff Errors
Forward difference method: f ′(x, dx) = [f(x +dx) – f(x)] / dx dx: 10-15 to 10-0.5
>> fp=(exp(2+dx)-exp(2))./dx;
= exp(2)[exp(dx)-”1” ]
Total error
e1 e2
exp(2)[ e1 + e2]
Log10(err)
< exp(2)*2emach
Total error = RE + TE
~ 2emach exp(2)/dx +exp(2)/2*(dx)
Log10(dx)
1.7 Propagation of Errors
Compute r = 13 - 168 (= x – y) .
Lesson: avoid subtraction of two close numbers! Whenever you can, use double precision.
1.7.5 Induced error in evaluating functions
f(xT, yT) - f(xA, yA) 𝑓𝑥′ (xA, yA) (xT − xA) +𝑓𝑦′ (xA, yA) (xT − xA) + o(xT - xA, xT - xA) (39)
Error(fA) 𝑦𝐴 𝑥𝐴 𝑦𝐴 −1
Error(xA) + 𝑥𝐴 𝑦𝐴
log(xA) Error(yA)
𝑀
Consider S= 𝑥𝑗 (40)
𝑗=1
sk+1 = (sk + xk+1) (1 + ek+1) = (x1 + x2+ x3 +... xk+1) + e2(x1 + x2) + e3(x1 + x2+ x3) + ...
+ (x1 + x2+ x3+... +xk+1) ek+1 (41d)
1.7.6 Error in summation
ii) summing from k=M to 1 using single precision (single: small to large)
M
1
iii) summing from k=1 to M using double precision (double: large to small) k
k =1
iv) summing from k=M to 1 using double precision (double: small to large)
asymptote = ln(M)+ 0.5772156649015328
M SP: large to small SP: small to large DP: large to small DP: small to large asymptote
16384 10.2813063 10.28131294 10.2813068 10.28130678 10.2812767
32768 10.9744091 10.97444344 10.9744387 10.9744387 10.9744225
65536 11.667428 11.66758823 11.6675783 11.66757825 11.6675701
131072 12.3600855 12.36073208 12.3607216 12.36072161 12.3607178
262144 13.0513039 13.05388069 13.0538669 13.05386689 13.0538654
524288 13.7370176 13.74705601 13.7470131 13.74701311 13.7470112
1048576 14.4036837 14.44023132 14.4401598 14.44015982 14.4401588
2097152 15.4036827 15.13289833 15.1333068 15.13330676 15.1333065
4194304 15.4036827 15.82960701 15.8264538 15.82645382 15.8264542
8388608 15.4036827 16.51415253 16.5196009 16.51960094 16.5195999
16777216 15.4036827 17.23270798 17.2127481 17.21274809 17.2127476
18
Sum
17
16
15
2000000
4000000
6000000
8000000
10000000
12000000
14000000
16000000
18000000
II. Root Finding
1.6
x
x=r
Example 1:
(This example illustrates how the intermediate value theorem is used to
derive other important results of interest.)
Given the Intermediate value theorem:
Let f(x) be continuous function on the finite interval a≤x≤b, and define
m = Infimum f(x), M = Supremum f(x)
a≤x≤b a≤x≤b
Then for any number z in the interval [m, M], there is at least one point in
[a, b] for which
f() = z.
Prove the Integral Mean Value Theorem:
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 (*)
a a
b
If w(x) dx = 0, then (*) is valid for any in [a, b].
a
b
If w(x) dx 0, then
a
b b
m w(x) f(x) dx / w(x) dx M
a a
b b
so that f() = w(x) f(x) dx / w(x) dx.
a a
b
Multiply w(x) dx on both sides we obtain (*).
a
x 1
Solution 1: factoring (1 + ) out first
x
1 x +1
(1 + )
2 1 x +1 1 x 2 1 x x + 1
lim x [(1 + ) − (1 + ) ] = lim x (1 + ) − 1
x → x +1 x x → x (1 + 1 ) x
x
x +1 x
1 x ( x + 2) x
2
= lim x (1 + ) − 1
x → x ( x + 1) 2 x +1
Let y=x+1, then the square bracket term in the above expression becomes
x +1 x
lim ( x + 2) x − 1
2 x +1
x → ( x + 1)
( y + 1) y ( y − 1) y −1
= lim − 1
y → ( y ) 2 y −1
1 y 1 y y
= lim 1 + 1 − − 1
y → y y y −1
y
= lim 1 −
1 y
− 1
y →
y y − 1
2
y y ( y − 1) 1 y ( y − 1)( y − 2) 1 y
= lim 1 − + − + − 1
y → 2 2! 4 3! 6 y −1
y y y
1 1 1 1
= lim 1 − + + ...1 + + + ... − 1
y → y 2! y 2
y y2
1 1
= lim 1 + − − 1 = lim −
y → 2y2 y → 2 y 2
1 1
= lim − +
x → 2( x + 1)2 6( x + 1)3
Hence,
1 x +1 1 x 1 x ( x + 2) x +1 x x
lim x [(1 +
2
) − (1 + ) ] = lim x (1 + )
2
− 1
x → x +1 x x → x ( x + 1) 2 x +1
1 x x2 x2
= lim (1 + ) − +
x → x 2(x + 1)2 6( x + 1)3
e
=
2
1 x
Solution 2: directly expanding (1 + )
x
Note: The standard binomial expansion gives:
1 x 1 x( x − 1) 1 x( x − 1)( x − 2) 1 x( x − 1)...( x − n + 1) 1
(1 + ) x = 1 + + + + ... + ...
x 1! x 2! x 2 3! x 3 n ! x n
1 x +1 x +1 1 ( x + 1) x 1 ( x + 1) x( x − 1) 1
(1 + ) = 1+ + + + ...
x +1 1! x + 1 2! ( x + 1) 2 3! ( x + 1) 3
( x + 1) x...( x − n + 2) 1
+ + ...
n! ( x + 1) n
Subtracting the above two expressions give
1 x +1 1
(1 + ) − (1 + ) x ] =
x +1 x
( x + 1) x ( x + 1) x( x − 1)
+ ... ( x + 1) x...( x − n + 2) 1 + ...
1 1
+
2! ( x + 1) 2 3
3! ( x + 1) n! ( x + 1) n
x( x − 1) 1 x( x − 1)( x − 2) 1
- − − ... x( x − 1)...( x − n + 1) 1 + ...
2 3
2! x 3! x n! xn
x x − 1 x( x − 1) 1 ( x − 1)( x − 2) 1
= − + −
2( x + 1) 2 x 6 ( x + 1) 2 6 x2
( x + 1) x...( x − n + 2) 1 x( x − 1)...( x − n + 1) 1
+ − + ...
n! ( x + 1) n n! xn
1 ( x − 1)(3x + 2) ( x − 1)( x − 2)...( x − n + 2) n − 2
= + + ... + [x + .h.o.t.]
2 x( x + 1) 2
6 x ( x + 1) 2
2(n − 2)! x n −1 ( x + 1) n −1
Comment:
• The first approach is clearly easier than the 2nd approach because the
2nd approach involve summing the contribution from an infinite series
while the first approach involves only the first three non-zero terms in
y
1 y
the Taylor series expansion of 1 − 2 and .
y y − 1
1.2
1 (sinx/x)^3
cosx
0.8
0.6
0.4
0.2
-0.2
0 0.5 1 1.5 x
For sin(x), expand the first 3 terms using Taylor series expansion at
x=0 gives
1 3 1 5 1
sin x = x − x + x -…> x − x 3
6 120 6
Hence, (sin x / x )
3
( 2
)
3
1 − x / 3! = 1 −
x2 x4 x6
+ −
2 12 216
.
x2 x4 x6 1 1 1 1
1− + − 1 − x 2 + x 4 − x 6 + x8
2 12 216 2! 4! 6! 8!
1 1 1 2 1 4
or + (− + )x − x 0 .
4! 216 720 8!
In the above inequality, the left hand side is decreasing on the interval
(0, /2] and the minimum value is attained at x= /2.
1 1 1 2 1 4
Furthermore, at x= /2, + (− + )( ) − ( ) 0 because
4! 216 720 2 8! 2
1 1 4 2 1 4 4
+ (− )( ) − ( ) 0 .
24 216 2 8! 2
3
sin x
Thus we have proved cos x (the equality holds at x=0) for
x
1
0 x .
2
Example 4 Illustration complicated Taylor series expansion
(This example illustrates how to perform Taylor series expansion for not so
common functions using the expansion for common functions)
Using Taylor series expansion to obtain the first 4 NON-ZERO terms for small :
1
i. x() = 1 + 2
4
1 1 2
ii. x() = 1 − (1 − + )
2 8
(In some applications, we can find exact solution in terms of small
parameters such as given above. It would be easier to understand the
solution if it is expressed in power series.)
Solution:
* We note that Taylor series expansion for f(z) = (1+z) (|z|«1) is
( − 1) ( − 1)( − 2)
f(z) = (1+z) = 1 + z + z2 + z 3 + ...
2! 3!
* We will apply the above result (binomial expansion) to both problems.
1 2 1 2
i. For 1 + , we note that if we let z and =1/2
4 4
we can directly apply the Taylor series expansion for f(z) = (1+z)
Thus,
1 1 1 11 1 1 11 1 1 1
1+ 2 = 1+ ( 2) + ( − 1)( 2 ) 2 + ( − 1)( − 2)( 2 ) 3 + ...
4 2 4 2! 2 2 4 3! 2 2 2 4
1 2 1 4 1 6
= 1+ − + + ... (note: =1/2, z = /4)
8 128 1024
Comment: the important thing is that we have avoided the tedious
1 2
procedures of evaluating the derivatives of f(x) = 1 + x
4
1 1
ii. For f() = 1 − (1 − + 2 ) , it is clear that the evaluation of the high
2 8
1.05 0.006
f( ) 1
0.005
0.95
0.9 exact 0.004
0.85 4-term expansion
0.003
0.8 error/eps^5
0.75 0.002
0.7
0.001
0.65
0.6 0
0 0.2 0.4 0.6 0.8 1 1.2
1 1
Fig. S1.1 Taylor series expansion for f() = 1 − (1 − + 2 ) .
2 8
Note:
i) As you can see from the above plot, comparison of the expansion with the
exact expression is very good.
ii) We can refine the above analysis to find the error in the above expansion to
be about /256.
1 1 1 1 2 1 4
iii) The actual error E()=| 1 − (1 − + 2 ) -( 1 − + − + ... )| is
2 8 2 8 128
computed for between 0 and 1. Then E()/ is plotted (blue thin line). As
can be seen, this ratio is very close to 1/256~0.0039 for small , indicating
that the analysis for the O() term is also correct.
s = a0 + a1s + a2 s 2 + a3 s 3 + a4 s 4 + ...
+
1
20
(
a0 + a1s + a2 s 2 + a3 s 3 + a4 s 4 + ...
2
)
+
3!
7!
(a0 + a1s + a2 s 2 + a3 s 3 + a4 s 4 + ...)3
+
3!
9!
( )4
a0 + a1s + a2 s 2 + a3 s 3 + a4 s 4 + ... +… (9)
Since the above must hold for arbitrary s, the coefficients of various powers (s0,
s1, s2, s3, s4,…) must balance on both sides.
Since the left hand side only has a linear term, s, it is clear that
a0 = 0. (10)
Now consider the coefficient of s1 on both sides of Eqn. (9). The 2nd , 3rd, and
4th lines will each give O(s2), O(s3) and O(s4) as their leading order term.
Thus, s = a1 s gives
a1 = 1. (11)
Equation (9) can thus be rewritten as
s = s + a2 s 2 + a3 s 3 + a4 s 4 + ...
+
1
20
(
s + a2 s 2 + a3 s 3 + a4 s 4 + ...
2
)
+
3!
7!
(
s + a2 s 2 + a3 s 3 + a4 s 4 + ...)3
+
3!
9!
( )4
s + a2 s 2 + a3 s 3 + a4 s 4 + ... +… (12)
0 = a2 s 2 +
1
( 2
s + a2 s 2 ... +…
20
)
Thus,
a2 = -1/20 (13)
For the balance of s3 in Eqn. (12), we have
1 3!
0 = a3 s 3 + 2a2 s 3 + s 3
20 7!
Hence,
a3 = 1/200 – 3!/7! = 2/525 (14)
For the balance of s4 in Eqn. (12), we note that
Solution:
* Two observations first:
i) We first note that the integration exists for any 0.
ii) We can also perform a numerical integration for 0 to get accurate value.
* Perform Taylor series expansion for 1/(1 + t ) first, then integrate,
we obtain
−t −t
f() = 0 e /(1 + t )dt ~ 0 e [1 − t + ( t ) − ( t ) + ...]dt
2 3
But f() = 1- +22 + O(3) is a valid three term expansion for f() as →0.
It gives a good approximation to f() for small .
1.6
1.4 converging as → 0
1.2
f( )
1
0.8
0.6
0
0 0.1 0.2 0.3 0.4 0.5
−t
Fig. S1.2 N-term asymptotic expansion for f() = 0 e /(1 + t )dt .
Fig. S1.2 shows convergence of the series in the limit of →0 for several terms
in comparison with the numerically integrated result. Clearly, at any given .,
the increase in N leads to poor accuracy.
* Further comments on asymptotic expansion
For a given , an indefinite increase in N will lead quickly to divergence.
Such an expansion is called asymptotic expansion. For an asymptotic
expansion, the magnitude of the error associated with the retention of only n
terms can be made arbitrarily small by taking a parameter x sufficiently near
a certain fixed value x0 (or sufficiently large in magnitude). The error often
first decreases as n increase but eventually increases unboundedly in
magnitude with increasing n, when x is given a fixed value other than x0. In
solving engineering and physical problems, we are often interested only in
the limit of small and we only need to find the first few terms in the
expansion. This type of asymptotic expansion becomes extremely valuable.
0.5
Relative error
0.4
0.3
0.2
0.1
0
1 2 3 4 5 6 7 8 9 N
2 x 2
Solution: erf ( x) = exp(−t )dt (TS expansion for exp()=>)
0
2 x 2 1 4 n1 2n
= [1 − t + 2! t − ... + (−1) n! t + ...]dt
0
2 1 1 5 1
= [ x − x3 + x − ... + (−1) n x 2n +1 + ...] (1)
3 2!5 n!(2n + 1)
From which we can also compute the complimentary error function
2 2
erfc( x) = 1 − erf ( x) = exp(−t )dt (2)
x
Comments:
i) The above expansion converges for ALL x.
ii) One needs a lot of terms for large values of x. Consider x=3 below:
n Term in Eq. (1) Series
1 3 3.3851375013
2 -9 -6.7702750026
3 24.3 20.6493387578
4 -52.07142857 -38.1069764431
5 91.125 64.7165751585
6 -134.2022727 -86.7144735638
7 170.3336538 105.4864728915
8 -189.8003571 -108.6802960158
9 188.4047663 103.9117172377
10 -168.5726856 -86.3021893576
11 137.2663297 68.5862774415
12 -102.5428313 -47.1209171238
13 70.75455359 32.7170471262
14 -45.35548307 -18.4611350853
15 27.14626204 12.1701414600
16 -15.23693417 -5.0228976332
17 8.051334536 4.0620605240
18 -4.01890144 -0.4727841360
19 1.900831762 1.6720748248
20 -0.854219942 0.7081908384
21 0.365647804 1.1207802033
22 -0.149417541 0.9521805625
23 0.058408675 1.0180876948
24 -0.021882991 0.9933953835
25 0.007871178 1.0022770567
26 -0.002722502 0.9992050426
27 0.000906842 1.0002283042
28 -0.000291289 0.9998996202
29 9.03433E-05 1.0000015617
30 -2.70871E-05 0.9999709971
31 7.85971E-06 0.9999798658
32 -2.20941E-06 0.9999773728
33 6.02277E-07 0.9999780524
34 -1.59354E-07 0.9999778726
35 4.09593E-08 0.9999779188
36 -1.02357E-08 0.9999779072
37 2.48882E-09 0.9999779100
38 -5.89245E-10 0.9999779094
39 1.35933E-10 0.9999779095
40 -3.0575E-11 0.9999779095
41 6.70952E-12 0.9999779095
Thus, it takes 39 terms to obtain erf(3) with error <10-10.
If we use the above Taylor series expansion to compute erf(4), we obtain
2 x 2 2
2
erf ( x) = 2
exp(−t )dt = exp(−t ) dt − exp(−t ) dt
0 0 x
2 −t 2
=1 − e dt
x
−1 −1
−t 2
de − t
2
2
Now notice that exp(−t )dt = (−2te ) dt =
x x 2t x 2t
1 e −t 2
− x2
(integration by parts=>) = e − dt =…
2x x 2t
e −t
2
105
R5 = (−2t ) 9 dt
16 x t
105 1 − t 2 105 1 − x 2
|R5| < de = e (since t>x)
16 x 9 x 16 x 9
Comment:
i) the above expansion diverges for any x if we keep adding more terms
ii) The remainder is quite small when x is large which means that the
So if we use (1) for exp(-x) while x is between 0.333 and 0.334, the largest
possible error will be
0.00052+ 0.0005 0.00107
if we do not include the roundoff error in summing the 4 terms.
If we keep 4 decimal places in summing these 4 terms, then the total error
will be
0.00052+ 3*0.00005+ 0.0005 0.00122
Example 10: Improving accuracy by avoiding loss-of-significance error
For =1.0x10-18, A=1, B=1- , the following operations will suffer loss of
accuracy:
i) (1-cos())/2
ii) 3 1+ −1
Give ways to EXACTLY evaluate the above three expression (which should
give exact result when =O(1)) while avoiding loss-of-significance errors
when is very small.
Solution:
Observations:
We note that even if we use double precision, direct calculation on Excel
spread sheet will give (1-cos( ))/ 2= 0 and 3 1 + − 1 = 0 because the
machine cannot distinguish 1 from cos() for =1.0x10-18 so that (1-cos())
will be treated as 0 by the machine, and 3 1 + is treated as 1 since 1 + is
first calculated to be 1.
the ratio sin(/2)/ =1/2 can be calculated without any loss of accuracy.
2
1 − cos( ) sin( / 2)
Thus, = 2 =1/2.
2
x −1
ii) 3 x − 11 / 3 = . For x=1 + , it becomes
2/3 1/ 3
x +x +1
x −1
=
x 2 / 3 + x1 / 3 + 1 (1 + ) 2 / 3 + (1 + )1 / 3 + 1
The above is exact for any values of . When =1.0x10-18, the computer will
treat the numerator exactly and gives a value of 3 for the denominator.
Hence the result is
= 3.3333333 x 10-19.
(1 + ) 2/3
+ (1 + ) 1/ 3
+1
1 1 1 1 1 1 1 1 1 1
= − − − = − * =
2 k =1 k k + 1 2 k =1 k + 1 k + 2 2 2 2 4
Thus
1 k 2 (k + 1) 1
S = 1 + + 1 − 2
4 k =1 k (k + 1)(k + 2) k (k + 1)
5 1
= +2
2
4 k =1 k (k + 1)(k + 2)
Clearly, the last series converges much faster than the original one.
After N applications of the transformation,
N 1 1
S= + N!
k2
k =1
2
k =1 k (k + 1)(k + 2)...(k + N )
Now consider N=5.
5 1
2 = 1.463611111
k =1 k
30 1
5! = 0.1813229391
2
k =1 k (k + 1)(k + 2)...(k + 5)
Hence, S = 1.4636111111+ 0. 1813229391 = 1.6449340502