CS 323 - Spring 2006
Homework 2

Due at start of class: Wednesday, February 22


Check this page for updates and clarifications
(Any changes will be marked with [Update])


Instructions
Answer the following questions. When writing up your solution, include some brief narrative to explain your approach (in other words, show your work; don't just give the final answer.) Clearly state any assumptions you make.

When you use MATLAB, hand in everything: the programs, transcripts (from the command window) and graphs. Label them (by hand is ok). No need to write a general program (such as one that accepts varying input) unless explicitly specified. Comment the program and output so that it can be understood without too much trouble. Print out any graphs.


Problem 1
Let all of the numbers given below be correctly rounded (in base 10) to the number of digits shown. (Assume you round up for a number that ends in a 5.) For each calculation, determine the smallest interval in which the results, using true instead of rounded values, must lie. (For instance, given the number 3.4; the true value of this number could have been as small as 3.35 but also must be less than 3.45.)

(a)    2.377 + 1.034

(b)    4.20 - 4.18

(c)    15.32 * 0.189


Problem 2
Find bounds for the error and relative error in approximating sin(pi/3) by:

(a)    sin(1.05)

(b)    sin(1.0472)

[Update 2/15] This question is not asking for the actual error, but upper and lower bounds on the error. See § 2.3.1 (p 60). (As a way of checking your work, you still might want to find the actual error, and see that your bounds respect it.)

[Update 2/19] To further clarify this, you treat the values above (1.05 and 1.0472) as the approximate values. You don't treat 1.05 as rounded from an unknown value in a range, like in problem 1.


Problem 3
Look at problem 1(a) in § 2.4 (page 69).

Now, consider the computation of this sum when:

A C++ program was written that implements all eight combinations of these for this problem, for N=10^i for i in 0..8. The output of this program (which you can paste into matlab) is here.

(You probably won't need to compile, run, or use the C++ program, but for completeness, here it is.)

In the output, the vector N holds the values used for n in the summation, and the vectors that follow hold the errors in computations that resulted from using these values of n. The variable names of these vectors starts with either LS or SL and is followed by an s or d for single/double precision, and an r or c for rounding/chopping.

Using Matlab, try to use this data to support the following claims. If the claim is too strong, explain how, and give a weaker claim that still makes the same point. Support this with brief explanation via graphs, etc... In some cases, it might not be possible with the data; when this happens, say so, and explain why you can't draw your conclusion.

Suggestion: you should probably graph using log10(N) instead of N (in which case the x-axis would be the exponent on the 10), as it spaces things out much more nicely. Don't forget how this changes the shape of the graph.

(example)    When using rounding, errors get larger as n increases.

Answer: This is only a general trend, as rounding errors can cancel more in certain situations than in others. When the errors are larger (for LS), this trend is apparent in a log-log plot:
   plot(log10(N), log(abs(LSsr)), '.-g', log10(N), log(abs(LSdr)), '.-b');
       (The first blue point is missing as it had zero error, and was lost in the log. No big deal.)

When the errors are very small (for SL), the rounding errors don't seem to accumulate, as is the case for double precision:
   plot(log10(N), SLdr, '.-');

Justify/modify/explain the following:

(a)    Using double precision (for both LS or SL) for the summation is always better (or equal) to using single precision (for both LS or SL).

(b)    Errors when using rounding are always smaller (or equal) in magnitude than errors are when using chopping, when comparing like-methods (LS/SL) and like-precisions (single/double).

(c)    Errors when using chopping grow at most linearly with n; and for rounding, by at most the square root of n (scaled by an appropriate constant). See § 2.4.1.

[Update 2/15] The phrase "or equal" was added to (a) and (b) above to clarify what "better" means. We're really interested in explanations that apply to any summation, not just this one.

Keep your explanations brief for this problem; don't ramble.


323 Home