CSC 336H
Sample Midterm Test 1 February 2018
Duration: Aids Allowed:
50 minutes
A calculator.
A single 8.5 by 11 inch aid sheet, written on one side only.
The aid sheet must be a handwritten original copy. No photocopies.
Student Number: Family Name: First Name:
Do not turn this page until you have received the signal to start. Please fill out the identification section above.
This test consists of 5 questions on 6 pages (including this one).
When you receive the signal to start, please make sure that your copy of the test is complete.
#1: /6
#2: /6
#3: /6
#4: /6
#5: /6
TOTAL: /30
This test is double-sided.
University of Toronto
Page 1 of 6
cont’d. . .
Good Luck
CSC 336H Sample Midterm Test 1 February 2018
Question 1. [6 marks] Part (a) [2 marks]
In a floating-point number system, is the product of two floating-point numbers usually exactly repre- sentable in the floating-point system? Explain.
Part (b) [2 marks]
Give examples of floating-point arithmetic operations that would produce each of the exceptional values
Inf and NaN.
Would produce Inf:
Would produce NaN:
Part (c) [2 marks]
In what circumstances does cancellation occur in a floating-point system?
University of Toronto Page 2 of 6 cont’d. . .
CSC 336H Sample Midterm Test 1 February 2018
Question 2. [6 marks] Part (a) [4 marks]
If A is an n×n matrix, x is an n×1 (column) vector and y is a 1×n (row) vector, which of the following computations requires less work? Explain.
1. B=(x∗y)∗A 2. B=x∗(y∗A)
Part (b) [2 marks]
Give an example of a 3 × 3 matrix A, other than the identity matrix, such that cond(A) = 1. Justify your
response.
University of Toronto Page 3 of 6 cont’d. . .
CSC 336H Sample Midterm Test 1 Question 3. [6 marks]
The dot product of two n-vectors x and y may be defined using the formula
February 2018
n x·y=xi∗ yi. i=1
The formula suggests use of the algorithm:
dotProd = x(1) * y(1)
for i = 2:length(x)
dotProd = dotProd + x(i) * y(i)
end for
This algorithm does not always compute an accurate result when implemented using floating-point arith- metic. Discuss the numerical difficulties that might arise and propose alternative approaches that may make the algorithm’s result more accurate.
University of Toronto Page 4 of 6 cont’d. . .
CSC 336H Sample Midterm Test 1 February 2018 Question 4. [6 marks]
135 010 1 0 0 484 4 LetA=4 8 4,P=0 0 1,L=0.5 1 0,U=0 2 6andb=4.
2 6 8 1 0 0 0.25 0.5 1 0 0 1 6 Part (a) [2 marks]
Show that PA = LU.
Part (b) [4 marks]
Use the PA = LU factorization to solve the problem Ax = b for x. Please show all steps in your solution.
University of Toronto Page 5 of 6 cont’d. . .
CSC 336H Sample Midterm Test 1 February 2018 Question 5. [6 marks]
The “floor” of a real number x is an integer valued function of x, usually denoted ⌊x⌋, and defined as ⌊x⌋ ≡ the largest integer ≤ x.
Suppose that you have a function with prototype int mfloor ( float x ). Given a normalized number x in the IEEE single-precision floating-point number system, mfloor returns an approximation to ⌊x⌋.
The following program segment attempts to print out ⌊2ke⌋ for k from 1 to 29.
float x;
int j,k;
x = (float) exp( 1.0 );
for ( k = 1; k < 30; k ++ ) {
x = 2.0 * x;
j = mfloor( x );
printf("k = %2d j = %10d \n", k, j);
}
Explain why the program will most likely print out a wrong value for ⌊2ke⌋, for some k.
Note: The exp function computes the exponential of x, ex, where the irrational number e is the base of natural logarithms. The float variables implement the IEEE single precision floating-point number system which has parameters β = 2, p = 24, L = −126, and U = 127. Assume that int variables are 32 bits in size.
University of Toronto Page 6 of 6 End of Test