Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
CS 335 Assignment
(a) (2 marks) Suppose that on a given base-10 flfloating point system of the form considered in class, the number 23 and the next representable flfloating point number larger than 23 are separated by 10−3 . What is the number of digits, t, in this system?
(b) (2 marks) Using what you found above, what is the spacing between 5 and the next larger representable number in the same flfloating point system?
(c) (2 marks) Suppose you are now given the fact that the range for the exponent is given by L = −4 and U = 6 in the system above. What is the largest magnitude negative number that can be represented in this system? Express your answer in terms of the form
±0.d1d2 · · · dt × 10p . (1)
We saw in class that adding two numbers of similar magnitude and opposing sign has the potential to cause large relative errors under flfloating point – this effffect is known as catastrophic cancellation, since cancellation of the leading digits causes a disastrous loss of precision. In some cases, however, this effffect can be avoided by rearranging the arithmetic expression to be computed.
The roots of a quadratic equation, ax2 + bx + c = 0, are given by
x1 = −b + p b 2 − 4ac /(2a), x2 = −b − p b 2 − 4ac /(2a)
when a 6 = 0.
(a) (3 marks) Consider performing arithmetic in a flfloating point number system with β = 10,t = 5, L = −10, U = 10 with truncation. Using the above formulas, you are to simulate by hand (with the aid of a calculator) the computation of the roots of the following quadratic equation
0.2x 2 + 14.2x + 1.67 = 0, (2)
under this flfloating point system. (Obey the usual order of operations.) The true roots of the given quadratic, correct to fifive signifificant digits, are −0.11780 and −70.882. What is the relative error of each of your computed roots, x1 and x2?
(b) (2 marks) A cancellation problem arises when applying the above formulae for any quadratic equation having the property that
|b| ≈ p b 2 − 4ac.
When this property holds, if b > 0 then the quadratic formula for x1 will exhibit cancellation, while if b < 0 then x2 will exhibit cancellation. We will try to circumvent this problem by reformulating our expression. Show that the following formula for x1,
x1 = (2c)/ −b − p b 2 − 4ac ,
is mathematically equivalent to the usual one given at the start of the question (i.e., assuming you are working with real numbers rather than flfloating point numbers.) Hint:
Rationalize the denominator of this expression.
(c) (1 mark) The formula for x2 can be manipulated similarly. Deduce a better algorithm for calculating the roots of a quadratic equation (which avoids cancellation errors), and present it in the form below (i.e., fifilling in the blanks for the x1 and x2 expressions).
Algorithm R.
if b > 0 then
x2 = −b− √ b 2−4ac /2a
x1 =c/ax2
else
x1 =___
x2 =___
end
(d) (2 marks) Redo the calculation of the roots of equation (2) by applying Algorithm R using the same flfloating point number system. Compute the relative error of the computed roots and compare against your results from part (a). What do you observe?
Show that if x, y, z are already flfloating point numbers in some flfloating point system F, the relative error of the flfloating point calculation (x y) z with respect to the true value of (x − y)/z is less than or equal to 2E + E2 (where E is machine epsilon for the FP system F) assuming no overflflow/underflflow errors occurs.
The symbols and here represent flfloating point subtraction and division, respectively. Just like we saw for addition in class, they satisfy a b = fl(a − b) and a b = fl(a/b), for flfloating point inputs a and b.
Consider a fifixed point iteration:
xk+1 = g(xk) (3)
g(x) =sin(x + π/2)/2 (4)