






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Question 1: Which of the following choices will generate a vector p whose elements are the following? 0, 4, 8
a) p = linspace(0, 4, 8) b) p = linspace(0, 8, 4) c) p = linspace(0, 8, 3) Answer c d) p = linspace(0, 3, 8)
Question 2: Which of the following choices will generate a vector p whose elements are the following? 0, 4, 8
a) p = 0:4:8 Answer a b) p = 0:8: c) p = 0:8: d) p = 0:3:
Question 3: After the following code fragment is run, what is the value of y?
x = [1,2,3; 4,5,6; 7,8,9]; y = x(end-1:end, [1,2])
a) [4, 5, 7, 8] b) [1, 2; 3, 4] c) [4, 5; 7, 8] Answer c d) [1, 2, 3, 4]
Question 4: After the following code fragment is run, what is the value of y?
z = [1, 2; 3, 4]; y = [z(:,1)'; z(2,:)]
a) [1, 2; 3, 4] b) [2, 1, 3, 4] c) [1, 2, 3, 4] d) [1, 3; 3, 4] Answer d
Question 10: After the following code fragment is run, what is the value of A?
A = ones(4,4); B = zeros(2,2); A(3:end, 1:end-2) = B
a) [0,0,1,1; 0,0,1,1; 1,1,1,1; 1,1,1,1] b) [1,1,0,0; 1,1,0,0; 1,1,1,1; 1,1,1,1] c) [1,1,1,1; 1,1,1,1; 0,0,1,1; 0,0,1,1] Answer c d) [1,1,1,1; 1,1,1,1; 1,1,0,0; 1,1,0,0]
Question 11: After the following code fragment is run, what is the value of x?
a = 2; b = 4; x = [1,2,3,4; 5,6,7,8; 9,10,11,12]; x(end,:) = 100
a) [1,2,3,100; 5,6,7,8; 9,10,11,100] b) [1,2,3,100; 5,6,7,100; 9,10,11,100] c) [1,2,3,4; 5,6,7,8; 9,10,11,100] d) [1,2,3,4; 5,6,7,8; 100,100,100,100] Answer d
Question 12: After the following code fragment is run, what is the value of x?
a = 2; b = 4; x = [1,2,3,4; 5,6,7,8; 9,10,11,12]; x(:,end-1) = (1:2:6)'
a) [1,2,3,4; 3,6,7,8; 5,10,11,12] b) [1,2,1,4; 5,6,3,8; 9,10,5,12] Answer b c) [1,2,3,4; 1,3,5,8; 9,10,11,12] d) [1,2,3,1; 5,6,7,3; 9,10,11,5]
Question 13: After the following code fragment is run, what is the value of y?
x = [2, 0, 5, 8, 10]; y = find (x<7)
a) [2, 0, 5, 8, 10] b) [2, 0, 5] c) [1, 2, 3] Answer c d) [4, 5]
Question 14: After the following code fragment is run, what is the value of z?
x = [2, 0, 5, 8, 10]; y = find (x<7); z = x(y)
a) [2, 0, 5, 8, 10] b) [4,5] c) [2, 0, 5] Answer c d) [1, 2, 3]
Question 15: After the following code fragment is run, what is the value of y?
x = [2, 4, 6, 7, 5, 8, 10]; y = x(16 < x.^2 & x.^2 < 50)
a) [4, 6, 7, 5] b) [3, 4, 5] c) [6, 7, 5] Answer c d) [2, 3, 4, 5]
Question 16: After the following code fragment is run, what is the value of a?
a = [2, 4, 6, 7, 5, 8, 10]; y = find(a > 4 & a < 8); a(y) = a(y) + 10
a) [16, 17, 15] b) [2, 4, 16, 17, 15, 8, 10] Answer b c) [12, 14, 16, 17, 15, 18, 20] d) [13, 14, 15]
Question 17: Which of the following will NOT generate an error for arrays A, B, and C defined as
A = [1,2,3; 4,5,6]; B = [3,6; 9,12; 15, 18]; C = [2,4; 6,8];
a) A * B’ b) A * B Answer b c) A * C d) A * C’
Question 21: After the following code fragment is run, what is the value of output?
a = 5; b = 10; c = 7; d = 2; output = 12; if ((a > b) & (c > d)) | (c > d) output = 10 else output = 0 end
a) 12 b) [10, 0] c) 0 d) 10 Answer d
Question 22: After the following code fragment is run, what is the value of total?
total = 0:3; for count = 3: total(count-1) = total(count-1) * total(count-2); end
a) [0, 0, 0, 3] Answer a b) [0, 1, 2, 3] c) [1, 2, 2, 3] d) [1, 2, 2, 4]
Question 23: After the following code fragment is run, what is the value of myVar?
data = [1:3; 4:6; 7:9]; [numRows, numCols] = size(data); myVar = 1; for x=1: for y=1: if (x - 1) == (numRows - y) myVar = myVar * data(x,y) end end end
a) 7 b) 45 c) 105 Answer c d) 362880
Question 24: After the following code fragment is run, what is the value of theAns?
data = [1:3; 4:6; 7:9]; count = 0; for j = [2, 3] count = count + 1; theAns(count) = data(j-1,j) * data(j, j-1); end
a) 4: b) 48 c) [8, 48] Answer c d) none of the above
Question 25: After the following code fragment is run, what is the value of mySum?
mySum = 0; for i = 1: for j = 1: for k = 2: mySum = mySum + k; end end end
a) 16 b) 8 c) 12 d) 20 Answer d
Question 26: After the following code fragment is run, what is the value of mySum?
mySum = 0; for i = 1 for j = 1: for k = 1: mySum = mySum + i + j + k end end end
a) 6 b) 16 c) 18 d) 27 Answer d