MATLAB: Midterm Review

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

True

(True/False) All matrices are arrays.

False

(True/False) All matrices are vectors.

True

(True/False) All vectors are arrays.

False

(True/False) An answer of logical 1 means the relation was false.

True

(True/False) An independent variable is usually defined with a colon operator or linspace.

False

(True/False) Given the code: x = [1; 2]; y = [5; 7]; xy = [x; y] xy will end up as a 2x2 array.

False

(True/False) Given the following: x = 1; y = 0; z = x | x & y z returns 0

False

(True/False) If you try to use a variable in an equation before it is given a value your code will work.

False

(True/False) If you want to create a spaced vector, A, that starts with -4, ends with 12 and has increments of 2, you would use the following code. A=[-4:12:2]

True

(True/False) In MATLAB you can define a section of code using %%

False

(True/False) MATLAB returns 0 if a logical operation is true and 1 if a logical operation is false.

True

(True/False) The disp function can only print one element (e.g. one number, string, variable) per use.

True

(True/False) The linspace function lets you create a vector with a specific number of points.

False

(True/False) The only way to plot more than one set of data in one plot is to provide more pairs of data in the plot command.

False

(True/False) The workspace is where you type in your MATLAB instructions.

False

(True/False) There is no limit to the number of characters a variable name can have.

True

(True/False) We use parentheses to change the order of operations when evaluating an expression.

False

(True/False) You are given the following code: name='Ann'; aver_miles=25.739; fprintf('%s ran an average of %f miles last week', name, aver_miles) The following will be printed as output: Ann ran an average of 25.7 miles last week

False

(True/False) You are given the following code: t=linspace(0,15,100) x=12*t.^2; If you enter this, an error message will be returned.

False

(True/False) Your code will not run if you use a built-in variable name as your own variable name.

False

(True/False) Your code will run fine if you use a keyword as a variable name.

False

(True/False) hold off tells MATLAB to keep drawing plots in the same place as the previous plot.

True

(True/False) x=[1 2 3 4 5] x is an example of a row vector

No

(Yes/No) Is the following variable declaration valid?

Yes

(Yes/No) Is this a valid variable name: power_of_3

True

(True/False) A semicolon is used to separate rows in an array.

True

(True/False) A string is an array of characters.

False

(True/False) A syntax error is one in which the code runs, but the results are incorrect.

False

(True/False) All arrays are vectors.

1. None of the answers have equal precedence 2. Division 3. Exponentiation 4. Subtraction 5. Addition

Choose all of the operations that have equal precedence. 1. None of the answers have equal precedence 2. Division 3. Exponentiation 4. Subtraction 5. Addition

1. radius_of_cone 2. 11th_sample_height 3. _sample_two_mass 4. Length

Which of the variable names below are not valid? 1. radius_of_cone 2. 11th_sample_height 3. _sample_two_mass 4. Length

2

Given a subplot command for a 3x2 grid of plots, what should be the third value you need to provide to make the next plot display in the upper right hand location.

4

Given a subplot command for a 3x4 grid of plots, what should be the third value you need to provide to make the next plot display in the upper right hand location.

4

Given the code: x = [10; 4; 5]; y = [4; 5; 5]; xy = [x y] What would be the result of xy(2,1)?

1. before the ^ operator 2. before the * operator 3. No dot operators are needed

Given the equation for the area of a circle: A = πr^2 You are given a vector of radii, r. Select all of the places where a dot operator must be used 1. before the ^ operator 2. before the * operator 3. No dot operators are needed

No dot operators are needed

Given the equation for the circumference of a circle C = 2πr You are given a vector of radii, r. Select all of the places where a dot operator must be used.

t = independent z = dependent

Given the following code, choose the dependent and independent variables. pi = 3.14159; t = linspace(0,2*pi); z = 6*sin(t); t = ? z = ?

a = 7 b = 2

Given the following code, what will be stored in a and b? F = [4 7 3 1 5]; [a,b] = max(F);

7

Given the following code, what will be stored in b? F = [4 7 3 1 5]; b = max(F);

1. plot(t,x) 2. plot(x,t) 3. plot(y,x) 4. plot(y,t)

Given the following code, which command would you use to plot your independent and dependent variables? y = 2; x = 1:y:10; t = x.^2/2; 1. plot(t,x) 2. plot(x,t) 3. plot(y,x) 4. plot(y,t)

1. AB(5) 2. AB(1,3) 3. AB(3,1) 4. AB(3)

Given the following code: A = [1 2 3]; B = [4 5 6]; AB = [A; B]; How could you access the value of 3 in AB? Choose all correct options.

Logical Array = [1 0 1 0]

Given the following code: a = [7 6 0 9]; b = [5 3 2 7]; c = [7 3 5 2]; d = (a-b) ~= c; What is the stored in d?

True

Given the following code: y=[2 5 -19 4 -100 63]; z=length(y); The value stored in z is 6.

1. M(1,2) = 1 2. M(1,3) = 2 3. M(3,1) = 8 4. M(2) =5

Given the following matrix: M = [3 1 2; 5 4 6; 8 9 7] Match the code with the value it will return 1. M(1,2) = ? 2. M(1,3) = ? 3. M(3,1) = ? 4. M(2) = ?

1. M(1,2) = 4 2. M(2,1) = 3 3. M(2) = 3 4. M(1,1) = 5

Given the following matrix: M = [5 4 6; 3 1 2]; Match the code with the value it will return 1. M(1,2) = ? 2. M(2,1) = ? 3. M(2) = ? 4. M(1,1) = ?

1. Raising a to the power of b 2. Dividing b by d 3. Multiplying b by d 4. Subtracting c from d

Given the following variables: a = 3;b = 5;c = [7 4 6 1];d = [3 8 4 5]; Which operation below requires the element-by-element operator? 1. Raising a to the power of b 2. Dividing b by d 3. Multiplying b by d 4. Subtracting c from d

[4 3]

Given the matrix D defined below, what would be the value of y? D = [4 1 2; 3 2 3; 1 2 8; 7 5 0]; y = size(D);

4

Given the matrix, M defined below? What would be the value of x? M = [4 5 2 5; 3 2 3 5; 1 2 9 8];x = length(M);

scores = [78, 23, 99, 85, 97]; count = mean(scores)

Given the numbers: 78, 23, 99, 85, & 97 Find the average score in an array called scores where values are stored in a row vector. Output only the highest value from that vector in the command window.

scores = [78, 23, 99, 85, 97]; highest = max(scores)

Given the numbers: 78, 23, 99, 85, & 97 Find the highest value in an array called scores where values are stored in a row vector. Output only the highest value from that vector in the command window.

scores = [78, 23, 99, 85, 97]; count = length(scores)

Given the numbers: 78, 23, 99, 85, & 97 Find the number of values in an array called scores where values are stored in a column vector. Output only the highest value from that vector in the command window.

4 (Format Short)

How many decimal places does MATLAB display in the command window by default?

0

If you are given the following: q = 0 & 4; What will be returned in q? Type 1 for true and 0 for false.

False

If your code is missing a closing parenthesis, then your code has a semantic error.

1. tab = \t (Forward Slash "t") 2. newline = \n (Forward Slash "n") 3. apostrophe = " (Apostrophe) 4. percent = %% (Double Percent Signs "%%")

Match the special character with its code when you are trying to get them to display in a fprintf statement. 1. tab = ? 2. newline = ? 3. apostrophe = ? 4. percent = ?

Left to Right

Operators with the same order of precedence are evaluated in which way?

1. 2 2. 4

The following code defines a ________ by ________ matrix. D = [1 5 2 6; 2 5 10 3];

1. 3 2. 5

The following code generates a grid of plots with ________ columns and ________ rows. subplot(5, 3, 2)

1. time = linspace (0, 10, 50); 2. velocity = v0 + acceleration * time; 3. plot (time, velocity) 4. xlabel ('time in sec') 5. ylabel ('velocity in m/s')

The velocity of an object at any point in time can be calculated based on the formula v = v0 + a * t. Calculate the velocity of an object with an initial velocity, v0, of 10 m/s and accelerating at 10 m/s/s over time from 0 to 10 seconds. Generate 50 points for your time vector. Plot your time and calculated velocities. Your first two lines are provided for you: Line 1 v0 = 10; % m/s Line 2 acceleration = 10; %m/s/s

list = linspace (3, 12, 4); divideBy3 = list./3; matrix = [divideBy3; list]

Write a code that should generate 4 numbers between 3 and 12 and store them in an array. Then it will create a new array by dividing the values in the previous array by 3. Create and display a matrix of your two arrays with the calculated values in the top row and the original values in the bottom row.

A = [2:2:20]

To create a spaced vector, A, that will give the first 10 even numbers (starting with 2), which code would you use?

Format Bank

To have numeric output display formatted to round to two decimal places, use:

1. Variables can start with a number. 2. Variables cannot use punctuation characters. 3. Variables must start with a letter. 4. Variables can use letters, numbers, and the underscore character.

To name a variable in MATLAB, the following requirements are true except __________. 1. Variables can start with a number. 2. Variables cannot use punctuation characters. 3. Variables must start with a letter. 4. Variables can use letters, numbers, and the underscore character.

linspace (0, 30, 15)

What command would create an array of 15 equally spaced points between 0 and 30?

5

What is displayed after running the following code? A = [2 1 1 1]; sum(A)

Format Short

What is the default format type in MATLAB for output?

1. format compact 2. format short 3. format bank 4. format long

What is the default format type in MATLAB for output? 1. format compact 2. format short 3. format bank 4. format long

/ (Backwards Slash)

What is the symbol used for division?

^ (Carrot)

What is the symbol used for exponentiation?

* (Asterisk)

What is the symbol used for multiplication?

Column Vector

What kind of an array is C? C = [2; 4; 6; 8]

abs(log10(%^2))

What line of code is equivalent to the following function: | log 5^2 |

sqrt(4*log(10))

What line of code is equivalent to the following function?

% (Percent Symbol)

What symbol denotes a comment in a MATLAB script?

6

What value is stored in D after the following code is run; A = 6; B = 4; C = 4; D = A-B+C;

2

What value is stored in D after the following code is run? A = 4; B = 7; C = 5; D = A-B+C;

8

What value is stored in D after the following code is run? A = 5; B = 6; C = 9; D = A-B+C;

14

What value is stored in D after the following code is run? A = 7; B = 2; C = 9; D = A - B + C;

10

What value is stored in D after the following code is run? A =5; B = 3; C = 8; D = A-B+C;

100

What will be the length of the array created by the following statement? linspace(1,50)

1

What would be stored in ans after running this code? If it is a logical value please type 1 for true and 0 for false. a = [ 5 6 6 ]; b = [ 2 4 8 ]; comp = a >= b comp(2)

1

What would be stored in ans by the following code? Answer 1 for true and 0 for false. 3 < 5 + 4 * 1

0

What would be stored in ans by the following code? Answer 1 for true and 0 for false. 7 < 2 + 1 * 2

2

What would be the result stored in b when the following code is run? a = -2; c = 5; b = abs(a);

10

What would be the value stored in ans if the following were type in the command window? 6^2 / 6 + 3 * 2 - 2

1. [1, 2, 3, 4, 5] 2. [1 2 3 4 5] 3. [2; 4; 6; 8; 10]

Which of the following is a column vector? 1. [1, 2, 3, 4, 5] 2. [1 2 3 4 5] 3. [2; 4; 6; 8; 10]

1. list = [1:4]; 2. squares = list.^2; 3. matrix = [list: squares]

Write a code that should generate the numbers from 1 to 4 and store them in an array. Then it will create a new array containing the squares of the values in the previous array. Finally, create and display a matrix of your two arrays with the original values in the top row and the squares on the bottom row.

1. celsiusTemp = 0:10:100 2. farenheitTemp = (celsiusTemp*(9/5)) + 32 3. plot (celsiusTemp, fahrenheitTemp) 4. xlabel ('Temp in degrees C') 5. ylabel (''Temp in degrees F')

Write a code that should generate values in degrees Celsius from 0 to 100 in ten-degree increments. Then, calculate the equivalent temperatures in degrees Fahrenheit using the formula (C * 9/5) + 32. Finally, plot your two temperatures.

1. numbers = linspace (2, 12, 6); 2. numbers (3) 3. mean(numbers)

Write a code that will generate an array of 6 numbers between 2 and 12. It will display the 3rd item in the array. Then it will display the average value in the array.

1. numbers = linspace (1, 11, 2); 2. numbers (2) 3. sum(numbers)

Write a code that will generate an array of all of the odd numbers between 1 and 11. It will display the 2nd item in the array. Then it will display the total of all the values in the array.

16

You are given the following code: X=[1 4 9 16 25 36 49 64]; y = X(4) What number will be stored in y?

49

You are given the following code: X=[1 4 9 16 25 36 49 64]; y = X(7) What number will be stored in y?

0.51

You are given the following code: d=[8 -2 0.51 99 -63 18.25] f=d(3) What is stored in f?

z = x./y

You are given the following code: x=[2 9 7]; y=[1 3 0]; You want to do element by element math such that a variable z holds the result of x divided by y. What line of code would you use?

linspace

You want to create an array that allows you to set the number of data points - regardless of increments. What function would you use?

name = input('What is your name? ', 's')

You want to create an input statement that queries a user to enter their first name and store it in the variable, name. What code would you use?

y = 10:10:100

You want to create the following array: y=[10 20 30 40 50 60 70 80 90 100] What line of code would you use?

y = [10:10:100]

You want to create the following array: y=[10 20 30 40 50 60 70 80 90 100] What line of code would you use?

3

a is a vector [ 3 1 5 2]; b is a logical vector [0 1 0 1]; What would be returned by sum(a(b)) ?


Set pelajaran terkait

serology, blood, & bodily fluids

View Set

Biology AMP 1 BSC2085 Chapter 1-3 (Quizzes) (PART 2) EXAM1

View Set

Chapter 17. Methods of Persuasion Concept

View Set

Operating-System Structures Ch. 2

View Set

Evolve Chapter 53 practice questions

View Set