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

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
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 .
Image of page 2
3 (2) (Programming) Implement the following algorithm for converting a decimal number to its binary equivalent x = ( a n a n - 1 . . . a 0 ) 2 . Step 1: x 0 := 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. I’ve implemented some error checking and added commentary since it’s 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 );
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern