COMPSCI 200 Final Exam (Past Midterm Questions), compsci final

Ace your homework & exams now with Quizwiz!

Fall 15 exam 2

.

exam 2

.

spring 16 exam 1

.

Consider the following code fragment: k= 0; while k^0.5<k k = k + 1; end What will be the value of k at the end of a run of this code? a. 1 b. 2 c. 0 d. 4

0

What will be the value of y after a run of this code fragment? z = 4; x = 3; y = z == x a. 0 b. 1 c. 4 d. Nothing; due to (a) syntax error(s), this code fragment will fail to fully execute

0 not true

Consider the following code fragment: w = [1 5 4 3] x = find(w<=3) What will be the value of x at the end of a run of this code? a. x=[1 3] b. x = [] c. x=[1 4] d. x will not have a value due to (a) syntax error(s)

1 5 4 3 1 4 3 over (counting from left to right)

How large is a logical variable?

1 bit

How large is a logical variable? a. 1 byte b. 2 bits c. 2 bytes d. 1 bit

1 bit

what would be the anticipated output from this command sum((1:3).*(3:-1:1)

10 second one means from 3 to one in incriments of -1 so 3 2 1 123 * 321

How much memory would be required to store a dense 50 x 50 matrix of single precision floating point numbers? a. 10 MB b. 20 KB c. 20 MB d. 10 KB

10 KB

How much memory would be required to store a dense 50 x 50 matrix of single precision floating point numbers?

10 KB (4 per character)

Consider the following code fragment. What would be the scalar value of S? S = 0; for ii = 1:1:13 S = S + 1 end

13

Consider the following code fragment: c = [1 2 3; 5 4 ... 1; 1 0 2] d = c(4) What will be the value of d after a run of this code fragment? a. 2 b. 1 c. 5 d. d would not have a value because of (a) syntax error(s)

2

consider the following code fragment: x=exp(0) x=x+1 value of x

2

What result would you anticipate after running the command. . .nargin('nthroot') and nargout

2, 1

what will be stored in the variable x as a result of this code fragment x=10*rand(2,100)-5 a. 200 uniformly distributed pseudorandom numbers between 0 and 10 b. 200 Gaussian ("normal") pseudorandom numbers with a mean of -5 and a variance of 10 c. 200 uniformly distributed pseudorandom numbers between -5 and +5 d. 200 Gaussian ("normal") pseudorandom numbers between -5 and +5

200 uniformly distributed pseudorandom numbers between -5 and +5

Consider the following code fragment: x = [1 3 6]; j = 0; for i = 1:5 while j < 3 for k = x % Nothing end if j/3 == 0 j= j + 2; else j = j + 1; end end end What will be the value of j at the end of this code fragment?

3

What is a a variable name that is NOT valid in MATLAB?

38special *must start with a letter*

Which of the following is NOT a valid variable name in MATLAB? a. 3rdEyeBlind b. Maroon5 c. Thirty_Seconds_to_Mars d. Matchbox20

3rdeyeblind must start with a letter

Consider the following code fragment: y = ones(1); while (y ~= 3 || y < 2) && y <= 5 y = y +2; end What will be the value of y at the end of a run of this code? a. 7 b. 4 c. 6 d. 3

4

Consider the following code fragment: a = [2 5 4 1] b = [3.7 10.4 1.8 2.7] c = a(find(b<3)) What would be stored in the variable c after a run of this code fragment? a. c=[4 1] b. c=[2 5] c. c=[3 4] d. c = [1.8 2.7]

4 1

What numeric value would be produced by this calculation in MATLAB? 5-2/4^2

4.875

How much memory would be required to store a dense 100 x 100 matrix of single precision floating point numbers? a. 80 kilobytes (KB) b. 40 megabytes (MB) c. 80 megabytes (MB) d. 40 kilobytes (KB)

40 kilobytes

Consider the following code fragment: k = 1; for i = 1:2 for j = 3:5 k=k+1 end end What will be the value of k at the end of a run of this code? is code vectorization? a. 6 b. 3 c. 7 d. 2

7

for i=1:5 for j=i:5 C(i,j) = i + j; C(j,i)= C(i,j); end end D = C(4, 3) What will be the value of D at the end of a run of this code fragment? a. 8 b. 6 c. 11 d. 7

7

What numeric value would be produced by this calculation in MATLAB? 3^2+4/6 a. 121.5000 b. 18.7208 c. 9.6667

9.6667 9+ 2/3

In MATLAB, which relational operator can be used to check if two variables are equal to each other?

= =

Consider the following code fragment: j = 0; x = 0; y = 5; for i = 1:3 while j < 6 j = j + 2; x = x + i + j; y = y - 1; end end What will be the value of x at the end of a run of this code fragment? a. 15 b. 24 c. 6 d. 3

A

What important consideration do you have to make when you want to study code execution times? a. Due to variances in other processes controlled by the OS, it is a good idea to run your code multiple times to get a true indication of its performance b. Code runs are static in nature; while they do change from machine to machine, they should be identically consistent on any one machine c. Most computer languages are converted to machine language that has similar execution times d. The best measure of wall time is to measure the amount of time each CPU spent on a given task, and then sum those times together

A

What is the role of continue? a. To skip the rest of the current loop iteration, advancing to the next loop pass b. To force MATLAB to not rest between loop iterations c. To give MATLAB an opportunity to rest between loop iterations d. To cause the termination of the smallest enclosing loop

A

What is the role of continue? a. To skip the rest of the current loop iteration, advancing to the next loop pass b. To force MATLAB to not rest between loop iterations c. To give MATLAB an opportunity to rest between loop iterations d. To cause the termination of the smallest enclosing loop

A

a = 4 b = 5 c = (a+B)^0.5 What will the result be in MATLAB? a. There is a syntax error in the code, so the code will not run without error b. 3 c. 1 d. 4.2361 (the numeric result of 4 + 5)

A

consider the code fragment: y = ones(1); while (y ~= 3 || y > 2) || y <= 8 y=y+3 end What will be the value of y at the end of a run of this code fragment? a. Impossible to determine, since this code fragment will result in an infinite loop b. 10 c. 11 d. 9

A

The programmer wants to print a single character (a letter) with the fprintf command, the neccessary type field would be

%c

if a person wants to print an entire character string using the fprintf command, the necessary type field would be %s %c %d %i

%s

What result would you anticipate after running the command nargout('size')? a. ans = 1 b. ans = -1 c. ans = 2 d. ans = 0

-1

if one were to excecute the below code fragment what would b contain a=linspace(0,pi,10) b=cos(a(10)) -1, 0, or 1

-1 in incriments of pi, 10 would be the full value of pi breaks pi up into ten incriments

Which is an example of a computer input device?

A key board *not a screen, printer, or CPU*

What is a characteristic of pseudocode? It is a verbal description of the computer code. It is a graphical representation of how computer code flows or progresses, and are constructed with well-defined conventions. It is an intermediate step between everyday language and a programming language. None of the above.

A or C ???

What is a program?

A set of precise instructions tom perform specific tasks

What value of y would be produced from a run of this code fragment? A = [1 5 4; 5 7 4; 9 6 2]; B = transpose([1 4 5]); A(:,4) = B; [x,y] = size(A) a. 3 b. 4 c. y would not have a value d. NaN

A(:,4)=B keeps the 3 rows, adds a fourth column, which equals B size is 3,4 3

what is code vectorization a. A programming technique that uses vector operations instead of element-by- element loop-based operations. b. A programming technique that uses elements stored in vectors instead of multiple scalar variables. c. A programming technique that uses element-by-element loop-based operations instead of vector operations. d. A programming technique that uses multiple scalar vectors instead of elements stored in vectors.

A. aprogramming technique that uses vector operations instead of element-by- element loop-based operations

Chars in MATLAB are represented by what value in memory? You may assume that this question refers to an installation of MATLAB on a personal computer(PC).

ASCII value

.Which of the following is an example of volatile memory? a. ROM b. RAM c. Floppy disks d. Magnetic tape

B

Generally, when is a good time to use a while loop instead of a for loop? a. You should always use a for loop; you can always break out of the loop when you are ready for the loop to terminate. b. When you can only know a posteriori ("after the fact") how many times the loop will need to execute. c. Use should always use a while loop; you can always use a counter to keep track of how many times the loop will have to run. d. When you know or can calculate a priori ("before the fact") how many times the loop will need to execute.

B

If the only input to the orderfields command is a structure array, what would be anticipated behavior of the output array? a. The structure array's fields would be placed in the order of their creation b. The structure array's fields would be placed in ASCII or EBCDIC dictionary order, as appropriate to a particular computer system c. The structure array's fields would be placed in (English) alphabetical order d. It is not deterministic (i.e. there is normally no way to determine this)

B

What is the advantage of short circuit evaluation? a. When checking the logic you must evaluate all the terms b. When checking the logic you don't evaluate the other terms(s) if you find you do not need to do so c. There is no advantage to short circuiting; it is merely a style preference d. There is no advantage to short circuiting; it forces MATLAB to evaluate the logic instead of permitting it to cut corners

B

What is the role of a sentinel value? a. To keep track of - or count of - an event or occurrence b. To keep watch for a specific occurrence so that a loop can be terminated c. To act as a special indicator for the start of a while loop d. To teach children how to count

B

When it is available in a particular language, when is a good time to use a do while loop? a. If you know a priori ("before the fact") how many times the loop will need to execute b. When you can only know a posteriori ("after the fact") how many times the loop will need to execute, but you know the loop will need to run at least once c. When you do not know a priori ("before the fact") how many times the loop will need to execute, but you have a way of calculating the required number of iterations d. When you can only know a posteriori ("after the fact") how many times the loop will need to execute, and you do not know if the loop will even need to run at all

B

Which command will delete (i.e. completely remove) the last cell of a cell-array C? a. C[end] = []; b. C{end} = []; c. C(end) = []; d. C{end} = {[]};

B

Which of the following is a valid for loop index? a. Cell array b. Scalar c. Structure array d. Multidimensional array

B

You have a system of simultaneous linear equations. You know that once put into the matrix form 𝐴𝑥 = 𝑏 that 𝐴 is square and non-invertible. Generally speaking, from a computational point of view, which is the best approach to solving this system? a. Using the \ operator b. Such a system has no exact solution c. Using the / operator d. Using the matrix inverse

B

Presume that a programmer has entered the following commands into MATLAB: x = [1 3 5 645 9 3 5] y = prod(x) What would be stored in the variable y? a. y=15 120 135 b.y=54 36 125

B. Multiply each number in the collumn

Chars in MATLAB are represented by what value in memory? You may assume that this question refers to an installation of MATLAB on a personal computer (PC). a. EBCDIC value b. Hexadecimal value c. ASCII value d. Decimal value

C

The magnitude of a vector can be calculated via the built-in function a. abs() b. absolute() c. norm() d. length()

C

What is an issue with trying to time computer code runs? a. Run times can vary from run to run, especially if other tasks are competing for time on the processor. b. The operating system (OS) can make adjustments to the system clock, so using the system clock for timing presents difficulties. c. Both A and B are correct. d. None of the above.

C

What is the role of break? a. To skip the rest of the current loop iteration, advancing to the next loop pass b. To force MATLAB to not rest between loop iterations c. To cause the termination of the smallest enclosing loop d. To give MATLAB an opportunity to rest between loop iterations

C

What will be the value of counter at the end of a run of this code fragment? counter = 0 for k = 1:10 if k < 2 && k > 5 counter = counter + 1; end end a. There is (a) syntax error(s), so the code fragment will not run to completion b. counter = 5 c. counter = 0 d. counter = 1

C

Which of the following is true of MATLAB switches? a. Switches can be used any time if statements are used b. Switches have faster evaluation times than if statements c. MATLAB switches will stop checking cases once a true case is discovered d. MATLAB switches check all of the cases, even if a true case is already discovered

C

You have two square 2 x 2 matrices A and B. You want to manipulate the matrices so that it has the practical effect of x = [A, B]. Which of these commands would result in the variable y having the same value as x? a. y = vertcat(A,B) b. y = cat(A,B) c. y = horzcat(A,B) d. Both a) and c) would work

C

You know that a matrix 𝑀 is square and - from a numerical point of view - could be considered to be singular. What will occur if you try to perform the operation 𝑀'(𝑀? a. The calculated result will be equal to the identity matrix. b. MATLAB will realize that 𝑀 cannot be inverted, and will issue an error instead of performing the requested calculation. c. It would be hard to know a priori the calculated result, though it will be nothing desired and the result will be wrong. d. The calculated result will be equal to a matrix of zeros.

C

A vector q exists. Which of the following is NOT a command that could reasonably be used to count the number of elements in f? a. size(q) b. length(q) c. numel(q) d. sort(q)

D

In MATLAB, which relational operator can be used to check if two variables are not equal to each other? a. != b. <> c. == d. ~=

D

Picture a figure containing 24 subplots, arranged as if they had 4 rows and 6 columns. Which subplot command is associated with operations for the plot in the third row, second column? a. subplot(2,3,14) b. subplot(3,2,7) c. subplot(2,3,7) d. subplot(3,2,14)

D

What is the role of a counter? a. To keep watch for a specific occurrence so that a loop can be terminated b. To act as a special indicator for the start of a while loop c. To teach children how to count d. To keep track of - or count of - an event or occurrence

D

Which consideration is important when selecting a programming language to use to solve a science or engineering problem? a. Hardware constraints b. Safety c. Control over various aspects of the memory d. All of the above

D

while working with programmer defined functions, which of the following is not true a. The function file must be in the folder that MATLAB has open. b. The name of the function in the function call must match the function file's name. c. In MATLAB, programmer-defined functions can either be anonymous functions or they can be separate MATLAB files. d. The function should never call another function.

D

x = 2; while x < 13 fprintf('We are the music makers, ') fprintf('and we are the dreamers of dreams.\n') x = x + 1.6; end How many lines of output will display in the Command Window? a. 8 b. 16 c. 14 d. 7

D

An exclusive or always evaluates to true when either A or B are non-zero

False

Doubles have the same memory storage requirements as complex numbers

False

Every else needs an if, and every elseif needs an else

False

The default case in a switch is denoted with an else or an otherwise; one can use either of these interchangeably

False

The symbol \\ is reserved in MATLAB to indicate a multi-line(or block) comment

False(%%)

Most of the built-in functions in MATLAB are row dominant

False(column dominant)

One can use the reserved word "last" to identify the final row or column in a matrix if they do not know how big the matrix is. An example use is B = A(1,last)

False(end)

Assuming x is a numeric array and that n is a scalar number, the commands x.^n and nthroot (x,n) will produce the same result

False(nthroot=sqrt(n)[x]

Algorithms can implement programs

False(only programs implement algorithms)

The default unit set for angles in MATLAB is degrees

False(radians)

What does the command sprintf do?

It enables the programmer to store a character string as a variable

What is a characteristic of pseudocode?

It is a verbal description of the code AND it is an intermediate step between everyday language and programming language

What is the role of a semicolon when it appears at the end of a line of MATLAB code?

Its presence causes MATLAB to suppress the automatic printing of the result of the line to the Command Window

Which of the following is true of MATLAB switches?

MATLAB switches will stop checking cases once a true case is discovered

what happens if the result of a calculation is too big for matlab to store The number will wrap-around, restarting from the most negative number possible in memory. MATLAB will return an error message MATLAB will report the result as +inf or -inf, as appropriate MATLAB will freeze while attempting to perform the calculation

MATLAB will report the result as +inf or -inf, as appropriate

Why should someone consider using a programmer-defined function?

Maintainability and Convenience

What is the fundamental data construction in MATLAB?

Matrix

What does MATLAB stand for?

Matrix Laboratory

A dense matrix is a matrix where:

Most of the elements are nonzero

What is the distinction between non-volatile and volatile memory? nonvolitile memory is temporary storage while volatile memory is permenat volitale memoriy is slower than nonvolitile volitile memory is temporary while nonvolitile is perminate

Non-volatile is permanent storage, while volatile is temporary storage

What is a guiding principle for improving code performance in MATLAB?

Only print using print statements when you want something to be printed to the Command Window

Which of these are NOT an example of non-volatile memory?

Random Access Memory (RAM) *CDs, ROM, Magnetic Tape all ARE examples*

Which of the following is a valid for loop index?

Scalar *not cell array, structure array, or multidimensional array*

what is an operating system

Something that allocates computer resources, and allows communication between the user and the computer

What is the first step in the software development process?

Specifying what the program needs to do

You have a system of simultaneous linear equations. You know that once put into the matrix form AX = b that A is square and non-invertible. What is the best approach to solving this system?

Such a system has no exact solution

When working with programmer-defined functions, which of the following is NOT true?

The function should never call another funciton

If the only input to the orderfields command is a structure array, what would be the anticipated behavior of the output array?

The structure arrays fields would be placed in ASCII or EBCDIC dictionary order, ass appropriate to a particular computer system

Consider the following code fragment: a = 4 b = 5 c = (a+B)^0.5 What will be the result?

There is a syntax error in the code, it will not run

What is the role of break?

To cause termination of the smallest enclosing loop

What is the role of a counter?

To keep track of (or count of) an event or occurance

What is the role of a sentinel value?

To keep watch for a specific occurance so that a loop can be terminated

What bis the role of "continue"?

To skip the rest of the current loop iteration, advancing to the next loop pass

1 is the binary representation for true, while 0 is the binary representation for false

True

Computers follow instructions precisely. The difficult part for the programmer is being able to write precise instructions.

True

Errors will print red text to the Command Window and will stop the execution of your code; warnings will merely print orange to the Command Window

True

Examples of data types in MATLAB include doubles, singles, chars, and symbols

True

In general, for performance reasons it is generally preferable to use built-in functions such as the find command instead of using loops in MATLAB

True

In the MATLAB programming language, it is generally more computationally efficient to use a built-in function than it is to write your code to accomplish the task

True

MATLAB, like most programming languages, is case sensative

True

Matrix Multiplication is associative with any square matrix

True

One feature that distinguishes MATLAB from many other programming languages is the ease of matrix operations built into the language itself

True

T or F . In general, for performance reasons it is generally preferable to use built-in functions such as the find command (when practical to use) instead of using loops in MATLAB.

True

T or F many of the built in functions in MATLAB implement an element by element operation procedure

True

What would be the result of this expression? TRUE && (FALSE||TRUE)

True

When it is available in a particular language, when is it a good time to use a do while loop?

When you can only know a posteriori how many times the loop will need to execute, but you know the loop will need to run at least once.

Which of the following is a "guiding principle" for improving code performance in MA TLAB? a. Only print using print statements when you want something to be printed to the Command Window. b. Do not use MATLAB if you want or need fast code. c. Generally, there are not a lot of "guiding principles;" when it converts the code to machine language, MATLAB is generally able to speed up your code regardless of approach or technique the programmer used. d. Do not pre-allocate space for very large variables because it forces MATLAB to visit the same memory location twice (once when you reserve the space, and once again when you update the value in memory).

a

what is a program

a set of precise intructions to perform specific tasks

A sentinel loop will terminate when: a. A certain condition is met (the sentinel condition) b. When a fixed number of iterations (the sentinel iterations) are executed c. Only when the computer runs out of memory. d. N/A - sentinel loops are by design infinite loops

a. A certain condition is met (the sentinel condition)

the CPU has two components, and they are a. Arithmetic and logic unit; control unit b. Algebraic and logic unit; control unit c. Arithmetic and logic unit; random-access memory d. Control unit; random-access memory

a. Arithmetic and logic unit; control unit

Which of the following comprises a valid MATLAB for loop index? a. A scalar b. A vector c. A matrix d. All of the above

all of the above

c = (1:3)'; d = c(1,2)' What will be displayed in the Command Window after this code runs? a. 1 b. 2 c. 1 2 d. An error message

an error message

What result would you anticipate after running the command. . .nargout('size')

ans = -1

Assuming MATLAB's typical decimal point behavior, what will result from the operation 1+(eps-0.1) appear as in the Command Window?

ans = 0.9000

What is a characteristic of a flowchart? a. It is a verbal description of computer code. b. It is a graphical representation of how computer code flows or progresses, and it is constructed with well-defined conventions. c. It is an intermediate step between everyday language and a programming language. d. None of the above.

b

a = 2 sin = a./4 sigma = sin(a) This code fragment will not run. What is the problem with this code fragment? a. There is a syntax error; ./ requires you to have a matrix or a vector for the operator to be valid b. It is not possible to access the second element of the variable sin c. There is a syntax error; scalar inputs require / instead of ./ d. MATLAB got confused and did not know what to

b

You have a system of simultaneous linear equations, with exactly as many linearly independent equations as you have unknowns. Once you place the system into the matrix form 𝐴𝑥 = 𝑏, you observe that 𝐴 is invertible. Generally speaking, from a computational point of view, which is the best approach to solving the linear system for 𝑥? a. Using the / operator b. Using the \ operator c. Using the matrix inverse d. Guessing and checking

b. Using the \ operator

What statement will print as a result of a run of this code fragment? x = [4 3]; if x == 3 disp('Pikachu') elseif x == 4 disp('Squirtle') elseif x <= 3 disp('Charmander') else disp('Bulbasaur') end Pikachu Squirtle Bulbasaur Charmander

bulbosar

Consider the matrix 𝐴 = 3 1 , 1 2 which is stored in MATLAB as the variable What would the calculation B = A*A result in? a. B = 9 1 14 b. B = 1 0 0 1 c. B=10 5 5 5 d. B would be none of these choices

c

For large, long-term software systems, the most expensive phase of software development is in a. Specifying what the program needs to do b. Testing the program c. Maintaining the code d. Developing the algorithm(s) to solve your problem

c

In MATLAB, which relational operator can be used to check if two variables are equal to each other? a. != b. = c. == d. ~=

c

Which of these units of information can store exactly 1 logical variable? a. byte b. kilobyte c. bit d. kilobit

c

Why should someone consider using a programmer-defined function? a. Maintainability b. Convenience c. Both A and B are correct d. None of the above are correct

c

pi = @(x) pi + 1 z = pi*5 What is the value of z at the end of a run of this code fragment? a. 20.7080, which equals 5(pi + 1 b. 15.7080, which equals 5pi c. This code fragment will not run, so it is impossible to know what z would be d. 10.7080, which equals 5(pi − 1)

c

Consider the code fragment: a = [2 5 4 1] b = [3.7 10.7 1.8 2.7] c = a(find(b<3))

c = [4 1]

Which command rounds an arbitrary variable x to the nearest integer towards (+)infinity? floor ceil fix round

ceil(y)

6. What statement will print from the following code fragment? x = [2 1]; if x == 2 disp('Bulbasaur') elseif x == 1 disp('Pikachu') elseif x >= 2 disp('Squirtle') else disp('Charmander') end a. Charmander b. Bulbasaur c. Pikachu d. Squirtle

charmander

What will be stored in my_entree at the end of a run of this code fragment? entrees = {'Sole' 'Chicken' 'Beef'} my_entree = entrees{2} a. C b. o c. Nothing; due to (a) syntax error(s), this code fragment will not fully execute d. Chicken

chicken

Which command clears the Command Window?

clc

which of these is a trait of compiled languages code written by the programmer is saved in the same format it was origoally used in generally slower than interpreted languages harder to write code for interpreted languages than compiled languages code written by the programmer is reduced to a set of machine specific functions prior to runtime

code written by the programmer is reduced to a set of machine specific functions prior to runtime

Consider the following code fragment: x = e(1) x = x + 1 What is the value of x at the end of a run of this code fragment? NOTE: In the answer choices for this question, e represents Euler's number. a. 3.7183, which equals e + 1 b. 2.7183, which equals e c. The answer is another choice not listed here d. There is a syntax error, so this code will not fully execute

d

in languages that support the do while loop, what distinguishes it from the while loop? a. The do while loop is a pre-test loop b. The do while loop is guaranteed to run at least once c. Both A and B are correct d. None of the above

do while is gaurunteed to run at least once

Assuming MATLAB's typical decimal point display behavior, what will result from the operation 1+(eps-0.1) appear as in the Command Window? a. An error message; eps was not previously defined b. ans = 0.8999 c. This is impossible to determine with the provided information d. ans = 0.9000

eps is the smallest number possible eps-1 =-1 eps+1=1 eps-.1 = -.1 1+ (-.1) =.9

An 'exclusive or' evaluates as false when either inputs A or B (but not both) are non-zero. a. True b. False

false

T or F Every if needs an else, but not every else needs an elseif

false

T or F If MATLAB finds a true case in a switch, it will continue checking the other cases.

false

T or F In MATLAB, what would be result of this expression? FALSE || (TRUE&&FALSE)

false

T or F Matrix multiplication is commutative for any square matrix.

false

T or F 0 in binary is true, 1 is false

false

T or F An exclusive or always evaluates to true when either input A or B is non-zero.

false

T or F Assuming x is a numeric array and that n is a scalar number, the commands x.^n and nthroot(x,n) will produce the same result.

false

T or F Every else needs an if, and every elseif needs an else.

false

T or F The default case in a switch is denoted with an else or an otherwise; one can use either of these interchangeably.

false

T or F The symbol \\ is reserved in MATLAB to indicate a multi-line (or block) comment.

false

T or F a matrix ix invertible if its determinant is not equal to one

false

T or F command window code and script code do not share the same workspace

false

T or F even if the "niceties" are observed (ex files saved in correct folder, etc.) a function can never call another function

false

T or F Doubles have the same memory storage requirements as complex numbers.

false

T or F algorithms can implement programs

false

T or F The default unit set for angles in MATLAB is degrees.

false - radians

T or F Most of the built-in functions in MATLAB are row-dominant.

false- collumn

T or F One can use the reserved word last to identify the final row or column in a matrix if they do not know how big the matrix is. An example use is B = A(1,last).

final - end

Which command rounds an arbitrary variable x to the nearest integer towards −∞? a. ceil(x) b. floor(x) c. fix(x) d. round(x)

floor

Consider the case where the programmer wants MATLAB to output all numbers with exactly two decimal places. The command needed to accomplish this is:

format bank

consider the case where the programmer wants MATLAB to output all numbers with exactly two decimal places. the command is format long eng b. format short c. format short E d. format bank

format bank

presume a person wants to output all numbers in a fractional form. the command needed is format bank format short eng format long format rat

format rat

Which of the following is a valid function header in MATLAB function y, z=f[x] function=f(x) y, z y,z=f(x) function [y,z]=f(x)

function [y,z] = f(x)

a = 3; b = 4; switch a case 1 if b > 2 c = 'Red Hot Chili Peppers'; else c = 'Lifehouse'; end otherwise if b > 2 c = 'Green Day'; else c = 'The Eagles'; end end What will be the value of c at the end of a run of this code

green day

What order does MATLAB store field names for structure arrays? a. ASCII dictionary order b. In order of creation c. Alphabetical order d. It is not deterministic (i.e. there is normally no way to determine

in order of creation

what is the role of a semilcolin when it does not appear at the end of sa line its absence causes matlab to suppress the output from the command window it is a required part of matlab syntax, incorrect without it its absecnece causes matlab to print the result of the line to the command window none of the above

its absecnece causes matlab to print the result of the line to the command window

consider the following code fragment: A = 2; for k = 0:2:4 A = [A, A*k]; end B=A What will be the value of B at the end of a run of this code fragment? a. B = 2,0,0,0 b. B=204080160 c. B = 220 200 2000 d. B=2248

k = [0 2 4] 2x2 matrix, 2 from A and the matrix multiplied by scalar multiplier 2 B

which command is used to calculate log base e

log(X)

Which command is used to calculate log base e, also known as ln(x)?

log(x)

what command is used to calculate log base 10 a. ln(x) is an operating system? b. log10(x) c. log(x) d. log(x,10)

log10(x)

Consider the following code fragment: m = (1:4)' n = m(2,1) What value of n will be displayed in the Command Window after this code runs? a. n = 1 b. n = 2 c. n = 1 2 d. An error message

m=1 2 3 4 m'= 1 2 3 4 m(2,1)= 2nd row first collumn n=2

A dense matrix is a matrix where: a. Non-zero elements are confined to a diagonal band comprising the main diagonal, and it can have zeroes or more diagonals on either or both sides of the main diagonal b. Most of the elements are zero c. Most of the elements are non-zero d. The elements are zeroes below the diagonal, and non-zero above the diagonal

most of the elements are nonzero

A sparse matrix is a matrix where: a. The elements are zeros below the diagonal, and non-zero above the diagonal. b. Non-zero elements are confined to a diagonal band comprising the main diagonal, and it can have zeros or more diagonals on either side of the main diagonal. c. Most of the elements are zero. d. Most of the elements are non-zero.

most of the elements are zero

Consider the code fragment: m = (1:4)' n = m(2,1) What value will be displayed in the command window?

n = 2

nargin and nargout

nargin and nargout are the inputs and outputs of a function. only used in function defining

The magnitude of a vector can be calculated via the built-in funciton

norm( )

In terms of amounts of required storage, how do these data types compare? a. single < complex number consisting of singles < double b. single < double < complex number consisting of singles c. double < complex number consisting of singles = single d. single < complex number consisting of singles = double

single < complex single=double

which of these is a built in function in MATLAB NaN Pi Size j

size

A vector q exists. Which of the following is NOT a command that could reasonably be used to count the number of elements in q?

sort (q)

Picture a figure containing 18 subplots, arranged as if they had 3 rows and 6 columns. Which subplot command is associated with operations for the plot in the 2nd row, 4th column?

subplot(3,6,10)

Picture a figure containing 24 subplots, arranged as if they had 4 rows and 6 columns. Which subplot command is associated with operations for the plot in the third row, second column?

subplot(4,6,14)

If you want to know how much wall time has elapsed for a code to run, which technique would be the best approach? a. Tic and toc b. cputime c. clock and etime d. Verbally counting "1 Mississippi, 2 Mississippi, ..." and hoping for the best

tic and toc

T or F 1 is the binary representation for true, while 0 is the binary representation for false.

true

T or F Computers follow instructions precisely. The difficult part for the programmer is being able to write precise instructions.

true

T or F Examples of data types in MATLAB include doubles, singles, chars, and symbols.

true

T or F For personal computers (PCs) or laptops, chars in MATLAB are represented by their ASCII value when stored in memory.

true

T or F In MATLAB, what would be the result of this expression? TRUE&&(FALSE||TRUE)

true

T or F In the MATLAB programming language, it is generally more computationally efficient to use a built-in function than it is to write your code to accomplish the same task.

true

T or F Matrix multiplication is associative for any square matrix.

true

T or F One feature that distinguishes MATLAB from many other programming languages is the ease of use of matrix operations built into the language itself.

true

T or F The ' operator and the transpose command both compute transposes, but these two techniques do not behave identically under all circumstances.

true

T or F The default numeric data type in MATLAB is the double

true

T or F some built-in functions may behave differently based on how many inputs are given to the function

true

T or F the %% symbol is reserved in matlab to indicate a comment

true

T or F the rule in creating a matrix or array is that all the rows must have the same number of elements (which implies each collumn has same number of rows)

true

T or F two arrays should be the same size for one to be able to add or subtract them

true

T or F In general, for performance reasons it is preferable to use built-in MATLAB features such as the find command (when practical) instead of using MATLAB loops.

true

T or F each function has its own workspace

true

T or F MATLAB is case sensitive

true

Generally, sections of computer code can be categorized into three separate categories. Which of the following is NOT one of those categories? a. Sequences b. Selection structures c. Repetition structures d. V ectorized

vectorized

In the main script of a file exists the following code fragment: x = 4 y = subtracting_function(x) In a function exists the following code: function [YY] = subtracting_function(XX) YY = XX + 1; end Assuming that the function is properly saved, what value of x is recorded in the function's Workspace at the end of a run of the program? x is not recorded in the functions workspace 4 5 3

x is not recorded in the function's workspace

You have two square 2x2 matrices A and B. You want to manipulate the matrices so that it has the practical effect of x = [A,B]. Which of these commands would result in the variable y having the same value as x?

y = horzcat(A,B)

what will the value of z be after this x = [2:4; -1:1; 1 2 3] y = x(2,:) z = size(transpose(y))

z=3 1 x(2,:) second row of x -1 0 1 -1 0 1 size=3x1


Related study sets

History 6.3 Andrew Carnegie's "Wealth"

View Set

A2 History: Social policies in Nazi Germany

View Set

Key shortcuts- Undo, Copy and Paste

View Set

Ch. 15 - Fetal Assessment during Labor

View Set

Wordly Wise 3000, book 6, lesson 17

View Set

apush: ch. 20-politics and expansion in an industrializing age, 1877-1900

View Set

Science Ecosystem 5th grade Test

View Set

RE Book question multiple choice

View Set