SPH 7460 Final Exam December 21, 2009 page 1 of 6 Five Problems - 6 pages Name: _________________________________________ ===================================================================================== 1. A transformation T of two-dimensional space R^2 is defined to be the composition of two other transformations, R followed by S. That is T = S o R, or in other words: | X | | X | T | | = S ( R | | ), | Y | | Y | | 1 | | -5 | | 0 | | -3 | where R | | = | | and R | | = | | , and S is reflection through the Y - axis. | 0 | | -1 | | 1 | | 1 | a) Find the 2 x 2 matrix A corresponding to T. | -1 0 | | -5 -3 | | 5 3 | [6] A = S o R = | | * | | = | | | 0 1 | | -1 1 | | -1 1 | b) Compute the two eigenvalues and eigenvectors of T. | 5 - x 3 | Eigenvalues of A: det | | = x**2 - 6*x + 8 = (x - 2)*(x - 4), | -1 1 - x | | 3 | | 1 | so the eigenvalues are 4, 2. The corresponding eigenvectors are | | and | |. | -1 | | -1 | [7] c) Write a PROC IML program that computes the eigenvalues and eigenvectors of T. proc iml ; [7] A - {5 3, -1 1} ; call eigen(D, P, A) ; print "Matrix A : " A ; print "Eigenvalues : " D ; print "Eigenvectors : " P ; quit ; SPH 7460 Final Exam December 21, 2009 page 2 of 6 Name: _________________________________________ ===================================================================================== 2. Check digits are often used for numerical IDs. Assume that the main part of the ID is a 4-digit number, like N = 3815. To compute the check digit: Multiply the rightmost digit by: 2, Multiply the next digit to the left by: 1, Multiply the next digit to the left by: 2, Multiply the next digit to the left by: 1, etc. For 3815, the process is: Digits of N: 3 8 1 5 Multipliers: 3 x 1 8 x 2 1 x 1 5 x 2 Products: 3 16 1 10 Add the resulting digits: 3 + 1 + 6 + 1 + 1 + 0 = 12 ------ Subtract this from the next largest multiple of 10: 20 - 12 = 8 The check digit is 8. (a) Compute the check digit for N = 9768. 9 7 6 8 x 1 2 1 2 [5] 9 + 1+4 + 6 + 1+6 = 27 Checkdigit is 30 - 27 = 3. [continue on next page] SPH 7460 Final Exam December 21, 2009 page 3 of 6 Name: _________________________________________ ===================================================================================== 2., Continued (b) Write a macro which computes the check digit for any 3-digit number, N. The call to the macro should look like: %check(n, checkdig) ; where n is the input and checkdig is the output. [15] The following macro should work for numbers n with any number of digits - %macro check(n, checkdigit) ; m = &n ; start = 2 ; sumdigits = 0 ; do while m ne 0 ; md10 = int(m / 10) ; lastdigit = m - 10 * md10 ; product = start * lastdigit ; prod1 = int(product / 10) ; prod2 = product - 10 * prod1 ; sumdigits = sumdigits + prod1 + prod2 ; m = md10 ; start = 3 - start ; end ; a = 10 ; do while sumdigits > a ; a = a + 10 ; end ; &checkdigit = a - sumdigits ; %mend ; SPH 7460 Final Exam December 21, 2009 page 4 of 6 Name: _________________________________________ ===================================================================================== 3. Data are collected on one person's triglyceride levels, every hour for 48 hours. It is believed that triglyceride levels are cyclic - that is, they are function of the time of day. The model that is usually assumed is: T(t) = a + b * cos((pi/12)*t + c) + error, where the assumption is that error ~ N(0, sigma^2). Here a, b, and c are unknown constants. The variable t is time in hours. pi is the constant 3.141592. The objective here is to use the data to estimate a, b, and c. Write a program in SAS which includes the PROC NLIN procedure to do this. proc nlin data = trigdata method = marquardt ; */ Data file trigdata has values for trig, t /* ; parms a 0 b 0 c 0 ; [20] pi = 3.141592 ; der.a = 1 ; der.b = cos(pi*t/12 + c) ; der.c = -b * sin(pi*t/12 + c) ; model trig = a + b * cos(pi*t/12 + c) ; run ; SPH 7460 Final Exam December 21, 2009 page 5 of 6 Name: _________________________________________ ===================================================================================== 4. A simple game is played as follows. You are given a random integer between 1 and 10. You then decide whether you will be given another random integer between 1 and 10. If the sum of your numbers, S, is less than 13, you win S. If the sum of the two numbers is 13 or bigger, you win nothing. The only decision you make in this game is whether or not you will ask to be given a second random integer. A good strategy for this game would be a strategy that maximizes your expected winnings. a) What would you guess is the best strategy? [You don't need to give a proof, just a little explanation of why you think your strategy is best.] The following logic is tempting: Let s1 = first number, s2 = second number. The expected values of s1 and s2 are both 5.5. [5] So if s1 <= 7, the expected value of s1 + s2 is s1 + 5.5 <= 12.5. If s1 >= 8, then the expected value of s1 + s2 is >= 13.5. So the best strategy seems to be to ask for a second number if s1 <= 7, and not ask if s1 >= 8. However, it is incorrect! The best strategy is to ask for s2 if s1 <= 5. If s1 > 5, then the best strategy is to stay with s1. Example: suppose s1 = 6. Then there are two cases. If s2 < 6, then s1 + s2 < 13. The possible choices for s2 in this case are 1, 2, 3, 4, 5, 6, each with probability 1/10. The corresponding s1 + s2 = 7, 8, 9, 10, 11, 12. The average of these is 57/6 = 9.5. If s2 > 6, then the sum s1 + s2 = 0, and the average is 0. The overall average is: .6 * 9.5 + .4 * 0 = 5.7. Which means that when s1 = 6, you do better with strategy 1! b) Write a program which simulates this game. Assume you will do 10,000 simulations. In each simulation, record two outcomes: one where you decide not to ask for a second integer, and the other where you do ask for a second integer. Record the output in such a way that you will be able to evaluate your best strategy, and explain. Note that your strategy will depend on the value of the first integer. data simgame ; do i = 1 to 10000 ; s1 = 1 + int(10 * ranuni(-1)) ; s2 = 1 + int(10 * ranuni(-1)) ; strategy1 = s1 ; strategy2 = s1 + s2 ; if strategy2 ge 13 then strategy2 = 0 ; output ; end ; run ; proc means data = simgame ; class s1 ; var strategy1 strategy2 ; run ; [This program confirms the logic given above.] [15] SPH 7460 Final Exam December 21, 2009 page 6 of 6 Name: _________________________________________ ===================================================================================== 5. A nonlinear function G: R^2 --> R^2 is defined as follows: | X | | .5 + sin(X + Y) + X^2 + Y | G | | = | | | Y | | -.3 + exp(X - Y) - Y - 2*X | | X | | 0 | Write a PROC IML program in SAS which will solve G | | = | | | Y | | 0 | proc iml ; start gfunc(a, b, g, dg) ; g1 = .5 + sin(a + b) + a*a + b ; g2 = -.3 + exp(a - b) - b - 2*a ; dg1a = cos(a + b) + 2*a ; dg1b = cos(a + b) + 1 ; [20] dg2a = exp(a - b) - 2 ; dg2b = -exp(a - b) - 1 ; e1 = {1, 0} ; e2 = {0, 1} ; s1 = {1 0, 0 0} ; s2 = (0 1, 0 0} ; s3 = {0 0, 1 0} ; s4 = {0 0, 0 1} ; g = g1*e1 + g2*e2 ; dg = dg1a*s1 + dg1b*s2 + dg2a*s3 + dg2b*s4 ; finish gfunc ; data solve ; x = 0 ; y = 0 ; v1 = {1, 0} ; v2 = {0, 1} ; eps = 1e -8 ; absg = 99999 ; do i = 1 to 30 while (absg > eps) ; run gfunc(x, y, g, dg) ; v = x*v1 + y*v2 ; v = v - inv(dg) * g ; absg = sqrt(g` * g) ; print i v g dg absg ; end ; run ;