0% found this document useful (0 votes)
39 views2 pages

Homework #2: MA 402 Mathematics of Scientific Computing Due: Wednesday, January 26

This document outlines 7 problems for a homework assignment on scientific computing and floating point arithmetic. The problems cover topics like carrying out floating point operations by hand, properties of floating point addition and subtraction, avoiding overflow and underflow, square root identities in floating point, factorials and scientific notation, associativity of floating point operations, and testing identities with random test cases. Students are asked to solve the problems, with some requiring MATLAB or Python code, and submit their work by a due date.

Uploaded by

Andrea Stancescu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

Homework #2: MA 402 Mathematics of Scientific Computing Due: Wednesday, January 26

This document outlines 7 problems for a homework assignment on scientific computing and floating point arithmetic. The problems cover topics like carrying out floating point operations by hand, properties of floating point addition and subtraction, avoiding overflow and underflow, square root identities in floating point, factorials and scientific notation, associativity of floating point operations, and testing identities with random test cases. Students are asked to solve the problems, with some requiring MATLAB or Python code, and submit their work by a due date.

Uploaded by

Andrea Stancescu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Homework #2

MA 402
Mathematics of Scientific Computing
Due: Wednesday, January 26

Problem 1. In MATLAB, the code (3*(1+eps) - 3)/eps will return the value
4. In exact arithmetic, the correct answer is 3. Carry out the floating point
arithmetic by hand, bearing in mind that the quantity must be rounded after
each individual binary operation. (Hint: only one of the operations will need to
be rounded; the other three are computed exactly.)
Problem 2 (Higham). Which of the following statements are true in IEEE
arithmetic, assuming that a and b are normalized floating point numbers and
that no overflow or underflow occurs? You should mostly rely on the principle
“fl(x y) is equal to the exact value of x y, rounded correctly.”
a) fl(a + b) = fl(b + a)
b) fl(b − a) = − fl(a − b)

c) fl(a + a) = fl(2 ∗ a)
d) fl((a + b) + c) = fl(a + (b + c))
Problem 3. The MATLAB p code hypot(x,y) (or Python math.hypot(x,y)
evaluates the quantity x + y 2 in a way that is careful to avoid overflow or
2

underflow.

a) Find an example where the code sqrt(x^2 + y^2) overflows but hypot(x,y)
does not.
b) Find an example where the code sqrt(x^2 + y^2) underflows but hypot(x,y)
does not.
c) Find an example where hypot(x,y) will overflow no matter how carefully
it is written.

1
Problem 4 (Higham). Two requirements that we might ask of√a routine for

computing
p x in floating point arithmetic are that the identities x2 = |x| and
( |x|)2 = |x| be satisfied. Barring overflow/underflow, it turns out that only
the first identity can be satisfied.
a) Exactly how many floating point numbers fall in the interval [1, 2]?

b) Approximately how many floating point numbers fall in the interval [1, 2]?
You do not have to be too precise.
c) Use the Pigeonhole Principle to show that there exist distinct floating
point numbers x and y such that sqrt(x) == sqrt(y) in floating point
arithmetic.
p
d) Why can the second identity ( |x|)2 = |x| not be satisfied in IEEE double
precision?
Problem 5. The number of ways to shuffle a standard deck of cards is 52
factorial, written as 52! and equal to 52 × 51 × · · · × 1 or

80658175170943878571660636856403766975289505440883277824000000000000.

In scientific notation, its value is about 8.066 × 1067 . It cannot be represented


exactly in IEEE double precision, but about how accurate (in absolute and
relative terms) can you expect the best floating point approximation to be?

Problem 6 (Moler). Determine what output is produced by the MATLAB


code

t = 0.1
n = 1:10
e = n/10 - n*t.

What does this demonstrate about floating point arithmetic (in particular, as-
sociativity)? Explain.
Problem 7. A useful skill to develop is writing short programs in order to gain
insight into a problem or test a hypothesis. The MATLAB code rand(1,N)
(Python numpy.random.rand(1,N)) will generate a vector of length N whose
entries are uniformly distributed in [0, 1]. In addition, the code isequal(a,b)
(Python numpy.all(a==b)) will determine whether all corresponding entries of
two vectors are equal to one another.
Generate random test cases to examine at least one of the identities in either
Problem 2 or Problem 4. Submit your code separately, but report your results
along with the rest of the written homework.

You might also like