hw1_solutions - Homework 1 Math 471, Fall 2006 Assigned:...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Homework 1 Math 471, Fall 2006 Assigned: Friday, September 7, 2007 Due: Friday, September 14, 2007 Section 002 This document is intended to show what a good solution to the first homework assignment might look like. Note in particular the following points of style: There is a cover page with my name and section number. I have written in complete, English sentences. I boxed my answers whenever it was appropriate. (I admit that the boxes are not typeset very well, but we all have our flaws.) The answers are both complete and concise. I included the Matlab code for my program and a transcript of the output. The Matlab code has comments. The tables are neatly printed with the required number of rows, decimal places, etc. The problems are all labeled, and the pages are all in order. 1 2 (1) (Finite precision numbers) The floating point representation of a real number takes the form x = (0 .a- 1 a- 2 ...a- n ) e , where a- 1 6 = 0,- M e M . Suppose that = 2, n = 4, and M = 5. (a) Find the smallest and largest positive numbers that can be represented in this floating point system. Give your answers in decimal form. The largest positive number that can be represented in this floating point system is +(0 . 1111) 2 2 5 = 30 . The smallest positive number is +(0 . 1000) 2 2- 5 = 0 . 015625 (Recall that the first digit to the right of the decimal must be nonzero.) (b) Find the floating point number in this system that is closest to 2. The number closest to 2 = 1 . 4142 is +(0 . 1011) 2 2 1 = 1 . 375 . 3 (2) (Programming) Implement the following algorithm for converting a decimal number to its binary equivalent x = ( a n a n- 1 ...a ) 2 . Step 1: x := x ; j := 0 Step 2: while x j 6 = 0 , do a j := remainder of integer division x j / 2 x j +1 := quotient of integer division x j / 2 j := j + 1 end while The Matlab functions rem , mod , and floor may be useful. Make sure your algorithm prints the result out in the correct order. Apply the algorithm to convert the numbers x = 34 and x = 2006 into binary. The following Matlab function accepts a natural number x and prints its binary ex- pansion. Ive implemented some error checking and added commentary since its good programming practice. function PrintBinary(x) if (x <= 0), error( The input was not positive. ); end if (x ~= floor(x)), error( The input was not an integer. ); end j = 1; % Set the position counter to one % since Matlab indexes arrays starting % from one (not zero, like C) while (x > 0) a(j) = mod(x, 2); % Find and store the LSB of x x = floor(x / 2); % Remove the LSB from x j = j + 1; end a = a(:); % Force a to be a row vector a = fliplr( a ); % Reverse the entries so they print % in the correct order a % Print out the answer Here is a transcript of the program output, edited slightly for legibility....
View Full Document

Page1 / 10

hw1_solutions - Homework 1 Math 471, Fall 2006 Assigned:...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online