Docsity

Homework 2 Solution Manual - Numerical Analysis - 2007 | MATH 575A, Assignments of Mathematical Methods for Numerical Analysis and Optimization

Toggle sidebar
bg1
MATH 575A, HW 2 9/4/2007
Solution Provided by Wolfgang Balzer and J Restrepo
Problem 1.)
For some of the operations, I incorporated the rules for adding and subtracting binary numbers,
in particular I needed 1 + 1 = 10 (carry 1) and 0 −1 = 1 (with borrow)
a)
x=3
5= (0.100110011001100110011001 . . .)2
x−= (1.001 ...01)2·2−1
x+= (1.001 ...10)2·2−1
(x−x−) = (1.001 ...011001 ...)2·2−1
−(1.001 ...01)2·2−1= (1.001 ...)2·2−24 =3
5·2−24
(x+−x) = (x+−x−)−(x−x−)
= (1.001 ...10)2·2−1
−(1.001 ...01)2·2−1−3
5·2−24
= (0.000 ...01)2·2−1−3
5·2−24 = 1 ·2−24 −3
5·2−24 =2
5·2−24
hence, the closest machine number is x+= (1.001 ...10)2·2−1. Absolute and relative error are
|x+−x|=2
5·2−24
|x+−x|
|x|=2
3·2−24
b)
x=2
7= (0.010010010010010010010010 . . .)2
x−= (1.00100 ...10)2·2−2
x+= (1.00100 ...11)2·2−2
(x−x−) = (1.00100 ...100100 ...)2·2−2
−(1.00100 ...10)2·2−2= (1.001 ...)2·2−25 =2
7·2−25
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Homework 2 Solution Manual - Numerical Analysis - 2007 | MATH 575A and more Assignments Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

MATH 575A, HW 2 9/4/

Solution Provided by Wolfgang Balzer and J Restrepo

Problem 1.)

For some of the operations, I incorporated the rules for adding and subtracting binary numbers, in particular I needed 1 + 1 = 10 (carry 1) and 0 − 1 = 1 (with borrow)

a)

x =

x− = (1. 001... 01) 2 · 2 −^1 x+ = (1. 001... 10) 2 · 2 −^1

(x − x−) = (1. 001... 011001.. .) 2 · 2 −^1

− (1. 001... 01) 2 · 2 −^1 = (1. 001.. .) 2 · 2 −^24 =

· 2 −^24

(x+ − x) = (x+ − x−) − (x − x−) = (1. 001... 10) 2 · 2 −^1

− (1. 001... 01) 2 · 2 −^1 −

· 2 −^24

= (0. 000... 01) 2 · 2 −^1 −

· 2 −^24 = 1 · 2 −^24 −

· 2 −^24 =

· 2 −^24

hence, the closest machine number is x+ = (1. 001... 10) 2 · 2 −^1. Absolute and relative error are

|x+ − x| =

· 2 −^24

|x+ − x| |x|

· 2 −^24

b)

x =

x− = (1. 00100... 10) 2 · 2 −^2 x+ = (1. 00100... 11) 2 · 2 −^2

(x − x−) = (1. 00100... 100100.. .) 2 · 2 −^2

− (1. 00100... 10) 2 · 2 −^2 = (1. 001.. .) 2 · 2 −^25 =

· 2 −^25

(x+ − x) = (x+ − x−) − (x − x−) = (1. 00100... 11) 2 · 2 −^2

− (1. 00100... 10) 2 · 2 −^2 −

· 2 −^25

= (0. 000... 01) 2 · 2 −^2 −

· 2 −^25 = 1 · 2 −^25 −

· 2 −^25 =

· 2 −^25

hence, the closest machine number is x− = (1. 00100... 10) 2 · 2 −^2. Absolute and relative error are

|x− − x| =

· 2 −^25

|x− − x| |x|

= 1 · 2 −^25

c)

x = 23 + 2−^19 + 2−^22 = (100. 000000000000000000000000.. .) 2

  • (0. 000000000000000000100000.. .) 2
  • (0. 000000000000000000000100.. .) 2 = (1. 000000000000000000001001.. .) 2 · 22 x− = (1. 00... 100) 2 · 22 x+ = (1. 00... 101) 2 · 22

(x − x−) = (1. 00... 1001000.. .) 2 · 22 − (1. 00... 100) 2 · 22 = 1 · 2 −^22 (x+ − x) = (x+ − x−) − (x − x−) = (1. 00... 101) 2 · 22 − (1. 00... 100) 2 · 22 − 1 · 2 −^22

= 1 · 2 −^21 − 1 · 2 −^22 =

· 2 −^21

hence, the closest machine number is x− = (1. 00... 100) 2 · 22. Absolute and relative error are

|x− − x| = 1 · 2 −^22 |x− − x| |x|

1 · 2 −^22

23 + 2−^19 + 2−^22

≈ 1 · 2 −^25

The absolute error is not surprising because the bits for 2^3 and 2−^22 are ’too far apart’ in the IEEE SP representation, so that the bit associated with 2−^22 can actually not be presented on the machine. However, the relative error is still small.

[ 1 2 ,^1

] = [2−^1 , 20 ]:

β = 2, t = 24, U = 0, L = − 1 → N = 2^24 = 16777216

• [2−^126 , 2 −^125 ]:

β = 2, t = 24, U = − 125 , L = − 126 → N = 2^24 = 16777216

The same number of machine numbers (≈ 0 .4% of all IEEE SP numbers) is included in both intervals indicating that the binary numbers are clustered towards zero as mentioned in class.

Note also the following: take (a). On the Marc-

x = ±(0. 1 a 2 a 3 ...a 2 4) 22 ±m.

there are 2 for ±, 2 for each ai and 8 choices for m. We also add 1 for the zero. Thus,

2 · 223 (2^8 − 1) + 1 = 2^32 − 22 4 + 1

different numbers. The other cases can be done similarly.

Problem 4.)

Results obtained with MatLab for f (x) = 1 − cos(x) and g(x) = 2sin^2 (x/2) at x-locations x = 9−^1 , 9 −^2... 9 −^10 are presented in figure 1 in form of a double logarithmic plot. For x = 9−^9 and x = 9−^10 MatLab gives the result f (x) = 0 whereas g (x = 9−^9 ) = 3. 331231652687833 e − 18 and g (x = 9−^10 ) = 4. 112631669984980 e − 20 are non-zero. The reason for that is the behavior of the sine and cosine functions near zero. The cosine is very shallow near x = 0 where the derivative approaches zero. Location x = 9−^8 where the function f (x) = 2. 220446049250313 e − 16 = eps is actually the smallest x 6 = 0 for which the machine can distinguish between f (x) = 0 and f (x) 6 = 0. The sine function is steep near x = 0 with the derivative being 1 so that even very small deviations from 0 yield a nonzero (on the machine representable) number.

10 − 10 − 10 − 10 − 10 − 10

(^100) −

10 −

10 −

10 −

100

x

f(x),g(x)

f(x)=1−cos(x) g(x)=2sin(x/2)sin(x/2)

Figure 1: Results obtained with MatLab for x = 9−^1 , 9 −^2... 9 −^10 and f (x) = 1 − cos(x), g(x) = 2 sin^2 (x/2)

However, using the better algorithm g(x) comes at a computational price: Repeating the cal- culation of f (x) and g(x) for the 10 x-locations 10^5 times and reporting the cputime yielded tf (x) = 1. 762 s and tg(x) = 1. 898 s (averaged over 10 runs). More internal operations are neces- sary for the evaluation of g(x) rather than f (x) explaining the 7.16% increase in computational time.

Also note that: y = 1 − cos(1/4) ≈ 0 .0311 which may indicate problem with loss of significance. The way to know if this is the case is to compute the condition number. Indeed, it shows that loss of significance is definitely a possibility on a finite precision machine. On the other hand

Problem 5.)

I 0 =

∫ (^1)

0

t^0 t + 5

dt =

∫ (^1)

0

t + 5

dt = ln(t + 5)

∣∣ ∣

1 0 = ln(6) − ln(5) = ln

Ik =

∫ (^1)

0

tk t + 5

dt =

∫ (^1)

0

tk−^1 · t t + 5

dt

making the substitution u = t + 5 with du = dt leads to

Ik =

∫ (^6)

5

(u − 5)k−^1 · (u − 5) u

du

∫ (^6)

5

[ (u − 5)k−^1 − 5

(u − 5)k−^1 u

] du

∫ (^1)

0

tk−^1 dt − 5

∫ (^1)

0

tk−^1 t + 5

dt

k

tk

∣∣ ∣

1 0 −^5 ·^ Ik−^1

=

k

− 5 · Ik− 1

3.) No, I 0 = ln^65 is not a machine number. An indication for this is that I 0 is representable by an infinte series for ln(1 + x) (where x = 15 ) of the form:

ln x = x −

x^2 2

x^3 3

x^4 4

+... + (−1)n+^

xn n

Calling dec 2 bin in MatLab for I 0 = log(6/5) yielded 1011101010110010100000001000111100100100101100111010 - supporting this answer.

In order to derive a condition number of In about I 0 we first need to express In in terms of I 0 :

I 1 = 1 − 5 I 0

I 2 =

− 5 (1 − 5 I 0 ) =

− 5 + 25I 0

I 3 =

( 1 2

− 5 + 25I 0

)

+ 25 − 125 I 0

In =

(−5)^0

n

(−5)^1

n − 1

(−5)^2

n − 2

(−5)^3

n − 3

(−5)n−^1 1

  • (−5)nI 0 = r(n) + (−5)nI 0

With the derivative dI dIn 0 = (−5)n^ we can find the condition number to be

Cond(In; I 0 ) =

∣∣ ∣∣ ∣∣

I 0 · dI dIn 0 In

∣∣ ∣∣ ∣∣

∣∣ ∣∣ ∣

(−5)nI 0 r(n) + (−5)nI 0

∣∣ ∣∣ ∣

where r(n) is the series as before:

r(n) =

(−5)^0

n

(−5)^1

n − 1

(−5)^2

n − 2

(−5)^3

n − 3

(−5)n−^1 1

4.) Calculating and plotting the condition number using MatLab for n = 1, 2 ,... , 10 (see fig- ure 2) suggests that the recurrence approximate solution is ill-conditioned. The linear behavior in the logarithmic plot tells us that the condition number actually grows exponentially.

1 2 3 4 5 6 7 8 9 10

101

102

10 3

104

105

10 6

10 7

108

109

n

cond(In;I0)

n Cond(In;I0) 1 1.0313e+ 2 7.8534e+ 3 5.2830e+ 4 3.3216e+ 5 2.0014e+ 6 1.1711e+ 7 6.7085e+ 8 3.7808e+ 9 2.1038e+ 10 1.1586e+

Figure 2: Condition number of In(I 0 ) in the interval [1, 10]

Problem 6.)

The derivative of the function f (x) = x − (x^2 − 1)^1 /^2 is

f ′(x) = 1 −

x (x^2 − 1)^1 /^2

The condition number of the function can then be found to

Cond(f ; x) =

∣∣ ∣∣ ∣

xf ′(x) f (x)

∣∣ ∣∣ ∣ =

∣∣ ∣∣ ∣∣ ∣∣

x ·

( 1 − (^) (x (^2) −x1) 1 / 2

)

x − (x^2 − 1)^1 /^2

∣∣ ∣∣ ∣∣ ∣∣

∣∣ ∣∣ ∣∣

x · (x^2 − 1)^1 /^2 − x^2 x · (x^2 − 1)^1 /^2 − x^2 + 1

∣∣ ∣∣ ∣∣

(2)

Using MatLab the condition number Cond(f ; x) was first computed and plotted for an interval [1. 01 , 100] using a step size ∆x = 0.01 (see figure 3). The results suggested ill-conditioning for numbers very close to x = 1 and well-conditioning for all other numbers, in particular as x → ∞. Figure 4 shows a zoom into the region very close to x = 1 for the interval [1 + 2−^20 , 1 + 2−^10 ] confirming the tendancy for ill-conditioning as x → 1.

10 20 30 40 50 60 70 80 90 100

1

2

3

4

5

6

7

8

x

Cond(f;x)

Figure 3: Condition number of f (x) = x − (x^2 − 1) 1 / 2 in the interval [1. 01 , 100]

10

10

10

10

(^10) 0. 1

10 2

10 3

x

Cond(f;x)

Figure 4: Condition number of f (x) = x − (x^2 − 1) 1 / 2 in the interval [1 + 2−^20 , 1 + 2−^10 ]