egm6341_sol_hw_02

9

Click here to load reader

Upload: raminshamshiri

Post on 16-Apr-2015

95 views

Category:

Documents


4 download

DESCRIPTION

EGM6341_Sol_HW_02

TRANSCRIPT

Page 1: EGM6341_Sol_HW_02

Ramin Shamshiri

HW#2 EGM6341 Spring 2009

Due 1/27/09

From the textbook by Atkinson: pp.43-50 :

21. For the following numbers xA and xT, how many significant digits are there in xA

with respect to xT?

a) xA = 451.023, xT = 451.01

b) xA = -0.045113, xT = -0.04518

c) xA = 23.4213, xT = 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 xA=0.937 has three significant digits with respect to xT. Bound the

relative error in xA. For 1f x x , bound the error and relative error in

Af x with respect to Tf 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

41

kk

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 .

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)

Page 2: EGM6341_Sol_HW_02

Background: Consider the series k

k

aA

1

and partial sum k

n

kn aA

1

of the sequence ka .

Suppose the nth term of the sequence nA is in the form of

n

n qAA ~ (1)

with |q|<1, so that AAn as n . Here, the term nq is the leading term of the

remainder (or error) in approximating A by nA . 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 qAA ~ (1)

1

1 ~ n

n qAA (2)

1

1 ~ n

n qAA (3)

There are three unknowns: A, , q.

Question 1: eliminate and q in the above to derive an expression for A in terms of 1nA , nA ,

and 1nA . Denote the resulting A as S(An) which is Shanks transformation. This

transformation creates a new sequence S(An) which often converges more rapidly than

the original sequence nA . One can apply Shanks transformation again on S(An) to obtain

S2(An)= S[S(An)] and then S

3(An)= S{S[S(An))}, and so on.

Question 2: For kxxA kk

k

/)1()( 1

1

, apply Shanks transformation repeatedly (S(An),

S2(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 | nA -ln2| to be less than 0.0005.

Page 3: EGM6341_Sol_HW_02

22. For the following numbers xA and xT, how many significant digits are there in xA

with respect to xT?

d) xA = 451.023, xT = 451.01

e) xA =-0.045113, xT = -0.04518

f) xA = 23.4213, xT = 23.4604

Soln. a) | xA - xT | = |451.023-451.01| = 0.013 m+1=5

m=4.

b) | xA - xT | = | -0.045113 + 0. 04518 | = 0.000067 m+1=3

m=2.

c) | xA - xT | = | 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

yx ) sin(

2

yx )

Experiment on a single precision using y=/4, x=/4+,

Page 4: EGM6341_Sol_HW_02

=x-y sin(y+)-sin(y) 2*cos(y+/2)sin(/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

yx ) sin(

2

yx ) remains accurate as long as |x-y| is

larger than

xL before the underflow occurs.

29. Assume that xA=0.937 has three significant digits with respect to xT. Bound the

relative error in xA. For 1f x x , bound the error and relative error in

Af x with respect to Tf x .

Sol. xA has three significant digits 45 10T Ax x

2 1Error x , where 4 4

1 25 10 , 5 10

Rel T AA

T T A

x xx

x x x

2 1

2 1

<Rel A

A A

xx x

4 45.3390 10 <Rel 5.3333 10Ax

1f x x

Error A T A T T Af x f x f x f x x x Eq. (1.4.19)

1 1

22 1f x

f xx

Page 5: EGM6341_Sol_HW_02

Error2 2 2 1

A T T A

T A A

f x f x x xf x f x x

1 2

1 2

< Error2 1 2 1

A

A A

f xx x

3 4-1 10 < Error 9.9209 10Af x

2

ErrorRel

2 1 2 12

A

A

T T AT

f xf x

f x x xf x

1 2

1 2

<Rel2 1 2 1

A

A A

f xx x

3 3-4 10 <Rel 3.9370 10Af 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.685A Ax y

T Ax x , T Ay y

, , , ,T T A A T A x T T T A y T Tf x y f x y x x f x y y y f x y Eq.

(1.4.20)

, cosx

ff x y y xy

x

, , cosy

ff x y x xy

y

Error sin sin sin cosA A T T A A T T T Tx y x y x y y x x y

cos cos 1.4645 1.7127A A A A A Ay x y x x y

Error sin cosRel 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 yx y y x x y

x y x y

3Rel sin 3.14 2.685 9.7583 10

Page 6: EGM6341_Sol_HW_02

A1. Order of summation problem:

It is known that 90

1 4

41

kk

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 .

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: ak: 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 ak 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 a8 + a7 = 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

41.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 kk

aA

1

and partial sum k

n

kn aA

1

of the

sequence ka . Suppose the nth term of the sequence nA is in the form of

Page 7: EGM6341_Sol_HW_02

n

n qAA ~

(1)

with |q|<1, so that AAn as n . Here, the term nq is the leading term of the

remainder (or error) in approximating A by nA . 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 qAA ~

(1)

1

1 ~ n

n qAA

(2)

1

1 ~ n

n qAA

(3)

There are three unknowns: A, , q.

Question 1: eliminate and q in the above to derive an expression for A in terms of

1nA , nA , and 1nA . Denote the resulting A as S(An) which is Shanks transformation.

This transformation creates a new sequence S(An) which often converges more rapidly

than the original sequence nA . One can apply Shanks transformation again on S(An) to

obtain S2(An)= S[S(An)] and then S

3(An)= S{S[S(An))}, and so on.

Question 2: For kxxA kk

k

/)1()( 1

1

, apply Shanks transformation repeatedly

(S(An), S2(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…

Page 8: EGM6341_Sol_HW_02

For your information, it takes 1000 terms for | nA -ln2| to be less than 0.0005.

Solution: ( to Question 1: )

Given

n

n qAA ~

(1)

1

1 ~ n

n qAA

(2)

1

1 ~ n

n qAA

(3)

[(2)-(1)] )1(~ 11 qqAA n

nn

(4)

[(1)-(3)] )1(~1 qqAA nnn

(5)

(4) / (5) 1

1

1

1

1

1~

q

q

q

AA

AAr

nn

nn (Eqn. for q)

(6)

(3)-(1) )1)(()1(~1 qAAqqAA nn

nn

=r

rAAn

1)(

(7)

From (7) we can solve for A as

1

~ 1

r

ArAA nn

(8)

Substituting (6) into (8), we obtain

nnn

nnn

AAA

AAAA

2~

11

211

(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 Aitken’s 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

Page 9: EGM6341_Sol_HW_02

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+z2-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.