Вы находитесь на странице: 1из 4

Numerical Analysis: A Computational Approach

COT4501, Spring 2017


Solutions to Homework 2

Epperson, Section 1.2: 3. Use Taylors Theorem to show that


1
1 + x = 1 + x + O(x2 )
2
for x sufficiently
small.
f (x) = 1 + x, f 0 (x) = 21 (1 + x)1/2 , and f 00 (x) = 41 (1 + x)3/2 . So 1 + x = 1 + 12 x 18 (1 +
)3/2x2 , for some || |x|. Since | 18 (1 + )3/2 x2 | Cx2 for some constant C, we can conclude
that 1 + x = 1 + 12 x + O(x2 ).

7. We are given the fact that


n
X 1
rk = + O(rn+1 ).
k=0
1r

Use the above result to show that 10 terms (k = 9) are all that is needed to compute

ek
X
S=
k=0

to within 104 absolute accuracy.


From the given equation, we have
9
1
ek = + O(e10 ) = ek + O(e10 )
X X
1
k=0
1 e k=0

Since e10 = 4.54 105 104 , the sum of the first 10 terms of this series can approximate the
required summation k within 104 in absolute accuracy.
P
k=0 e

10. Use the definition of O (big O) to show that if y = yh + O(hp ), then hy = hyh + O(hp+1 ).
|hy hyh | |h||y yh | hChp = Chp+1 for some constant C, as h 0. Therefore, hy =
hyh + O(hp+1 ).

12. Suppose that y = yh + O((h)) and z = zh + O((h)), for h sufficiently small. Does it follow
that y z = yh zh (for h sufficiently small)?
No, not exactly. We know that |y yh | C1 (h) and |z zh | C2 (h) for constants C1 and C2 ,
which leads to the fact that C1 (h) y yh C1 (h) and C2 (h) z zh C2 (h). We then

1
have (C1 (h) + C2 (h)) (y z) (yh zh ) C1 (h) + C2 (h), i.e. y z = yh zh + O((h)).
So y z = yh zh is not exactly correct but we can say that y z yh zh .

Epperson, Section 1.3: 3. For each function below, explain why a nave construction will be
susceptible to significant rounding error (for x near certain values), and explain how to avoid this
error.

(a) f (x) = ( x + 9 3)x1 ;
(b) f (x) = x1 (1 cos(x));
(c) f (x) = (1 x)1 (ln(x) sin(x));
(d) f (x) = (cos( + x) cos())x1 ;
(e) f (x) = (e1+x e1x )(2x)1 .
In each case, the function is susceptible to subtractive cancellation which will be amplified by
division by a small number. The way to avoid the problem is to use a Taylor series expansion to
make the subtraction and division both explicit operations.
1 x x2 5x3
(a) f (x) = 6 216 + 3888 279936 + O(x4 )
x x3 x5
(b) f (x) = 2 24 + 720 + O(x7 )
x1 5
(c) f (x) = (1 + ) + 2 + 16 ( 3 2)(x 1)2 ( 15 + 120 )(x 1)4 + O((x 1)3 ) at x = 1
x x3 x5
(d) f (x) = 2 24 + 720 + O(x7 )
x2 x4
(e) f (x) = e(1 + 6 + 120 ) + O(x6 )

10. Using the computer and language of your choice, write a program to estimate the machine
epsilon.
Using MATLAB 2016a on a x86-64 bit PC, we get u = 1.110215458040408 1016 . The code
is given below.
format long
x=1.0e-15;
k=0;
while 1+x > 1,
k = k+1
y = 1+x;
x = x*0.99999;
end
x
The code starts from a small value of x and reduces it by 0.99999 at each step until 1 + x becomes
equal to 1. (We also get u = 1.110221998436000 1016 when x is reduced by 0.999999 at each
step. The runtime is considerably increased.)

Epperson Section 2.2: 3. Write a computer program that uses the forward and central differenc-
ing derivative approximations to approximate the first derivative at x = 1 for each of the following

2
functions, using h1 = 4, 8, 16, 32. Verify that the predicted theoretical accuracy is obtainedin
other words, show that your results are consistent with the analysis in this section.

a) f (x) = x + 1;

h1 D1 (h) |f 0 (1) D1 (h)| D2 (h) |f 0 (1) D2 (h)|


4 0.3431 0.0104 0.3542 0.6953 103
8 0.3482 0.0054 0.3537 0.1729 103
16 0.3508 0.0027 0.353597 0.0432 103
32 0.3522 0.0014 0.353564 0.0108 103

b) f (x) = arctan(x);

h1 D1 (h) |f 0 (1) D1 (h)| D2 (h) |f 0 (1) D2 (h)|


4 0.4426 0.0574 0.5051 0.0051
8 0.4700 0.0300 0.5013 0.0013
16 0.4847 0.0153 0.5003 0.0003
32 0.4923 0.0077 0.5001 0.0001

c) f (x) = sin(x);

h1 D1 (h) |f 0 (1) D1 (h)| D2 (h) |f 0 (1) D2 (h)|


4 2.8284 0.3132 2.8284 0.3132
8 3.0615 0.0801 3.0615 0.0801
16 3.1214 0.0201 3.1214 0.0201
32 3.1365 0.0050 3.1365 0.0050

d) f (x) = exp(x);

h1 D1 (h) |f 0 (1) D1 (h)| D2 (h) |f 0 (1) D2 (h)|


4 0.3255 0.0424 0.3717 0.0038
8 0.3458 0.0221 0.3688 0.0010
16 0.3566 0.0113 0.3681 0.0002
32 0.3622 0.0057 0.3679 0.0001

e) f (x) = ln(x);

h1 D1 (h) |f 0 (1) D1 (h)| D2 (h) |f 0 (1) D2 (h)|


4 0.8926 0.1074 1.0217 0.0217
8 0.9423 0.0577 1.0053 0.0053
16 0.9700 0.0300 1.0013 0.0013
32 0.9847 0.0153 1.0003 0.0003

As the results show above, the errors of D2 approximations decrease faster (or at least no slower
in c) than the D1 approximations, which meets the analysis.

11. Let f (x) = arctan(x). Use the derivative approximation


8f (x + h) 8f (x h) f (x + 2h) + f (x 2h)
f 0 (x) =
12h

3
to approximate f 0 ( 14 ) using h1 = 2, 4, 8, . . .. Try to take h small enough that the rounding error
effect begins to dominate the mathematical error. For what value of h does this begin to occur?
(You may have to restrict yourself to working in single precision.)
In single precision, the results are as follows:

h1 D1 (h) |f 0 (1) D1 (h)|


2 0.630230784416199 0.011744320392609
4 0.619388937950134 0.000902473926544
8 0.618544042110443 0.000057578086853
16 0.618490040302277 0.000003576278687
32 0.618486702442169 0.000000238418579
64 0.618486464023590 0
128 0.618486464023590 0
256 0.618486464023590 0

Due to the lower precision, it is never the case that the rounding error dominates the mathe-
matical error. However, in double precision,

h1 D1 (h) |f 0 (1) D1 (h)|


2 0.630230806549992 0.011744348391155
4 0.619388909738750 0.000902451579913
8 0.618544021662939 0.000057563504103
16 0.618490064342505 0.000003606183669
32 0.618486683636449 0.000000225477613
64 0.618486472252444 0.000000014093607
128 0.618486459039701 0.000000000880865
256 0.618486458213889 0.000000000055053
512 0.618486458162276 0.000000000003439
1024 0.618486458159045 0.000000000000209
2048 0.618486458158941 0.000000000000105
4096 0.618486458159055 0.000000000000218
8192 0.618486458159244 0.000000000000408
16384 0.618486458159471 0.000000000000635
32768 0.618486458158259 0.000000000000578
65536 0.618486458157956 0.000000000000881

It is clear that after h = 2048, the error starts to increase, which means that the rounding error
starts to dominate the mathematical error.

Вам также может понравиться