




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Numerical Computing S’09 MATH/CSCI 4800- Homework-
(a) For the integer part, divide repeatedly by 2 and record the remainders.
12 / 2 = 6 + 0 6 / 2 = 3 + 0 3 / 2 = 1 + 1 1 / 2 = 0 + 1.
Therefore, the binary representation of the integer 12 is
(12) 10 = (1100) 2
For the fractional part, multiply by 2 and record the integer part.
We see that the pattern has begun to repeat. Therefore the binary representation of (0.8) 10 is
(0.8) 10 = (1100 1100 1100.. .) 2 = (.1100) 2.
Combining the two results above,
(12.8) 10 = (1100.1100) 2.
(b) Let x = (10.0101101) 2. Then, moving the radix 3 digits to the right,
23 x = (10010.1101) 2 = 24 + 2 + (.1101) 2.
We can rewrite the above relation as
8 x = 18 + z, z = (.1101) 2. (1)
Now, z = (.1100) 2 = (.1101 1101 1101.. .) 2. Moving the radix 4 points to the right,
24 z = (1101.1101 1101 1101.. .) 2 ,
or, 16 z = (1101.1100) 2 = 2^3 + 2^2 + 2^0 + z = 13 + z. Therefore, z =
Substituting into (1) above,
x =
x = 1.[100 1100 1100 1100 1100 1100]1100 1100... × 23.
Since the 24th digit after the radix is 1 and the subsequent digits are not all zeros, rounding up leads to replacing 0 at the 23rd position by 1, and chopping. Therefore,
f l(x) = 1.[100 1100 1100 1100 1100 1101] × 23.
This approximation involves removal of the infinite tail
t =. 1100 × 2 −^23 × 23 =. 1100 × 2 −^20. (1)
We can write the decimal representation of t as follows; the steps are similar to those employed in problem 1(b) above. Let x =. 1100. Then,
24 x = 1100. 1100 16 x = 23 + 2^2 +. 1100 = 12 + x x =
Substitution into (1) yields t = 0. 8 × 2 −^20. (2) The approximation also involves the addition of 2−^23 to the abscissa in the process of rounding up. This addition amounts to a = 2−^23 × 23 = 2−^20. Putting it all together,
f l(x) = x − t + a = x − 0. 8 × 2 −^20 + 2−^20 = x + 0. 2 × 2 −^20
Then, the relative error is
d =
f l(x) − x x
mach
where we recall that mach = 2−^23 for IEEE single precision.
(b) Text: Section 0.3, Page 16, Problem 8. (c) Let x and y be normalized positive floating point numbers on a binary computer with p-bit precision. How small can y − x be if x < 4 < y?
(c) Recall that the digits closest to the machine number z on either side of z are x = z(1 − mach) and y = z(1 + mach), as long as z is in the interior of a block corresponding to a particular value of the exponent. Here, however, z = 4 is at the boundary of the 2^1 and 2^2 blocks. Thus the number immediately to the right of 4 is
y = [1. 00... 01] × 22
where the fractional part of the mantissa has all zeros except in the p − 1 place. Thus we can write y = [1 + 1/ 2 p−^1 ] × 22 = 4 + 4/ 2 p−^1. Similarly the number immediately to the left of 4, lying in the 2^1 block, is
x = [1. 11... 11] × 21
where the fractional part of the mantissa now has all ones. Thus we can write
x =
2 p−^1
1 − 1 / 2 p 1 − 1 / 2 × 21 = 4 − 4 / 2 p.
Then,
y − x = 4 + 4/ 2 p−^1 − [4 − 4 / 2 p] = 4/ 2 p−^1 + 4/ 2 p^ = 8/ 2 p^ + 4/ 2 p^ = 6/ 2 p−^1 = 6mach.
The result could have been obtained more simply by realizing that the separation between numbers is 2^1 × mach in the 2^1 block and 2^2 × mach in the 2^2 block.
(a) We have ax^2 + bx + c = 0 with a = 1, b = 3 and c = − 8 −^14. The conventional way to express the roots is x 1 =
−b +
b^2 − 4 ac 2 a
and x 2 =
−b −
b^2 − 4 ac 2 a
Since b^2 is large compared to 4ac,
b^2 − 4 ac ≈ b and the formula for x 1 is subject to catas- trophic cancellation. We can compute x 2 as above and for x 2 , use the alternate form
x 1 =
c ax 2
Double precision calculation on Matlab gives
s =
b^2 − 4 ac = 3.000 000 000 000 151.
Then, using (1) above,
x 2 =
−b − s 2 a
to 3 digits, and
x 1 = −b + s 2 a
The second occurrence of 5 in the answer above for x 1 is suspect because −b + s has only 3 significant digits, with the third digit influenced by rounding. Using the above value of x 2 in (2) we obtain the more accurate solution
x 1 =
= 7. 579122514774211 × 10 −^14 = 7. 579 × 10 −^14 to 3 digits.
(b) We use Taylor’s theorem with remainder (Theorem 0.8, page 21 in the Text):
f (x) = f (a) + (x − a)f ′(a) +
(x − a)^2 2!
f ′′(a) + · · · +
(x − a)n n!
f (n)(a) +
(x − a)n+ (n + 1)!
f ′(n+1)(c),
where the last term is the remainder after n terms and c lies between x and a. Here, f (x) = cos x and n = 5. Then the above formula becomes
cos x = 1 −
x^2 2!
x^4 4!
Since f (vi)(x) = − cos x, the remainder is
x^6 6! cos c.
For a = 0 and x ∈ [−π/ 4 , π/4], the upper bound on R 5 corresponds to x = π/4 and cos c = 1. Then |R 5 | ≤
(π/4)^6 6!
It is easily seen that for f (x) =
tan x − x x^3 , lim x→ 0 f (x) = 1/ 3.
The attached Matlab output is a printout of x = 10−p^ and f (x) for p = 1, 2 , · · · 10. It shows that as p increases, agreement between computed f (x) and the limiting value increases until p = 4, and then decreases. At p = 8 the computed value of f (x) = 0, indicating that all significant digits are lost.
x 10 −
x
Plots of f(x) (red), g(x) (blue) and zero (green)