Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CMPS 1371: Chapter 8 to Chapter 12 Review Questions, Assignments of Computer Science

Review questions for chapters 8 to 12 of the cmps 1371 course, covering topics such as matlab functions, structures, matrices, file i/o, and recursion.

Typology: Assignments

Pre 2010

Uploaded on 08/04/2009

koofers-user-t82
koofers-user-t82 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMPS 1371
Chapter 8 to Chapter 12 Review
1. True or False
a) xlswrite function always generates a new excel file on your desktop.
b) plot3 function draws lines by connecting points in 3-D.
c) titles and labels would show on the plot even though executed before
the plot command.
d) Nested for loops is one of the methods for iterating through a matrix.
e) The results of A * B and B * A are identical.
2. Which one of the following is NOT a valid structure assignment?
A. collection(3).message = 'hope you do well on this test'
B. collection = struct('firstName', 'Thomas', 'lastName', 'Crown')
C. collection[2].student = 'George P. Burdell'
D. collection(1).x = double('*')
E. None of the above, all are valid.
3. Which one of the following lines will produce an error in MATLAB?
A. double('hello') + 5
B. 'computer' > 'g'
C. double('I hate tests')
D. double('yes!') + [1:10]
E. 'donot' + 'cheat'
4. Given the following MATLAB command:
[x y z] = xlsread(excel_file)
What are the data types of x, y, and z?
A. x = double, y = double, z = cell array
B. x = double, y = character, z = cell array
C. x = double, y = cell array, z = cell array
D. x = cell array, y = cell array, z = cell array
E. None of the above
5. Given the following matrices:
A = [3 6 -1; 0 0 2; 9 0 4]
B = [5 7; 0 0; -3 -1]
C = [1 2 3; 4 5 6]
Which of the following commands would NOT result in an error?
I. [A B C]
II. [B A]
III. [A C]
IV. [C B]
A. II only
B. I, III, and IV
C. III only
D. All are correct
E. None of the above
pf3
pf4
pf5

Partial preview of the text

Download CMPS 1371: Chapter 8 to Chapter 12 Review Questions and more Assignments Computer Science in PDF only on Docsity!

CMPS 1371

Chapter 8 to Chapter 12 Review

  1. True or False a) xlswrite function always generates a new excel file on your desktop. b) plot3 function draws lines by connecting points in 3-D. c) titles and labels would show on the plot even though executed before the plot command. d) Nested for loops is one of the methods for iterating through a matrix. e) The results of A * B and B * A are identical.
  2. Which one of the following is NOT a valid structure assignment? A. collection(3).message = 'hope you do well on this test' B. collection = struct('firstName', 'Thomas', 'lastName', 'Crown') C. collection[2].student = 'George P. Burdell' D. collection(1).x = double('*') E. None of the above, all are valid.
  3. Which one of the following lines will produce an error in MATLAB? A. double('hello') + 5 B. 'computer' > 'g' C. double('I hate tests') D. double('yes!') + [1:10] E. 'donot' + 'cheat'
  4. Given the following MATLAB command: [x y z] = xlsread(excel_file) What are the data types of x, y, and z? A. x = double, y = double, z = cell array B. x = double, y = character, z = cell array C. x = double, y = cell array, z = cell array D. x = cell array, y = cell array, z = cell array E. None of the above
  5. Given the following matrices: A = [3 6 -1; 0 0 2; 9 0 4] B = [5 7; 0 0; -3 -1] C = [1 2 3; 4 5 6] Which of the following commands would NOT result in an error? I. [A B C] II. [B A] III. [A C] IV. [C B] A. II only B. I, III, and IV C. III only D. All are correct E. None of the above
  1. Which of the following are the essentials of Recursion? (Circle all that apply) A. There must be a terminating condition B. The function must call a clone of itself C. The function must return something D. The parameters in the recursive call should move towards the terminating condition.
  2. Circle one of the following that is NOT true about the function meshgrid, as in [xx yy] = meshgrid(x, y) A. meshgrid takes in two vectors and creates two arrays. B. The two input vectors for meshgrid must be of the same size. C. The two outputs from meshgrid will be the same size. D. meshgrid creates a plaid of the input variables
  3. What will be the value of x, when the following line of code is executed? group1 = struct('Name', 'Blue Bombers', 'City', 'Winnipeg') group2 = struct('Name', 'Raiders', 'City', 'Oakland') group3 = struct('Name', 'Thrashers', 'City', 'Atlanta') x = isfield(group1,'Winnipeg') A. ‘City’ B. 1 C. ‘Blue Bombers’ D. 0
  4. Which of the following blocks of code returns the values of x, y, and z from the system of equations listed below? 2x + 5y + 7z = 9 3x + 3z = 2 x + 3y + 2z = 5 A. A = [2, 5, 7; 3, 0, 3; 1, 3, 2]; B = [9; 2; 5]; inv(A) * B B. A = [2, 5, 7; 3, 0, 3; 1, 3, 2]; B = [9; 5; 2]; A .^ -1 * B C. A = [1, 3, 2; 3, 0, 3; 2, 5, 7]; B = [2; 9; 5]; inv(A) * B D. A = [3, 0, 3; 2, 5, 7; 1, 3, 2]; B = [2; 9; 5]; A .^ -1 * B

x = struct('first', 'jim', 'last', 'bob', 'age', 14); y = struct('first', 'mary', 'last', 'sue', 'age', 13); z = struct('first', 'billy', 'last', 'joe', 'age', 19); collection = [ x y z ]; temp1 = rmfield(x,'first'); temp2 = setField(y, 'Intelligence', 0); z.last = 'uhhh'; collection = collection(1:2); temp3 = collection(2).last; temp4 = isfield(y, 'first'); What is the output of the following variables when the script above is executed: temp1 = temp2 = temp3 = temp4 = Problem – Matrices

  1. Consider the following piece of code and then answer the questions that follow.

    A = [3 2 1; 6 5 4; 9 8 7]; B = [1 1 1; 0 0 0]; C = [A B']; D = ones(size(A)); B(1:2, 1:2) = A(3:end, 3:end); D(end, : ) = B(1, 1:3) + max(A) A(1:3, 3) = 0; What is the value of the following variables after the following script is executed: A = B = C = D = Problem – File I/O

  1. You have the following Microsoft Excel worksheet saved in a file called ‘Baby_score.xls’. The following lines of code are executed. What is the value of the variables when the following code is executed? [num txt raw] = xlsread('Baby_Score.xls'); vec = num(:,end); [numrows numcols] = size(num); [txtrows txtcols] = size(txt); [rawrows rawcols] = size(raw); varA = find(vec == max(vec)); varB = txt{numrows,2}; varC = ischar(txt); varD = raw{end,1}; varE = (txtrows == rawrows) && (numrows == txtrows); varF = (txtcols == rawcols) && (numcols == txtcols); varA = varB = varC = varD = varE = varF = Problem – Plotting
  2. Write the code to plot the 4th^ degree function on the interval [-4, 4] along with its first and second derivative: f ( x ) = x^4 – 1 a) Plot on the same axis with the first derivative in red and the second derivative in green. Provide a title, labels, and a legend. b) Plot the 3 graphs as subplots. Problem – Recursion

Answers:

  1. a) F b) T c) F d) T e) F
  2. C
  3. D
  4. B
  5. A
  6. A,B,D
  7. B
  8. D
  9. A
  10. A
  11. A
  12. B
  13. temp1 = last: ‘bob’ age: 14 temp2 = first: ‘mary’ last: ‘sue age: 13 Intelligence: 0 temp3 = sue temp4 = 1
  14.            9 8 0 6 5 0 3 2 0 A (^) , (^)        0 1 7 7 7 7 B (^) ,            9 8 7 1 0 6 5 4 1 0 3 2 1 1 0 C (^) ,            16 15 8 1 1 1 1 1 1 D
  15. varA = 9 varB = Ian varC = 0 varD = 10 varE = 0 varF = 1
  16. a) x = -4:0.1:4; y = x.^4 – 1; y1 = 4 * x.^3; y2 = 12 * x.^2; plot (x, y, x, y1, ‘r’, x, y2, ‘g’) title (‘Graph with its derivatives) xlabel (‘x axis’), ylabel (‘y axis’) legend (‘y = x^{4} – 1’,’1st^ derivative’,’2nd^ derivative’) b) subplot (3, 1, 1) plot (x, y), title (‘y = x^{4} – 1’) subplot (3, 1, 2) plot (x, y1), title (‘1st^ derivative’) subplot (3, 1, 3) plot (x, y2), title (‘2nd^ derivative’)
  17. 10
  18. function result = myEvens(x) % returns positive even numbers if size(x) < 1 result = []; elseif (x(1) > 0 && mod(x(1),2)==0) result = [x(1), myEvens(x(2:end))]; else result = myEvens(x(2:end); end