Practice Midterm Problems Midterm: March 4, In Class Do you prefer the exam to be lengthy (and open book) or shorter (and closed book)? Discussion in Lecture 2/25/98 You are welcome to use MATLAB to check your answers for practice, but I think it's important for you to think through the answers and write them up yourself to prepare for the in class midterm. 1) Draw the following matrices. Give the sizes of the following matrices a) A = [1,0,0,0,0,1]; b) A = [1,0,0;0,0,1]; c) A = [1,0;0,0;0,1]; d) A = [1;0;0;0;0;1]; e) T = [ 4 24 9]; Q = [ T 0 T ]; R = [ T ; 3:5; 2*T]; 2) Given the following matrix -- -- | 0.6 1.5 2.3 -0.5 | | 8.2 0.5 -0.1 -2.0 | G = | 5.7 8.2 9.0 1.5 | | 0.5 0.5 2.4 0.5 | | 1.2 -2.3 -4.5 0.5 | -- -- Display the following. What is the size? a) A = G(:,2); b) B = G(4,:); c) C = [10:15]; d) D = [4:9; 1:6]; e) E = [0.0:0.1:1.0]; f) F = G(1:2:5,:); 3) Give MATLAB commands to compute the following values. Assume that the variables in the equations are scalars and have been assigned values. a) Coefficint of friction between tires and pavement: v^2 friction = ----- 30s b) slope between two points (x1,y1) and (x2,y2) y2 - y1 slope = ------- x2 - x1 c) resistance of a parallel circuit 1 resistance = ---------------- 1 1 1 --- + --- + --- r1 r2 r3 d) pressure loss from pipe friction 1 v^2 loss = f p --- ---- d 2 4) Given A = [2 -1 5 0] B = [3 2 -1 4] Give the value of C after executing the following statements a) C = A - B; b) C = B + A - 3; c) C = 2*A + A.^B; d) C = (2).^B + A;; e) C = B.\A; f) C = 2*B/3.0.*A; 5) Evaluate the following expression a) round([0:0.3:2,1:0.75:4]) 6) Give MATLAB commands for the following values Assume that the variables in the equations are scalars and have been assigned values. a) Electrical oscillation frequency 1 frequency = --------------- (2 pi * c) sqrt(--------) ( L ) 7) Determine is the following expressions are true(1) or false(0). Assume a = 5.5 b = 1.5 k = -3 a) b - k > a b) a + b >= 6.5 c) a < 10 & a > 5 d) ~(a == 3*b) e) abs(k) > 3 | k < b-a 8) Determine the value of the following expression. Assume -- -- | 1 0 4 | b = | 0 0 3 | | 8 7 0 | -- -- a) any(b) b) find(b) c) all(any(b)) d) any(all(b)) e) any(b(1:2,1:3)) 9) Give MATLAB statements that performs the steps indicated. Assume that are variables are scalars. Choose reasonable (valid) names for your variables and clearly indicate what you are doing. a) if time is greater than 50.0, increment time by 1.0 b) when the square root of poly is less than 0.001, print the value of poly c) if the difference between volt_1 and volt_2 is greater than 2.0, print the values of volt_1 and volt_2 d) if the value of den is less than 0.003, set result to zero, otherwise, set result equal to num divided by den e) if the natural logarithm of x is greater than or equal to 10, set time equal to zero and increment count. f) if dist is greater than or equal to 100.0, increment time by 10. if dist is between 50 and 100, increment time by 1. otherwise increment time by 0.5