<<

ECE3040 Assignment #7 [ii,iii]* 1. Find the decimal representation of the following binary . Show detailed work. a. 10011001; b. 1101.1010 2. Find the binary representation of the following numbers. a. 132 b. 39.34 3. Find the IEEE-754 double precision floating point binary representation. Give sign bit, normalized and biased exponent. a. 132 b. 39.34 . -0.821 d. 1/7 4. Determine Matlab’s output for the following calculations: a. eps*realmin b. 1000+realmax c. 2*realmax 푀 휀 3 3휀 5. Show that 퐸(ℎ) = ℎ2 + has its minimum at √ . 6 ℎ 푀 6. Can you explain how a smaller than realmin can still be represented using 64-bit floating point representation? 7. Convert the centered difference-based derivative script to a function that accepts the function to be differentiated (f), the point to evaluate the derivative at (x0), and step size (h) as inputs. The function should simply return the derivative value. If the step size is not included as input, the function should use 10-6 as default step size. Use your function to evaluate the derivative of 푥푐표푠(푥), at x = . Try h = 1, 0.1, 0.0001 and 10-6. 8. Modify your function from Problem 7 to implement the forward difference-based 푓(푥 )−푓(푥 ) 푓′(푥 ) = 𝑖+1 𝑖 differentiation, 𝑖 ℎ . Compare your results to those generated by the centered difference method in Problem 7. 9. Write a user-defined function that converts integers written in binary form to decimal form. The input is a row vector of 1s and 0s. The output is the decimal value. Test your function for the following inputs: a. 10011001 b. 1010101010 c. 11100011111100 10. The machine epsilon  can also be thought of as the smallest number that when added to one gives a number greater than 1. An algorithm based on this idea can be developed as

Step 1: Set  = 1 Step 2: If 1 +  ≤ 1 then go to Step 5. Step 3:  = /2 Step 4: Return to Step 2 Step 5:  = 2

Write a script or a function, based on this algorithm, to determine the machine epsilon. Compare your result to Matlab’s eps.

*Learning outcomes: iii (Problems 1-6), ii (Problems 7-10 and honors)

For the following problem, email your solution as an mfile via email to Prof. Hassoun by the deadline for this assignment. Use comments in your function to explain the code in details. Be prepared to explain your solution to your Professor. Name your file using your last name.

11. Write a Matlab function that converts any decimal number to its IEEE-754 64-bit floating point binary representation. Your function should accept a decimal number as input and should output the sign bit, the normalized mantissa and the biased exponent as binary strings of 1s and 0s without spaces in between. A sample output would look as follows:

Input: -103.45 IEEE-754, 64-bit floating point number representation: Sign = 1 Mantissa (52 bits) = 10011101110011001100110011001100110011001100110011011. Exponent (11 bits) = 1000000010111000000010

(Here is a link for an online-calculator that you may employ to verify your answers: http://babbage.cs.qc.cuny.edu/IEEE-754/)

*Learning outcomes: iii (Problems 1-6), ii (Problems 7-10 and honors)