Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Computer Arithmetic in Scientific Computing - Assignment | CS 340, Assignments of Computer Science

Material Type: Assignment; Professor: McNelis; Class: Intro Scientific Comp; Subject: Computer Science; University: Western Carolina University; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-n3k
koofers-user-n3k 🇺🇸

5

(1)

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 340 Introduction to Scientific Computing
Homework Project # 4: Computer Arithmetic
Purpose of the Project:
This project was designed to make sure each student is comfortable with IEEE floating point numbers and
computer arithmetic, as well as potential errors associated with floating point arithmetic in limited preci-
sion environments.
You are required to write your solutions to this homework in L
A
T
E
X. You are to submit the electronic
portions of your homework (the .tex file, the .pdf file, and the graphics files) via WebCAT.
1. Suppose you are working with a machine that uses 6 bits to represent a number: 1 bit to represent
the sign, s, 2 bits to represent the exponent (characteristic), c, and 3 bits to represent the fraction
(mantissa), f.
(a) [4 points] Determine the value for “shift” here. Explain your reasoning.
(b) [6 points] Use a graphics package to draw a number line, and plot and label all of the positive
machine numbers representable with this machine on it. (Hint: you may want to color code
them for your own use, with one color for each cvalue.) Give the illustration here.
(c) [6 points] If you were allowed access to 3 additional bits to represent each number, and you
knew you needed to represent much smaller (in magnitude) numbers than what you’ve listed
above, give TWO ways in which you would change your number representation (in bits and/or
formula) to achieve this. Explain your reasoning.
2. Recall our Mini-Machine from class, that used 6 bits to represent a number: 1 bit to represent
the sign, s, 3 bits to represent the exponent (characteristic), c, and 2 bits to represent the fraction
(mantissa), f. In this case our floating point number was of the form
(1)s2c3(1 + f)
Suppose that was the “short form” representation for machine numbers on the Mini-Machine, and
there’s also a “long form” available that utilizes twice as many bits to represent a number. With
the long form, the bits are distributed in the following fashion: 1 bit to represent the sign, 5 bits
to represent the exponent, and 6 bits to represent the fraction. The long form of the floating point
number is then given by
(1)s2c15(1 + f)
(a) [5 points] Explain why all of the short form numbers can be represented in the long form.
(b) [5 points] Find machine epsilon if the long format is our most precise representation of num-
bers?
(c) [5 points] How many long form floating point numbers are there between any two adjacent short
form floating point numbers? Explain your reasoning. (You really don’t want to enumerate
these. There are at least two ways to come up without enumerating them.)
(d) The following machine number is given in the “long format”.
1 10111 011101
i. [3 points] Determine it’s base 10 (decimal) equivalent. Show your calculations.
ii. [4 points] Find the next largest and smallest machine numbers, and represent these in their
“long format” as well as with their decimal equivalent. Label your answers accordingly.
1
pf2

Partial preview of the text

Download Computer Arithmetic in Scientific Computing - Assignment | CS 340 and more Assignments Computer Science in PDF only on Docsity!

CS 340 – Introduction to Scientific Computing Homework Project # 4: Computer Arithmetic

Purpose of the Project: This project was designed to make sure each student is comfortable with IEEE floating point numbers and computer arithmetic, as well as potential errors associated with floating point arithmetic in limited preci- sion environments.

You are required to write your solutions to this homework in LATEX. You are to submit the electronic portions of your homework (the .tex file, the .pdf file, and the graphics files) via WebCAT.

  1. Suppose you are working with a machine that uses 6 bits to represent a number: 1 bit to represent the sign, s, 2 bits to represent the exponent (characteristic), c, and 3 bits to represent the fraction (mantissa), f.

(a) [4 points] Determine the value for “shift” here. Explain your reasoning. (b) [6 points] Use a graphics package to draw a number line, and plot and label all of the positive machine numbers representable with this machine on it. (Hint: you may want to color code them for your own use, with one color for each c value.) Give the illustration here. (c) [6 points] If you were allowed access to 3 additional bits to represent each number, and you knew you needed to represent much smaller (in magnitude) numbers than what you’ve listed above, give TWO ways in which you would change your number representation (in bits and/or formula) to achieve this. Explain your reasoning.

  1. Recall our Mini-Machine from class, that used 6 bits to represent a number: 1 bit to represent the sign, s, 3 bits to represent the exponent (characteristic), c, and 2 bits to represent the fraction (mantissa), f. In this case our floating point number was of the form

(−1)s^2 c−^3 (1 + f )

Suppose that was the “short form” representation for machine numbers on the Mini-Machine, and there’s also a “long form” available that utilizes twice as many bits to represent a number. With the long form, the bits are distributed in the following fashion: 1 bit to represent the sign, 5 bits to represent the exponent, and 6 bits to represent the fraction. The long form of the floating point number is then given by (−1)s^2 c−^15 (1 + f )

(a) [5 points] Explain why all of the short form numbers can be represented in the long form. (b) [5 points] Find machine epsilon if the long format is our most precise representation of num- bers? (c) [5 points] How many long form floating point numbers are there between any two adjacent short form floating point numbers? Explain your reasoning. (You really don’t want to enumerate these. There are at least two ways to come up without enumerating them.) (d) The following machine number is given in the “long format”.

1 1 0 1 1 1 0 1 1 1 0 1 i. [3 points] Determine it’s base 10 (decimal) equivalent. Show your calculations. ii. [4 points] Find the next largest and smallest machine numbers, and represent these in their “long format” as well as with their decimal equivalent. Label your answers accordingly.

  1. [12 points] Prove that multiplication (of two non-zero numbers x and y) on a computer is a stable operation, in terms of relative error.
  2. [12 points] Use four-digit decimal floating point representation of numbers with rounding arithmetic to perform the following calculations. Compute the absolute error and relative error with the exact value determined to at least eight digits. Let

x = 192. 4031 , y = 0. 00605008 , z = 192. 2758

(a) x ∗ y (b) x − z (c)

z y

  1. (a) [6 points] Use four-digit decimal floating point representation of numbers with chopping arith- metic, and the quadratic formula:

x =

−b ±

b^2 − 4 ac 2 a to approximate the solutions to the quadratic equation given by

  1. 05010 x^2 − 98. 78 x + 5.015 = 0

You do NOT have to show all of your steps. (b) [4 points] Compute the absolute and relative errors of each result, taking the true solutions to be 1971.605916 and 0.05077069387. (c) [5 points] Explain any surprising results, and make a suggestion on how to rearrange the calcu- lation of the quadratic formula to improve your results.

  1. The exact values of

A =

x tan x cos x − 1

, B =

x sin x cos^2 x − cos x

, C = −

x(sin(x) + tan(x)) sin^2 x

, D = 2

(x sin x + x tan x) cos(2x) − 1

are equal when they are defined.

(a) [9 points] Use calculus to evaluate lim x→ 0

x tan x cos x − 1

. Show all of your work! (L’Hopital’s Rule!!)

(b) [6 points] Use Excel (or any spreadsheet) to evaluate these expressions for x = 2−k^ for k = 1 , 2 , · · · , 30. Make sure you have at least six columns: one for k values, one for the x values, and one column each for expressions A, B, C, and D. Make sure that you display each result to 10 decimal places and have adequate space to display these digits. Turn in a copy of this spreadsheet, saved as XGoesToZero.xls. (c) [8 points] Does Excel produce the same result for expressions A, B, C and D for all values of x here? If not, which formula is more reliable? Explain your reasoning thoroughly in terms of the stability of computer arithmetic.