Assignment 1 Solutions - Numerical Computation | CSCI 3656, Assignments of Computer Science

Material Type: Assignment; Class: Numerical Computation; Subject: Computer Science; University: University of Colorado - Boulder; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 02/10/2009

koofers-user-oks-1
koofers-user-oks-1 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
January 20, 2009
CSCI 3656
Solutions to Assignment 1
1. Machine epsilon is the smallest number x such that fl(1 + x)>1.Here’s a script
that finds it:
function meps = macheps
meps = 1;
while (1.0 + meps > 1.0)
meps = meps/2;
end
meps = meps*2
You just have to be careful not to get macheps/2.
On a machine that obeys the IEEE standard, double precision macheps is 2.21016.
That is the value returned by Matlab’s eps. (Also, see the note at the end of the
next solution.)
2. (10 points) In this system,
First, consider the 3 bit exponents:
mine = (000)2= 0
maxe = (111)2= 7.
The values 0 and 7 are reserved, so the range of biased exponents is [1,6].
In IEEE, where there are 8 bits for the exponent, the bias on the exponent is 2811 =
127.So, the bias on our exponent is 2311 = 221 = 3, and the range of unbiased
exponents pis [1 3,63] = [2,3].
For the 5 bit fraction:
minf = (.00000)2= 0
maxf = (.11111)2= 0.96875.
Which translates into a mantissa of
minm =min(1.f)2= (1.00000)2= 1
maxm =max(1.f)2= (1.11111)2= 1.96875.
Machine epsilon is 25= 0.03125.
pf2

Partial preview of the text

Download Assignment 1 Solutions - Numerical Computation | CSCI 3656 and more Assignments Computer Science in PDF only on Docsity!

January 20, 2009

CSCI 3656

Solutions to Assignment 1

  1. Machine epsilon is the smallest number x such that f l(1 + x) > 1. Here’s a script that finds it:

function meps = macheps

meps = 1; while (1.0 + meps > 1.0) meps = meps/2; end meps = meps*

You just have to be careful not to get macheps/2. On a machine that obeys the IEEE standard, double precision macheps is 2. 2 ∗ 10 −^16. That is the value returned by Matlab’s eps. (Also, see the note at the end of the next solution.)

  1. (10 points) In this system,

First, consider the 3 bit exponents:

mine = (000) 2 = 0 maxe = (111) 2 = 7.

The values 0 and 7 are reserved, so the range of biased exponents is [1, 6]. In IEEE, where there are 8 bits for the exponent, the bias on the exponent is 2^8 −^1 −1 =

  1. So, the bias on our exponent is 2^3 −^1 − 1 = 2^2 − 1 = 3, and the range of unbiased exponents p is [1 − 3 , 6 − 3] = [− 2 , 3]. For the 5 bit fraction: minf = (.00000) 2 = 0 maxf = (.11111) 2 = 0. 96875. Which translates into a mantissa of

minm = min(1.f ) 2 = (1.00000) 2 = 1 maxm = max(1.f ) 2 = (1.11111) 2 = 1. 96875.

Machine epsilon is 2−^5 = 0. 03125.

So, the range of normalized positive floating-point numbers (not counting zero) is

[(1.00000) 2 ∗ 2 −^2 , (1.11111) 2 ∗ 23 ] = [0. 25 , 15 .75].

If you want to consider denormalized numbers, that range becomes

[(0.00001) 2 ∗ 2 −^2 , (1.11111) 2 ∗ 23 ] = [0. 03125 , 15 .75].

But, plus and minus zero are of course representable by means of the exceptional exponents, so the range is actually

[+0. 000 , 15 .75].

(+0.000 is technically a positive number, but it’s fine if your answer is the above 0. and not this one including it.) I told you in class today that the text had the wrong definition of machine epsilon. That’s not actually true–rather it is an alternative definition of machine epsilon (but not a standard one). If you use the text’s definition, machine epsilon here is 2−^6 , and you’d remove the final step meps = meps*2 from the script in the first problem.

  1. (5 points extra credit) With this program, I was able to watch the 1 move down the initially normalized number and fall off after it reached the 52nd bit:

function u = uflo

u(1) = realmin; for i = 1: u(i+1) = u(i)/2; end format long e u

I’ll be interested to see if anyone discovered a machine where denormalized numbers were not properly implemented.

If you worked with other people on any of these problems, you must list the names of your collaborators. All writeups must be your own.