Docsity

7 Solved Problems on Computing for Engineers - Exam 1 | CS 1371, Exams of Computer Science

Partial preview of the text

Download 7 Solved Problems on Computing for Engineers - Exam 1 | CS 1371 and more Exams Computer Science in PDF only on Docsity!

Georgia Institute of Technology

College of Computing

CS 1371 Computing for Engineers

Test 1 Practice Test - Fall Semester 2006

Use this practice test and the book questions for chapters 3-8 for

practice.

Problem 1 – Short Answer

A) The two lines below are entered at the command prompt:

x = [ 9 3 0 6 3] y = mod((sqrt(length(((x+5).[1 2 3 4 5]))5)),3)

What is the value of y?

a) 0 b) 3 c) 2 d) 5

B) Consider the following vector in Matlab:

vec = [1 0 0 0 0];

Which of the following will produce an error?

a) vec(6) = 1; b) vec(4) = [ ]; c) vec(0) = 1; d) vec([4 5]) = 1; e) vec = [[6 [5] vec]];

C) If we define a vector A and we say:

B() = A()

where B did not exist beforehand.

What is true about range1 and range2?

A) They must be the same or you get an error B) range2 must be greater than range1 or you get an error C) range1 must be greater than range2 or you get an error D) They do not have to be same and B will be filled with zeros where assignments were not explicitly made.

F) Create a vector that starts at 4 and end at 286 and will have 1000 elements. Store your

answer in vec.

  • Find all the elements that are divisible by 3 with no remainder and store your answer

in a variable ind.

  • Remove every third element from vec.
  • Find the sum of vec and store it in sumVec.
  • Find the mean of vec and store it in meanVec.

Problem 2 - Iteration

Write a function called stat that takes in a vector of positive and negative numbers and returns four statistics about the data:

  • Average of all positive numbers
  • Maximum positive value
  • Minimum positive value
  • Standard Deviation of all positive numbers (formula given below)

You must use iteration to get any credit

stDev = sqrt((sum(data.^2)/length(data)) – mean)

Problem 4 – Cell Arrays

Write a function called sumCells that consumes a Cell Array containing vectors of varying lengths and a number, N. It returns the sum of all the vectors in the cell array of length N.

Example: sumCells( { [3 5 2], [ 2 5], [1 2], [ ], 42 } , 2 ) returns sum([2 5]) + sum([1 2]) = 10

Problem 5 – Multiple Choice

  1. Rewrite the following command using linspace:

a = 1 : (1/100) : 2;

  1. What are the values of variables 'ind' and ' x ' after executing the following code:

x = 1: for ind = x x = 1 end

a) x = 1:5, ind = 1: b) x = 1:5, ind = 5 c) x = 1, ind = 5 d) x = 1, ind = 1:

  1. Which of the following commands can be used to remove negative values from vector A = [ 9 -4 2 3 -6 -1] , so that the resulting vector is [9 2 3]

I) A(2)=[] A(5)=[] A(6)=[]

II) A([2 5 6]) = 0

III) A(6)=[] A(5)=[] A(2)=[]

IV) A(A<0)=[]

a) II only b) all of the above c) III and IV d) I and IV

  1. If B is any vector, then ~(~B) == B is always

a) an Error b) True d) False d) Cannot be determined.

Problem 7 – Cell Arrays

Write a script that will remove from a cell array, A , all the cells containing data of length 1. Append every cell removed from A to the end of a second cell array, B. Hint: strings respond to the length(…) function with the number of characters in the string.

For example, given the following cell array

A = { 1:10, 2:20, ‘c’, 1 , 2 , [ 6, 7 ] , 'cs1371' } B = { ‘original data’ } The final arrays should look like this:

A = { 1:10, 2:20, [6, 7], ‘cs1371’ } B = {‘original data’, ‘c’, 1, 2}