May 1, 2008
A.
B.
C.
D.
E.
2. Given the following lines of code, which of the following operations would produce the same
sound?
[x, fs] = wavread('mysound.wav')
sound(x, fs)
A.
B.
C.
D.
E.
May 1, 2008
4. Which of the following becomes much less efficient if the input vector is previously sorted?
A. Bubble sort
B. Insertion sort
C. Merge sort
D. Quick sort
E. Both C and D
A.
for vec
sum = sum + vec(i);
end
B.
for i = vec
sum = sum + vec(i);
end
C.
D.
for i = vec
sum = sum + i;
end
E.
for i = length(vec)
sum = sum+vec(i);
end
Page 2 of 11
May 1, 2008
9. How would you lower a note three half-steps in Matlab given the following code?
[a d] = wavread('c-note.wav');
b = length(a);
half=2^(1/12);
A. a(floor(linspace(1,b,b/(half^3))))
B. a(floor(linspace(1,b,b/(half/3))))
C. a(floor(linspace(1,b,b/(half*3))))
D. a(floor(linspace(1,b,b/half^(-3))))
E. a(floor(linspace(1,b,b*half*3)))
Page 3 of 11
May 1, 2008
11. Given:
vec = [5 9 6 3 6 8]
12. What is the difference between M and N where M = length(diff([5 4 3 2 1])) and
N = length(cumsum([5 4 3 2 1]))?
A. M = N
B. M > N
C. M < N
D. Their difference cannot be determined
E. None of the above
13. Given :
x = linspace(1,10,100)
y= x.^3
y1 = diff(y)./diff(x)
The command [a,b,c] = xlsread('test.xls'); is run in Matlab. What is the correct order
of a, b, and c in order of increasing number of elements (i.e. number of rows multiplied by
number of columns for each)?
A. c, b, a
B. a, b, c
C. a == b, c
D. b, c, a
E. a, b == c
Page 4 of 11
= [4 234 -5 8 4 23 5 -94]
=vec( vec<20)
= vec'
= abs(vec)
17. Given:
prof = struct('name','Cedric','classes',4);
Page 5 of 11
May 1, 2008
May 1, 2008
Which of the following lines of code will NOT produce an error in Matlab?
I. K*L;
II. inv(L);
III. L(20:30, 40:50) = [];
IV. M\K;
V. K(50,100) = L;
A. I and III
B. II, IV and V
C. IV and V
D. II only
E. IV only
19. Using what you know about your homework problem recursiveSum, recursion, and coding
in general, which of the following lines of code is incorrect?
1
2
3
4
5
6
A.
B.
C.
D.
E.
Line 1
Line 2
Line 3
Line 5
Everything is correct in the above code
20. Given:
cell = {'cool', 1:4, false}
cell{2} = [];
Page 6 of 11
May 1, 2008
The function is called using the test cases below. Please choose the correct outputs.
21. [A, B] = trfa('ta', 'TA')
A. A = 0; B = 0
B. A = 0; B = 1
D. A = 1; B = 1
E. Error
C. A = 1; B = 0
B. A = 0; B = 1
D. A = 1; B = 1
E. Error
C. A = 1; B = 0
B. A = 0; B = 1
D. A = 1; B = 1
E. Error
C. A = 1; B = 0
B. A = 0; B = 1
D. A = 1; B = 1
E. Error
C. A = 1; B = 0
B. A = 0; B = 1
D. A = 1; B = 1
E. Error
Page 7 of 11
C. A = 1; B = 0
May 1, 2008
B. [1 1 1 2]
C. [2 2 2 1]
D. [1 1 1 2 2]
B. cell
C. array
D. double
E. char
D. double
E. char
D. double
E. char
B. cell
C. array
B. cell
C. array
Page 8 of 11
E. [1 1 1 1 2]
May 1, 2008
size(mpoly);
1:r
zeros(1,length(x));
k = 1:c
y = y + mpoly(i,k)*x.^(c-k);
end
coeff(i,:) = polyfit(x,y,n);
newy(i,:) = polyval(coeff(i,:),x);
end
ret = newy;
31. What are the dimensions (rows by columns) of the output variable ret?
A. 1 x 41
B. 3 x 40
C. 40 x 3
D. 3 x 41
E. 41 x 3
32. The x and y data for which polynomial is passed into polyfit during the second iteration of
the outermost for loop?
A. 5x4 + 6x3 + x2 + 5x
B. 5x3 + 6x2 + x + 5
D. 4x2 + 2x + 5
E. 3x + 1
33. What is the order of the fitted polynomial during the second iteration of the outermost for
loop?
A. 1
B. 2
C. 3
D. 4
E. 5
34. What would happen if you were to replace line 5 with: y = [];
A.
B.
C.
D.
E.
Nothing would change. The function would produce the same results.
MATLAB would generate an error: Matrix dimensions must agree
MATLAB would generate an error: Index exceeds matrix dimensions
MATLAB would generate an error: Undefined function or variable y
The function would not cause an error, but it would produce different results.
35. What would happen if you were to replace line 6 with: for k = c:-1:1
A. Nothing would change. The function would produce the same results.
B. MATLAB would generate an error: Matrix dimensions must agree
C. MATLAB would generate an error: Index exceeds matrix dimensions
D. MATLAB would generate an error: Undefined function or variable y
E. The function would not cause an error, but it would produce different results.
Page 9 of 11
May 1, 2008
39. You are given a sound called 'sound.wav'. Determination the duration of the sound (how
many seconds it plays for) and store this is duration. Then, plot the amplitude of the sound
against time.
40. Write the code to plot the rotation the function f(x) = x2 around the x axis. The first few
lines have been done for you.
u = linspace(0, 5);
v = u.^2;
th = linspace(0, 2*pi);
[uu, tth] = meshgrid(u, th);
[vv, tth] = meshgrid(v, th);
41. Given a vector v, write code that creates the following items (no hard coding!):
- vecA, which contains all the elements of v which are less than 9
- vecB which is v in reverse order
- vecC, which contains only the elements of v which are at odd indices
- D, which is the average of the values in v
- vecE which is a vector of length 5 with random values between 5 and 7.
May 1, 2008
integ = cumtrapz(x,y);
fit = polyfit(x, integ, 2);
newInteg = polyval(fit, x);
plot(x, integ, x, newInteg)
Requirements:
- Correctly defines rr/xx/yy/zz (these count as 4 different requirements)
- Plots the surface using surf or mesh
- 2 points for each of the above requirements if completely correct
- 1 point if it is almost correct (i.e. student left out dot in the multiplication, etc.)
39. Suggested solution
vecA = v(v<9);
vecB = v(end:-1:1);
vecC = v(1:2:end);
D = mean(v);
vecE = 2*rand(1,5)+5;
- 2 points each for correctly defining vecA, vecB, vecC, D, and vecE
- 1 point if almost correct
Page 11 of 11