CS1371_2008_Spring_Questions_C by linzhengnd

VIEWS: 17 PAGES: 2

									   CS1371 - Computing for Engineers Final Exam Version C1                         April 29, 2008
Part 4 – Coding Problems [40 Points]

You must complete ALL of the following coding questions. Your code should not exceed 7
lines for any individual question. These are NOT functions. A function header is NOT
necessary. Please copy your answers to the given answer sheet.

38. Given vectors x and y of equal length containing x and y data values, please do the
following:
       - Compute the coefficients for a third order fit of the data and store in C
       - Create a new y vector called newy using this fit and the original x values
       - Compute the derivative of newy with respect to x and store in deriv
       - Plot the derivative versus the x values




39. 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.




40. You are given a sound of a piano playing a C-note – 'cNote.wav'. Write the lines of code to
lower this note 1 whole step, and store it in the variable bnote. (Hint: the factor for 1 half step is
2^(1/12).)




41. Write the code to plot the rotation the function f(x) = x + x2 around the z axis. The first few
lines have been done for you.
       u = linspace(0, 5);
       v = u + u.^2;
       th = linspace(0, 2*pi);
       [uu, tth] = meshgrid(u, th);
       [vv, tth] = meshgrid(v, th);



Part 4 Criteria (each worth 10 points, 40 points total)


                                            Page 1 of 2
   CS1371 - Computing for Engineers Final Exam Version C1                         April 29, 2008
38. Suggested solution:
C = polyfit(x,y,3);
newy = polyval(C, x);
deriv = diff(newy)./diff(x)
plot(x(2:end), deriv)

- 3 points each for correctly defining C/newy/finding derivative
- 1 point for plotting correctly
- 1 point if concept not completely correct (except for the plotting)

39. Suggested solution
vecA = v(v<9);
vecB = v(ebd:-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

40. Suggested solution:
[data, Fs] = wavread('cNote.wav');
N = length(data);
half = 2^(1/12);
bnote = data(round(linspace(1, N, N/(half^(-2)))));

- 2 points each for correctly reading in sound
- 4 points each for:
        - Attempting to stretch/shrink vector using linspace
        - Correctly changing pitch
- Half credit for each of above if not completely correct

40. Suggested solution:
rr = uu;
xx = rr.*sin(tth);
yy = rr.*cos(tth);
zz = vv;
surf(xx,yy,zz) or mesh(xx,yy,zz)

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.)




                                            Page 2 of 2

								
To top