EGM6341 Sol HW 02

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Ramin Shamshiri

HW#2 EGM6341 Spring 2009


Due 1/27/09
From the textbook by Atkinson: pp.43-50 :
21. For the following numbers x
A
and x
T
, how many significant digits are there in x
A

with respect to x
T
?
a) x
A
= 451.023, x
T
= 451.01
b) x
A
= -0.045113, x
T
= -0.04518
c) x
A
= 23.4213, x
T
= 23.4604

22. Let all of the following numbers be correctly rounded to the number of digits
shown:
a) 1.1062+0.947
b) 23.46-12.753
c) (2.747)(6.83)
d) 8.473/0.064
For each calculation, determine the smallest interval in which the result, using
true instead of rounded values, must be located.

25. Given exact ways of avoiding loss-of-significance errors int eh following
computations
a) log(x+1) log(x) large x
b) sin(x)- sin(y) x ~ y

29. Assume that x
A
=0.937 has three significant digits with respect to x
T
. Bound the
relative error in x
A
. For ( ) 1 f x x = , bound the error and relative error in
( )
A
f x with respect to ( )
T
f x .

30 Estimate the errors in the function values in terms of the errors in the arguments.
Bound the relative errors.
a) Sin[(3.14)(2.685)]

A1: Order of summation problem:
It is known that
90
1
4
4
1
t
=

= k k

Use only the first 8 terms in the summation and 3 significant figures for each number throughout
the calculation to approximate the value of 90 /
4
t .
Carry out the summation in two ways: from k=1 to 8 and from k=8 to 1.
Document your detailed intermediate computational results.
What is the preferred manner for calculating summations of positive numbers with known begin
and end points?

A2 Further studies on the convergence improvement: (20 points)
Background: Consider the series
k
k
a A =

=1
and partial sum
k
n
k
n
a A =
=1
of the sequence
k
a .
Suppose the nth term of the sequence
n
A is in the form of

n
n
q A A o + ~ (1)
with |q|<1, so that A A
n
as n . Here, the term
n
q o is the leading term of the
remainder (or error) in approximating A by
n
A . In practice, Eq. (1) can result from
summation of the Taylor series, successive refinement of numerical
integration/differentiation, successive refinement of grid in solving differential equations.
An example such a situation is
k
k
x) (
1

=

which is the Taylor series expansion of 1/(1+x) for |x|<1. The series converges very
slowly near x=1.
Shanks Transformation:
In order to improve the convergence using limited information, consider

n
n
q A A o + ~ (1)

1
1
~

+
n
n
q A A o (2)

1
1
~
+
+
+
n
n
q A A o (3)
There are three unknowns: A, o , q.
Question 1: eliminate o and q in the above to derive an expression for A in terms of
1 n
A ,
n
A ,
and
1 + n
A . Denote the resulting A as S(A
n
) which is Shanks transformation. This
transformation creates a new sequence S(An) which often converges more rapidly than
the original sequence
n
A . One can apply Shanks transformation again on S(A
n
) to obtain
S
2
(A
n
)= S[S(A
n
)] and then S
3
(A
n
)= S{S[S(A
n
))}, and so on.
Question 2: For
k x x A
k k
k
/ ) 1 ( ) (
1
1
+

=
=
, apply Shanks transformation repeatedly (S(An),
S
2
(An), S
3
(An)) to obtain A(x=1) using 10 terms, i.e. k=1 to 10 in the original series.
n an An S(An) S(S(An)) S(S(S(An)))
1 1 1 ------- ------- -------
2 -0.5 0.5 ------- -------
3 0.333333333 0.833333333 -------
4 -0.25 0.583333333
5 0.2 0.783333333
6 -0.166666667 0.616666667
7 0.142857143 0.75952381
8 -0.125 0.63452381
9 0.111111111 0.745634921
10 -0.1 0.645634921
Compare your approximate results with the exact result of ln2 = 0.693147181
For your information, it takes 1000 terms for |
n
A -ln2| to be less than 0.0005.
22. For the following numbers x
A
and x
T
, how many significant digits are there in x
A

with respect to x
T
?
d) x
A
= 451.023, x
T
= 451.01
e) x
A
=-0.045113, x
T
= -0.04518
f) x
A
= 23.4213, x
T
= 23.4604
Soln. a) | x
A
- x
T
| = |451.023-451.01| = 0.013 m+1=5
m=4.
b) | x
A
- x
T
| = | -0.045113 + 0. 04518 | = 0.000067 m+1=3
m=2.
c) | x
A
- x
T
| = | 23.4213 23.4604 | = 0.0391 m+1=4 m
=3.

22. a) 1.1062+0.947 => [1.10615+0.9465, 1.10625+0.9475]=[2.05265, 2.05375]
b) 23.46-12.753 => [23.455-12.7535, 23.465-12.7525]=[10.7015, 10.7125]
c) (2.747)(6.83) => [(2.7465)(6.825), (2.7475)(6.835)]=[ 18.7448625, 18.7791625]
d) (8.473)/(0.064) => [(8.4725)/(0.0645), (8.4735)/(0.0635)]~[131.3566,
133.4409]

25. Given exact ways of avoiding loss-of-significance errors in the following
computations
a) log(x+1) log(x) large x
b) sin(x)- sin(y) x ~ y
Sol. a) log(x+1) log(x) = log[(x+1)/x] = log(1+1/x)
Experiment on a single precision machine:

x log(y)-log(x) log(1+1/x) 1/x-1/(2x^2)+1/(3x^3)
10 9.53102E-02 9.53102E-02 9.53333300E-02
100 9.95016E-03 9.95032E-03 9.95033330E-03
1000 9.99451E-04 9.99547E-04 9.99500390E-04
10000 1.00136E-04 1.00012E-04 9.99949990E-05
100000 1.04904E-05 1.00135E-05 9.99994970E-06
1000000 9.53674E-07 9.53674E-07 9.99999540E-07
1.00E+07 0.00E+00 1.19209E-07 9.99999940E-08
1.00E+08 0.00E+00 0.00E+00 9.99999990E-09
1.00E+09 0.00E+00 0.00E+00 1.00E-09

Observations: i) log(1+1/x) is better than log(x+1)-log(x)
ii) log(1+1/x) still suffers from inaccuracy for large x because
1+1/x will be treated as 1 once 1/x is less than machine
epsilon.
iii) For large x, Taylor series expansion works very well and
does not
suffer from the roundoff error.
b) sin(x)- sin(y) = 2 cos(
2
y x +
) sin(
2
y x
)
Experiment on a single precision using y=t/4, x=t/4+c,

c=x-y sin(y+c)-sin(y) 2*cos(y+ c/2)sin(c/2)
0.1 6.7060351E-02 6.7060299E-02
1.0E-02 7.0356131E-03 7.0355949E-03
1.0E-03 7.0679188E-04 7.0675317E-04
1.0E-04 7.0750713E-05 7.0707138E-05
1.0E-05 7.0929527E-06 7.0710325E-06
1.0E-06 7.1525574E-07 7.0710644E-07
1.0E-07 1.1920929E-07 7.0710669E-08
1.0E-08 0.0000000E+00 7.0710677E-09
1.0E-09 0.0000000E+00 7.0710676E-10
1.0E-10 0.0000000E+00 7.0710680E-11
1.0E-11 0.0000000E+00 7.0710677E-12
1.0E-12 0.0000000E+00 7.0710679E-13
1.0E-13 0.0000000E+00 7.0710683E-14
1.0E-14 0.0000000E+00 7.0710675E-15
1.0E-15 0.0000000E+00 7.0710676E-16
1.0E-16 0.0000000E+00 7.0710674E-17

Comments: - sin(x)- sin(y) suffers from loss of accuracy when |x-y| reaches
10
-6
.
- 2 cos(
2
y x +
) sin(
2
y x
) remains accurate as long as |x-y| is
larger than
x
L
before the underflow occurs.

29. Assume that x
A
=0.937 has three significant digits with respect to x
T
. Bound the
relative error in x
A
. For ( ) 1 f x x = , bound the error and relative error in
( )
A
f x with respect to ( )
T
f x .

Sol. x
A
has three significant digits
4
5 10
T A
x x c

= <
( )
2 1
Error x c c < < , where
4 4
1 2
5 10 , 5 10 c c

= =
( ) Rel
T A
A
T T A
x x
x
x x x
c c
c

= = =
+

( )
2 1
2 1
<Rel
A
A A
x
x x
c c
c c
<
+ +

( )
4 4
5.3390 10 <Rel 5.3333 10
A
x

<

( ) 1 f x x =
( ) ( ) ( ) ( ) ( )( ) Error
A T A T T A
f x f x f x f x x x ' = = Eq. (1.4.19)
( )
( )
1 1
2 2 1
f x
f x x

' = =


( ) ( ) ( )( )
( ) ( )
( )
Error
2 2
2 1
A T T A
T A
A
f x f x x x
f x f x
x
c c c
c
c

' = = = =
+
+

( )
( ) ( )
( )
1 2
1 2
< Error
2 1 2 1
A
A A
f x
x x
c c
c c

<
+ +

( ) ( )
3 4
-1 10 < Error 9.9209 10
A
f x

<

( ) ( )
( ) ( )
( )
( )
| | ( )
2
Error
Rel
2 1 2 1
2
A
A
T T A
T
f x
f x
f x x x
f x
c c c
c

= = = =
( +
(



( )
( ) ( )
( )
1 2
1 2
<Rel
2 1 2 1
A
A A
f x
x x
c c
c c

<
( ( + +


( ) ( )
3 3
-4 10 <Rel 3.9370 10
A
f x

<


30. Estimate the errors in the function values in terms of the errors in the arguments.
Bound the relative errors. Sin[(3.14)(2.685)]

Sol. 3.14, 2.685
A A
x y = =
T A
x x c = + ,
T A
y y q = +

( ) ( ) ( ) ( ) ( ) ( ) , , , ,
T T A A T A x T T T A y T T
f x y f x y x x f x y y y f x y + Eq.
(1.4.20)
( ) ( ) , cos
x
f
f x y y xy
x
c
= =
c
, ( ) ( ) , cos
y
f
f x y x xy
y
c
= =
c

( ) ( ) ( ) ( ) ( ) ( ) Error sin sin sin cos
A A T T A A T T T T
x y x y x y y x x y c q = = +
( ) ( ) cos cos 1.4645 1.7127
A A A A A A
y x y x x y c q c q ~ + =

| | ( )
( ) ( )
( )
( ) ( )
( )
( ) ( )
Error sin cos
Rel sin cot
sin sin
A A T T T T
A A A A A A
T T T T
x y y x x y
x y y x x y
x y x y
c q
c q
+
= = ~ +


( )( )
( )
3
Rel sin 3.14 2.685 9.7583 10

( <


A1. Order of summation problem:
It is known that
90
1
4
4
1
t
=

= k k

Use only the first 8 terms in the summation and 3 significant figures for each number throughout
the calculation to approximate the value of 90 /
4
t .
Carry out the summation in two ways: from k=1 to 8 and from k=8 to 1.
Document your detailed intermediate computational results.
What is the preferred manner for calculating summations of positive numbers with
known begin and end points?

Soln: Since only 3 significant digits are used, the first 8 terms are:
a
k
: 1 0.0625 0.0123 0.00391 0.00160 0.000772 0.000416 0.000244
If we add from large to small, the sum of the first two terms gives:
1 + 0.0625 = 1.0625 need to round to 3 significant digits as 1.06
Now, 1.06 + 0.0123 = 1.0723 round to 1.07
1.07 + 0.00391 = 1.07391 round to 1.07 again
We see that the terms a
k
are less than .005. If we continue the summation process, 1.07
will remain the same. Thus, the result converges to 1.07 with 3 significant digits

If we add from small to large a
8
+ a
7
= 0.000244 + 0.000416 = 0.000660
0.000660 does not need rounding.
0.000660 + 0.000772 = 0.001432 round to 0.00143
0.00143 + 0.00160 = 0.00303 no rounding required
0.00303 + 0.00391 = 0.00694 no rounding required
0.00694 + 0.0123 = 0.01924 round to 0.0192
0.0192 + 0.0625 = 0.0817 no rounding required
1 + 0.0817 = 1.0817 round to 1.08

Note: =
90
4
t
1.082323
Now we compare the two results.
i) adding from small to large and adding from large to small indeed produced two
different results.
ii) comparing with the exact result, adding from small to large gives a more
accurate result.



A2. Further studies on the convergence improvement: (40 points)
Background: Consider the series
k
k
a A =

=1
and partial sum
k
n
k
n
a A =
=1
of the
sequence
k
a . Suppose the nth term of the sequence
n
A is in the form of

n
n
q A A o + ~
(1)
with |q|<1, so that A A
n
as n . Here, the term
n
q o is the leading term of the
remainder (or error) in approximating A by
n
A . In practice, Eq. (1) can result from
summation of the Taylor series, successive refinement of numerical
integration/differentiation, successive refinement of grid in solving differential equations.
An example such a situation is
k
k
x) (
1

=

which is the Taylor series expansion of 1/(1+x) for |x|<1. The series converges very
slowly near x=1.
Shanks Transformation:
In order to improve the convergence using limited information, consider

n
n
q A A o + ~
(1)

1
1
~

+
n
n
q A A o
(2)

1
1
~
+
+
+
n
n
q A A o
(3)
There are three unknowns: A, o , q.
Question 1: eliminate o and q in the above to derive an expression for A in terms of
1 n
A ,
n
A , and
1 + n
A . Denote the resulting A as S(A
n
) which is Shanks transformation.
This transformation creates a new sequence S(A
n
) which often converges more rapidly
than the original sequence
n
A . One can apply Shanks transformation again on S(A
n
) to
obtain S
2
(A
n
)= S[S(A
n
)] and then S
3
(A
n
)= S{S[S(A
n
))}, and so on.
Question 2: For k x x A
k k
k
/ ) 1 ( ) (
1
1
+

=
= , apply Shanks transformation repeatedly
(S(An), S
2
(An), S
3
(An)) to obtain A(x=1) using 10 terms, i.e. k=1 to 10 in the original
series.
n an An S(An) S(S(An)) S(S(S(An)))
1 1 1 ----- ----- -----
2 -0.5 0.5 0.7 ----- -----
3 0.333333333 0.833333333 0.69047619 0.693277311 -----
4 -0.25 0.583333333 0.694444444 0.693105756 0.693148869
5 0.2 0.783333333 0.692424242 0.693163341 0.693146682
6 -0.166666667 0.616666667 0.693589744 0.693139901 0.693147354
7 0.142857143 0.75952381 0.692857143 0.693150829 0.693147112
8 -0.125 0.63452381 0.693347339 0.693145196
9 0.111111111 0.745634921 0.693003342
10 -0.1 0.645634921
Compare your approximate results with the exact result of ln2=0.693147181
For your information, it takes 1000 terms for |
n
A -ln2| to be less than 0.0005.

Solution: ( to Question 1: )
Given

n
n
q A A o + ~
(1)

1
1
~

+
n
n
q A A o
(2)

1
1
~
+
+
+
n
n
q A A o
(3)
[(2)-(1)] ) 1 ( ~
1
1

q q A A
n
n n
o
(4)
[(1)-(3)] ) 1 ( ~
1
q q A A
n
n n

+
o
(5)
(4) / (5)
1
1
1
1
1
1
~


q
q
q
A A
A A
r
n n
n n
(Eqn. for q)
(6)
(3)-(1) ) 1 )( ( ) 1 ( ~
1
=
+
q A A q q A A
n
n
n n
o
=
r
r
A A
n

1
) (
(7)
From (7) we can solve for A as

1
~
1

+
r
A rA
A
n n

(8)
Substituting (6) into (8), we obtain

n n n
n n n
A A A
A A A
A
2
~
1 1
2
1 1
+

+
+

(9)
Comments:
- Equation (9) is known as Shanks transformation. Equations (8) and (6) are
perhaps better known as Richardson extrapolation.
- One can repeatedly apply the above transformation/extrapolation to accelerate the
convergence toward A.
- On page 85 of the book, the Aitkens extrapolation formula for root finding can
be easily shown to be the Shanks transformation (9).
- After repeated application of the Shanks transformation in the form of Equation (9)
suffers the loss of accuracy when A is reached. Usually, it is not a problem since
the result is already very good by the time the roundoff error becomes an issue of
concern. In some cases, the repeated application of Richardson extrapolation
(especially when (r-1)~ O(1)) does not suffer from the loss of accuracy as you can
see from Eq. (8).

Solution to Question 2: The numerical results are shown in the original table above.
Comments:
- You can see the rapid acceleration of the series with 3 applications of Shanks
transformation although only 10 terms in the original sequence are used.
- You can plot S(A)-ln(2) as a function of n to see the rate of convergence; then you
can compare the convergence of S(S(A))-ln(2) and S(S(S(A)))-ln(2).
- Shanks transformation also works when dealing with non-convergent series. For
example, consider 1/(1+z)=1-z+z
2
-z
3
+z
4
+ It does not converge when z=1
although the LHS is equal to . You can obtain the correct result by just using
one Shanks transformation.

You might also like