ECE 204 Numerical Methods for Computer Engineers MIDTERM EXAMINATION 2007-10-23/8:00-9:30 The examination is out of 67 marks. Instructions: No aides. Write your name and student ID number on each booklet. Turn off all electronic media and store them under your desk. Write all your answers in your booklets. Answer the questions order in which they appear on the examination. If you need to write your answer to a question elsewhere as a result of space considerations, please indicate where the answer may be found. You may ask only two questions during the examination: 1. May I go to the washroom? 2. May I have another booklet? At the of the exam, place this exam paper and any additional booklets into the first booklet. Do not leave during the first 30 minutes of the examination. Do not leave during the last 15 minutes of the examination. Do not stand up until all exams have been picked up. You must stop writing when you are told that the examination is finished. No exceptions, not even for your name. (-5 mark penalty.) Attention: The questions are in the order of the course material, not in order of difficulty. I have read and understood all of these instructions and accept a 0 if I fail to follow them: Name: Signature: 0 0000 8 1000 1 0001 9 1001 2 0010 A 1010 3 0011 B 1011 4 0100 C 1100 5 0101 D 1101 6 0110 E 1110 7 0111 F 1111 Page 1 of 5
Error Analysis and Numeric Representation 1. [3] Write the three numbers 52345 2.5455 0.0007821499999 using our decimal-digit floating-point representation of real numbers using the appropriate rounding where the representation of +1 is 0491000 and 1 is 1491000. 2. [3] Write the number 513 10 as a double-precision floating-point number using hexadecimal numbers. Recall that the double-precision floating-point representation of 1 is 3FF0000000000000. 3. [4] Add the following to double-precision floating-point numbers, giving your answer in the same format: 401 3A00000000000 3FD B100000000000 (Hint: just convert to the appropriate binary, don t try to convert to decimal.) Linear Algebra 5. [7] Find the three matrices P T, L, and U of the PLU-decomposition of the matrix 0.9 1.8 M = 9 2.7 7.5 4.2 5 2.5 3.8 9 2 2.8 1 3.4 0 7.3 6. [4] Use the P T, L, and U decomposition of the matrix M to solve the system Mx = b where: 0 1 0 1 0 0 3 0 5 6 T P = 0 0 1, L = 0 1 0, U = 0 2 0, b = 2 1 0 0 0 0.5 1 0 0 4 4 7. [3] Suppose a matrix M is symmetric, diagonally dominant, and has positive entries on the diagonal. Calculating the 1-norm of the matrix is an O(n 2 ) operation. Come up with an O(n) operation which uses the given properties to find an upper bound on the 1-norm of M. (An upper bound is a value which is guaranteed to be equal to or larger than the required value, in this case, the 1-norm of M.) Bonus [2]: give a single Matlab statement which returns your value. Page 2 of 5
8. [3] Use Matlab commands and operators to create a symmetric matrix R which has random entries between 0 and 2. Then, assuming all the diagonal entries of R are nonzero, use this matrix R to create a diagonally-dominant matrix D by adding the sum of each row (including the diagonal) onto the diagonal entry of that row. 8 9. [4] What are the 1 and infinity norms of the matrix M = 2 0 4 10 3 8 5? 9 10. [4] For applying one step of the Jacobi method to solve the system Mx = b given an initial approximation vector x 0, which of the following is more efficient, and explain why. Full marks are awarded for using Landau symbols (big-o). >> D = diag(diag(m)); >> Moff = M D; >> Dinv = D^-1; >> x = Dinv * (b Moff*x0); >> d = diag(m); >> Moff = M diag(d); >> dinv = d.^-1; >> x = dinv.* (b Moff*x0); Interpolation 11. [2] Write down the Vandermonde matrix which is used to find the interpolating polynomial through the points (0, 0.5), (1, 2.3), (2, 5.4), and (3, 4.7). 12. [4] Suppose that the Vandermonde matrix you found in the previous question is assigned to the variable V and y = [0.5 2.3 5.4 4.7]. Write down the Matlab code which would solve the system of linear equations (by the easiest means possible) and (without actually solving the system of linear equations) associate the entries of the solution vector with the coefficients of the appropriate basis functions x 3, x 2, x, and 1. 13. [3] Write a polynomial in x which passes through the (x, y)-point (5.1, 7.2) and is zero at the x-values 3.8, 6.1, 8.9, and 10.5. Page 3 of 5
14. [4] The Newton polynomial which passes through the points (1, -1), (3, 11), (4, 5), and (6, -1) is found by calculating the following divided difference table: 1-1 6 3 11-4 -6 1 4 5 1-3 6-1 Show how we can use this to find the Newton polynomial which passes through the points (3, 11), (4, 5), (6, -1), (8, 1) in linear time (and write down the Newton polynomial). 15. [4] Given the initial Matlab code >> x = [1 3 4 6]; >> c = [-1 6-4 1]; >> x0 = 9; >> y0 = c(4); write a for-loop which evaluates the Newton polynomial which passes through the points (1, -1), (3, 11), (4, 5), and (6, -1) (given in the previous question) using Horner s rule at the point x 0 = 9 and assigns the result to y 0. Least Squares Regression 16. [3] Write down the matrix V which is used to find the best-fitting straight line passing through the points ( 2, 0.1), ( 1, 0.2), (0, 0.5), (1, 1.1), (2, 1.9). 17. [2] Suppose you were given data points (x 1, y 1 ),..., (x n, y n ) which either came from a system of the form ae bx or ax b where a, b > 0, what would you look for to determine which model to use. Short answers, but you may uses diagrams to support your answer. 18. [4] Describe how you could find a best fitting curve to data which is know to be of the form y(x) = ax b e cx. You may either describe it mathematically or use Matlab code. Page 4 of 5
19. [3] The following points come from data which follows the curve described in the previous question. What would you suspect are the signs (positive or negative) of the three coefficients a, b, and c? Matlab 20. [3] What does the following function estimate? function a = h( M ) B = M*M ; c = random( length( M ), 1 ); d = norm(c); for e = 1:100 f = B * (c/d); g = norm( f ); if ( abs( d - g ) < 1e-10 ) a = sqrt( g ); break; c = f; d = g; error( 'the system did not converge' ); Some Matlab commands: random ones zeros sum mean product max diag det norm cond eig trace Page 5 of 5