Docsity

Programming Assignment 3 - Computer and Numerical Algorithms | MATH 248, Assignments of Mathematics

Toggle sidebar
bg1
GETTING TO KNOW YOUR MACHINE
Programming Assignment 3 (15 points)
Math 248 Computers and Numerical Algorithms
DATE ASSIGNED: Wednesday, 11 February, 2009
DATE DUE: Tuesday, 24 February, 2009
BACKGROUND: As we discussed in class, not all integers or real numbers can be stored exactly on a
computer, simply because computers use a finite number of bits per “word.” For example, the relationship
between a real number xand its machine number representation ¯xis given by
¯x=f l(x)(1)
where f l(x)(“float x”) can be thought of as a function from the (infinite) set of real numbers xonto the
(finite) set of machine numbers. The difference x−¯xis the absolute round-off error δ. A more useful
concept is relative round-off error ε, the absolute round-off error scaled by x. The maximum absolute
value that εcan obtain on a given machine is called u, the unit round-off error. More precisely, uis the
least upper bound of the absolute relative round-off error; that is, |ε| ≤ u.
ASSIGNMENT: For a “B” grade, do the following for “single-precision” real variables (KIND=4). For
an “A” grade, do the following also for double-precision real variables (KIND=8) in the same program.
1. Implement the unit round-off error algorithm in Fortran 90, and print out the computed value of u.
Note: this requires only a single DO loop.
2. Fortran 90 also provides an intrinsic function EPSILON(x) to compute the unit round-off error.
(Unfortunately, the name of this function if misleading). Use this function to determine u. Compare
your result with that above. Should the two results agree?
3. Based on the results above, and the theory we discussed in class, determine whether or not f l(x)
is determined by chopping or rounding. Show work to substantiate your reasoning. For the “A”
part, infer how many bits are used for the mantissa of double-precision REALs in Fortran 90 on a
PC, assuming that if single-precision REALs are rounded (chopped) then so are double precision
REALs.
4. A-Level Only: Interpret your results in terms of machine precision; that is, about how many decimal
digits of precision should you expect for double-precision machine REAL numbers on a PC?
SPECIAL CONSIDERATIONS: This assignment is to be considered a laboratory assignment whose
results should be clearly explained, with all work shown. Append to your Fortran 90 source code COM-
MENT lines in which you clearly explain and interpret your results. Submit the program with the appended
comments via the auto-submission protocol. You may work solo or with one other student. If working
together, both names should appear in the PREAMBLE and both students should PLEDGE.
As always, you are allowed to discuss programming issues with other students/groups, but the actual
coding of your program should be accomplished individually (or with your partner), and your program
should be unique.

Partial preview of the text

Download Programming Assignment 3 - Computer and Numerical Algorithms | MATH 248 and more Assignments Mathematics in PDF only on Docsity!

GETTING TO KNOW YOUR MACHINE

Programming Assignment 3 (15 points)

Math 248 Computers and Numerical Algorithms

DATE ASSIGNED: Wednesday, 11 February, 2009

DATE DUE: Tuesday, 24 February, 2009

BACKGROUND: As we discussed in class, not all integers or real numbers can be stored exactly on a computer, simply because computers use a finite number of bits per “word.” For example, the relationship between a real number x and its machine number representation ¯x is given by

x¯ = f l(x) (1)

where f l(x) (“float x”) can be thought of as a function from the (infinite) set of real numbers x onto the (finite) set of machine numbers. The difference x − x¯ is the absolute round-off error δ. A more useful concept is relative round-off error ε, the absolute round-off error scaled by x. The maximum absolute value that ε can obtain on a given machine is called u, the unit round-off error. More precisely, u is the least upper bound of the absolute relative round-off error; that is, |ε| ≤ u.

ASSIGNMENT: For a “B” grade, do the following for “single-precision” real variables (KIND=4). For an “A” grade, do the following also for double-precision real variables (KIND=8) in the same program.

  1. Implement the unit round-off error algorithm in Fortran 90, and print out the computed value of u. Note: this requires only a single DO loop.
  2. Fortran 90 also provides an intrinsic function EPSILON(x) to compute the unit round-off error. (Unfortunately, the name of this function if misleading). Use this function to determine u. Compare your result with that above. Should the two results agree?
  3. Based on the results above, and the theory we discussed in class, determine whether or not f l(x) is determined by chopping or rounding. Show work to substantiate your reasoning. For the “A” part, infer how many bits are used for the mantissa of double-precision REALs in Fortran 90 on a PC, assuming that if single-precision REALs are rounded (chopped) then so are double precision REALs.
  4. A-Level Only: Interpret your results in terms of machine precision; that is, about how many decimal digits of precision should you expect for double-precision machine REAL numbers on a PC?

SPECIAL CONSIDERATIONS: This assignment is to be considered a laboratory assignment whose results should be clearly explained, with all work shown. Append to your Fortran 90 source code COM- MENT lines in which you clearly explain and interpret your results. Submit the program with the appended comments via the auto-submission protocol. You may work solo or with one other student. If working together, both names should appear in the PREAMBLE and both students should PLEDGE.

As always, you are allowed to discuss programming issues with other students/groups, but the actual coding of your program should be accomplished individually (or with your partner), and your program should be unique.