Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Quiz #1 CSC2800 (Spring Term 2007) Full score: 10 % + 1% bonus Name:_______________________________ (Student ID: ________________________) Problem 1: A fictional machine represents non-zero floating point numbers in the following way: 0.a1a2 a3a4 10 e a1 0, 0 a1 , a2 , a3 , a 4 10 , and 5 e 5 That is, the mantissa can only support 4 decimal digits. In addition, numbers that cannot be represented exactly are rounded to the nearest representation. [This is the same fictional machine you encountered in your assignment #1] (a) What is the largest representable positive number on this machine? Answer: 0.9999 10 [1%] 5 (b) What is the smallest representable positive number on this machine? [1%] Answer: 0.1000 10 4 (c) Suppose x and y are two representable non-zero numbers of this machine. Find an example such that x / y (x divide by y) overflow. [1%] Answer: x 0.9999 10 5 , y 0.1 (or any number less than 1) 0.9999 10 5 / 0.1 0.9999 10 6 ( the largest representa ble number, and thus results in overflow) (c) Give an example to show that adding two numbers can result in underflow on this machine. [1%] Answer: Let x 0.1001 10 5 , y 0.1000 10 5 Then x y 0.0001 10 5 ( the smallest representa ble positive number, and thus results in underflow) Problem 2: Suppose in computing x2 + y, we begin with x and y with some errors. Let εx and εy be the errors introduced to x and y respectively. That is, xA = x + εx and yA = y + εy. Assuming there is no rounding error introduced during calculation, what is the total errors introduced to the final result? [2%] Answer: Total error ( x 2 y ) ( x A2 y A ) ( x 2 y ) (( x x ) 2 y y ) x 2 y x 2 2 x x x2 y y 2 x x x2 y Problem 3: Given f(x) = x4 + 2x3 + 2x + 5 (a) How can we compute f(x) efficiently and at the same time minimize the effect of rounding errors. [1%] Answer: Evaluate f(x) as ((x + 2)x2 + 2)x + 5 (b) What is the minimum number of terms in the Taylor expansion of f(x) at 1000 is needed to represent f(x) with no truncation errors? [1%] Answer: 5 terms. Problem 4: Given f(x) = ex – 1. (a) What values of x could lead to large error in the calculated result due to subtractive cancellation? [1%] Answer: When x is close to 0 (which makes ex is close to 1). (b) How should we compute f(x) for the values of x you specified in part (a)? Note: The Taylor series of ex at 0 is 1 x [1%] x2 x3 xn ... ... 2! 3! n! Answer: x 2 x3 xn x2 For x 0, calculate f ( x) as f ( x) e 1 (1 x ... ...) 1 x 2! 3! n! 2! 2 3 x x ( x ... y 1 1 e 2! 3! For x 0, set y x and calculate f ( x) as f ( y ) y 1 y e e ey x x3 xn ... ... 3! n! xn ...) n! Bonus: Prove or explain why your answer for 3(b) is indeed the minimum number of terms needed. [1%] Answer: f ( n 1) (c) The truncation error of the Taylor series of f(x) after including the first n+1 terms is ( x 1000)n 1 for (n 1)! ( 4) ( n) some c between 1000 and x. Since f ( x) 24 0 and f ( x) 0 for n ≥ 5, the smallest n that results in zero truncation error is 5.