Sie sind auf Seite 1von 5

ENGGEN 131 SC 2010

Question 1.
What is displayed when the following code is run?
a=3; b=5; c=10; if((b*c - 2*a) > 45) e= [1,5,3]; else e = [2,4,5]; end if ~(b==c) f= [4,8,12]; else f= [2,9,7]; end if b&&c disp([e*f]); else disp([e.*f]); end

MATLAB TEST 1

a) 68 b) 80 c) 100 d) 2 45 21 e) An error message

Question 2.
How many numbers will the following code display?
balance = 350; price = 160; while (balance > 60) disp(price); balance = balance price; price = price/2; end

a) 1 b) 2 c) 3 d) 4 e) 5

Question 3.
What values are contained in the day array after executing the following code?
d = 30; for i =1:3 d = d + 1; day(i) = d; end for i=4:7 d = d + 2; day(i) = d; end

a) 31, 32, 33, 34, 36, 38, 40 b) 31, 32, 33, 35, 37, 39, 41 c) 31, 32, 35, 37, 39, 41, 43 d) 30, 31, 32, 33, 35, 37, 39 e) 30, 31, 32, 35, 37, 39, 41

Question 4.
What sequence of values would be displayed when the following code is run?
a = 5; b = 1; while ( b < 4) disp(a) a = a + b; b = b + 1; end

a) 5, 6 b) 5, 6, 7 c) 5, 6, 8 d) 5, 6, 7, 8 e) 5, 6, 8, 11

Question 5.
Peter travels 15km to the university on week days and does not travel in on the weekends. On sunny week days Peter cycles the entire way. On rainy week days Peter drives part way and then completes the final 3km journey on his unicycle. Which of the following pieces of code does NOT correctly determine how far Peter will cycle on a given day:
a) if (isRaining & isWeekday) distanceCycled = 3 elseif (isWeekday) distanceCycled = 15 else distanceCycled = 0 end b) if (isWeekday) if (isRaining) distanceCycled = 3 else distanceCycled = 15 end else distanceCycled = 0 end c) if (isRaining) if (isWeekday) distanceCycled = 3 else distanceCycled = 0 end else distanceCycled = 15 end d) if (isWeekday & isRaining) distanceCycled = 3 elseif (~isWeekday) distanceCycled = 0 else distanceCycled = 15 end

e) None of the above are incorrect, they ALL correctly determine the distance cycled.

Question 6.
What is displayed as a result of running the following code?
for i=1:2:5 a(i)=i^2; end disp(a)

a) 25 b) 1 4 c) 1 9 d) 1 4 e) 1 0

25 25 9 16 25 9 0 25

Question 7.
Which one of the following set of commands produce a final sequence of values that is different from the rest?
a) x=linspace(0,16,5) b) x=[13 6 7 11 16 19 12] y=[1 2 3 5 8 13 -12] x=x+y x=x*0.5 x=x([7,2,(4:6)]) c) x=0:4:16 d) x=[0 4 4 12] x=[x,16] x(3)=8

e) None of them, they all produce the same array.

Question 8.
Which function header is the right one that indicates two outputs and one input?
a) b) c) d) e) function function function function function (x,y) [x,y] [x] = [x,y] (x,y) = myfunc[z] = myfunc(z) myfunc(y,z) = myfunc[z] = myfunc(z)

Question 9.
The swap function is defined as follows:
function b = swap(a,b) a = b; b = a; return

What is displayed when the following script file is run?


a = 3; b = 2; a = swap(b,a); disp([a b]) a) 2 2 b) 2 3 c) 3 2 d) 3 3 e) An error message

Question 10.
What is the value of the variable c after running the following code?
a = 5; b = 2; while b(length(b))^3 < a(length(a))^2 a(length(a)+1) = a(length(a))+1; b(length(b)+1) = b(length(b))+1; end c = a + b;

a) 27 b) 11 c) [7 9 11] d) [7 9 11 13] e) None of the above

Das könnte Ihnen auch gefallen