Cmpsc Midterm

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Consider the array A= [5 2 −3. 1]. Which of the following is not a valid approach for allocating this array in MATLAB? Make sure that your allocation has the same dimensionality as A. 1. A = [ 5; 2 -3; 1] 2. A = [ 5, 2, -3, 1] 3. A = [ 5 2 -3 1] 4. A = [5, 2; -3, 1]

1

multiple Which of the following are characters that require special formatting to be printed? 1. Percent sign: % 2. Single quotation mark: ' 3. Backslash: \ 4. Forward slash: /

1 2 3

multiple Which of the following are true about MATLAB variables? 1. May contain letters or numbers 2. May end with a letter 3. Must begin with a letter 4. May contain any special symbols, including those such as & or $

1 2 3

multiple which of the following are characteristics of computers? 1. Follow instructions precisely 2. Do not tire 3. Are reliable in most contexts 4. Are not good at performing logical comparisons

1 2 3

multiple In computer science, what are the main kinds of repetition structures? 1. while loop 2. for loop 3. repeat until loop 4. do while loop

1 2 4

multiple The key parts to every function are: 1. The inputs to the function, if applicable 2. The name of the function 3. Penn State Creamery Ice Cream 4. Comments that describe the other parts of the function 5. The outputs from the function, if applicable

1 2 4 5

multiple There are three primary steps for writing to a file with fprintf(). Which of the following are those steps? 1. Write to the file 2. Read the contents of the file 3. Close the file 4. Open the file, creating it if necessary

1 3 4

Match the following MATLAB command to its mathematical meaning 1. log(x) 2. log10(x) 3. ln(x) a. log base e of x b. not a valid MATLAB command c. log base 10 of x

1. a 2. c 3. b

Match the following concepts to their meanings: 1. Sequences 2. Selection Structures 3. Repetition Structures 4. Pseudocode 5. Flowchart a. Graphical representation of how code flows or progresses b. Lines of code are executed one after another c. Causes a group of statements to potentially be executed multiple times d. Nominally language-independent verbal description of computer code e. Enables one to have branches within their code

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

Match the following concepts or MATLAB commands to their definitions: 1. break 2. continue 3. Counter 4. Selection structures 5. Repetition structures a. Executes some piece of code if some known condition is true, otherwise executes some sort of alternative code (can be many branches) b. Used to skip the rest of the loop iteration, advancing to the next loop pass c. Used to cause the termination of the smallest enclosing for loop or while loop d. Causes a group of statements to be executed multiple times (either a fixed number, or until some stated condition is met) e. A variable that keeps track of some parameter of interest

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

Match the following concepts to their meaning: 1. Volatile memory 2. Non-volatile memory 3. Main Memory 4. Arithmetic and Logic Unit(ALU) a. stores programs and program data in random access memory b. performs mathematical operations c. temporary data storage d. permanent data storage

1. c 2. d 3. a 4. b

Match the following type fields to their meaning: 1. %f 2. %e 3. %i 4. %c 5. %s 6. %g a. Used for displaying just one character b. Used for displaying the shorter of fixed-point notation or exponential notation c. Fixed-point notation d. Integer notation e. Exponential notation f. Used for displaying a string of characters

1. c 2. e 3. d 4. a 5. f 6. b

Match the following MATLAB commands to their purpose: 1. input() 2. disp() 3. fprintf() 4. sprintf() 5. ginput() 6. dlmwrite() 7. num2str() a. Used for printing output to the screen, but does not generally have formatting capabilities b. Used to write delimited output c. Used for printing output to a text string, and generally has formatting capabilities d. Used to request input from the user e. Converts numbers to a character array f. Used for printing output to the screen or to a file, and generally has formatting capabilities g. Used to get data points from a plot

1. d 2. a 3. f 4. c 5. g 6. b 7. e

Match the following concept or built-in MATLAB function to its definition: 1. Mathematical function 2. Computer function 3. Pass by value 4. Pass by reference 5. nargin() 6. nargout() 7. type ___ 8. pathtool a. A piece of computer code that accepts an input argument from the user and provides output to the program b. Determines the number of input arguments c. Determines the number of output arguments d. A method for passing data to a function where a copy of the value of a variable of interest is sent to the function e. used to instruct MATLAB to search for a given function f. A mathematical relationship that maps an input to an output g. A method for passing data to a function where the memory address itself of a variable of interest is sent to the function h. Displays the contents of some files or functions

1. f 2. a 3. d 4. g 5. b 6. c 7. h 8. e

Match the following MATLAB commands to their purpose: 1. plot() 2. legend() 3. comet() 4. title() 5. figure() 6. clf 7. close 8. axis() 9. semilogx() 10. loglog() 11. plot3() 12. surf() a. Plots a 3D plot b. Clears the contents of a figure, but does not delete the figure window entirely c. Used to control the axes of a plot d. Creates a legend for a plot e. Adds a title to a plot f. Plots y-data points vs. x-data points g. Plots logarithm of y vs. logarithm of x h. plots a 3D surface plot i. Used to completely delete one or more figure windows j. Calls a figure, creating it if necessary k. Plots normal y vs. logarithm of x l. Creates an animated plot

1. f 2. d 3. l 4. e 5. j 6. b 7. i 8. c 9. k 10. g 11. a 12. h

Match the following MATLAB code snippets to their meaning: 1. < 2. <= 3. > 4. >= 5. == 6. ~= 7. & 8. | 9. ~ 10. xor() 11. && 12. || a. Not equal to b. Exclusive or c. Less than or equal to d. Or (used with scalars) e. And (used with vectors) f. Greater than g. Not h. Less than i. Equality check j. And (used with scalars) k. Greater than or equal to l. Or (used with vectors)

1. h 2. c 3. f 4. k 5. i 6. a 7. e 8. l 9. g 10. b 11. j 12. d

How many counters can be used within a single program? 1. It is impossible to determine this in advance 2. As many as the programmer would want or need 3. Only one 4. None

2

multiple Which of the following are characteristics of syntax errors? 1. Syntax errors are easy to miss, because MATLAB does not generally point them out to you 2. The code is written in such a way that MATLAB does not understand what it is being asked to do 3. Results in a red error message displaying in the Command Window 4. The computer understands the code, but the code does not do what you had intended for it to do

2 3

multiple Computer code can be categorized into which of the following categories? 1. Series 2. Repetition structures 3. Sequences 4. Selection structures

2 3 4

multiple Which of the following purposes can a counter be used for? 1. To keep track of the weather forecast 2. To keep track of "How much?" 3. To keep track of memory usage 4. To keep track of "How many?"

2 4

Which built-in command returns the largest number of elements in any dimension of a variable? 1. var() 2. numel() 3. length() 4. size()

3

Which built-in command would you use if you wanted to generate uniformly distributed pseudorandom numbers? 1. generate() 2. randn() 3. rand() 4. random()

3

What happens when you have a for loop inside of another for loop? 1. The inside for loop is the only loop that will execute 2. The outside for loop is fully executed before the second iteration of the inner for loop 3. The outside for loop is the only loop that will execute 4. The inside for loop is fully executed before the second iteration of the outer for loop

4

Which of the following is not true about plotting in MATLAB? 1. It can be used as a check to make sure that one's results look reasonable 2. It is a feature that distinguishes MATLAB from many, though not all, programming languages 3. The programmer has a large amount of control over the presentation of MATLAB plots 4. Plotting is not a useful feature in the MATLAB programming language

4

MATLAB generally interprets computer code line by line from the top to the bottom of a program. True or False

True

Consider the subplot command: subplot(m,n,p) In this expression, m represents _________________ for the entire figure , n represents _______________ for the entire figure , and p represents ____________________ a. The plot number from reading across the rows . b. The number of columns c. The number of rows

c b a

0 (zero) is the typical computer science representation for true, while 1 (one) is the typical computer science representation for false. true or false

false

An array cannot contain multiple pieces of information. true or false

false

Pass by value is not available in the MATLAB programming language, but pass by reference is.

false

Variables are global in scope by default; one must use a special technique to declare a variable to be local in scope.

false

When the MATLAB interpreter reports a warning it will also stop the execution of your code.

false

break and continue are "go-to" techniques that all programmers should readily use.

false

At the end of a for loop, the loop index variable keeps its most recent value.

true

In MATLAB, loops should not be your first choice programming technique if there are other reasonable alternatives.

true

In general, variables in MATLAB are either local or global in scope.

true

It is possible to have no inputs to a function, one input to a function, or multiple inputs to a function.

true

It is possible to have no outputs from a function, one output from a function, or multiple outputs from a function.

true

MATLAB array indexes must be positive integers.

true

MATLAB function files are .m files like scripts are.

true

Selection structures can be placed inside of repetition structures.

true

Switches can only check for equality, while if statements can check for equality or inequality.

true

The default angular unit in MATLAB is radians unless specified otherwise. true or false

true

The fact that a global variable is both visible and modifiable to all parts of a program is both an advantage and a disadvantage.

true

The input (or output) order must be consistent between a function and whatever calls it.

true

The input() command can be used to acquire numeric input from the user. The input() command can also be used to acquire character input from the user.

true

The semi-colon at the end of a line of code is generally an optional piece of syntax in the MATLAB programming language. true or false

true

There are sometimes multiple valid ways to solve the same programming tasks.

true

elseif (without a space) and else if (with a space) are generally not interchangeable.

true


Ensembles d'études connexes

Microtomy, hone & strop, floatation

View Set

Lesson 112 - Conductor Terminology, Switches, and Receptacles Homework

View Set