review 2 exam 3 1. 1.history of computers 1. cpu stands for _______________________. a. counter...
TRANSCRIPT
REVIEW 2 Exam 3
1
1.History of Computers
1. CPU stands for _______________________.
a. Counter productive units
b. Central processing unit
c. Copper Part Unit
d. None of the answers are valid
2. (True or False) MATLAB is a compiled language.
2
2.Getting Started with Matlab
Before coding anything, what are the 5 steps to follow?
S ________________________________
I ________________________________
M ________________________________
C ________________________________
T ________________________________
3
2.Getting started with Matlab
In 5 steps, how many parts are included in step C of SIMCT? What are they?
The command clear is a :a) built-in function
b) User-defined function
c) Language construct
d) None of the above.
4
3.Variables, Data Types
Which command creates a variable named age, assigns the value 29, and suppresses the output?
a. Age = 29
b. age =29
c. 29 = age;
d. None of the options is valid
5
4.Operators and Operands
Which of the following are Boolean Operators?
How about relational operators?
a. +-*/
b. <= >= < > == ~=
c. || && ~
d. None of the above are valid
6
4.Operators and Operands
Consider the following MATLAB code:num=10num_condition= (num > 0) && (mod(num,4)~=0)
then num_condition will evaluate to:
a. 0
b. 1
c. 2
d. 3
7
5.Inputs
Will the following script file allow the user to enter her/his name properly?
clc
clear
name = input(‘Enter your name’);
fprintf(‘Welcome %s!\n’, name);
a. Yes
b. No
8
6. Outputs What are the three methods to display results? Which method allows to print results with a specific
format? What are the 4 placeholders? What is the purpose of placeholders? Which function actually uses placeholders? What are format modifiers? Which placeholder can have a format modifier that
controls the number of decimal places? If there are 3 placeholders in the format string, how
many variables are likely printed to the screen?9
7. Conditionals
What are the two conditionals shown that allow to skip code?
Regardless whether it is if or switch, which keyword is always associated with both?
What other keywords are associated with if? What other keywords are associated with switch?
10
8.Library Functions What are library functions? What are arguments? What are return-values? Is there a limit to the number of arguments a function
can receive? Is there a limit to the number of return-values a function
can have? Name 3 rounding functions? Which rounding function rounds towards +infinity? Which rounding function rounds towards -infinity? Which rounding function rounds towards the nearest
integer? 11
9. Loops
12
LoopsWHILEFORchoosing a loopinfinite loops
Changing control-loop variable in body
Range operatorRunning TotalsRunning Products
Using While loops to:• validate input• repeat the program – based on user’s
selection
Nesting Loops
Numerical Methods• Iterative solutions – “close enough” to
a solution. Remember to use abs()
10. Array
13
Array TerminologyTypes of arrays"row", "column"empty vector [ ]
Matrix MathDifferences for:
additionsubtractionmultiplicationdivisionexponentiation
Defining arraysHard-codedRange operatorlinspace()
Re-defining array elementsEliminating array elementsAugmenting arrays
Array buildingDiminishing arrays
Referencing arrays
Slices
10. Array
14
SearchingLinear search – “one by one”Binary search – “sorted search”
Matrix MathUsing scalarsUsing vectors & matricesvs. element-per-element
Logical operations
Logical vectors
Find the values - Logical indexing
Find the indices - find()Applying &, | to logical operations on arrays
Question
How many different ways to create the following vector a? what is the length of vector a? which function can be used to determine it? How to determine minimum or maximum value in vector a? and the location?
1 3 5 7 9
How to extract a new vector as 5 9?
15
Question
1 5 6
8 9 0
4 3 2
How to access the number 0?
How to extract vector 4 3 2?
How to extract vector 5
9
3
How to extract matrix 9 0
3 2
16
Question
Consider the following MATLAB code:V=[2 9.5 4 9 7]W=[4 6 -7]X= V(2)+W(3)
Then X will be equal to:
a. Error
b. 2.5
c. 6.5
d. 19.5
17
Question
Consider the following MATLAB code:
A= [ 0 1 0 1 ]B= [ 1 0 1 0 ]C= A || B
Then C will return:
a. Error
b. [ 1 1 1 1]
c. [ 0 1 0 1 ]
d. [ 1 0 1 0 ]
18
Question
Consider the following MATLAB code:
D= [ 5 9 7]F=find(D>5)
then F will be equal to:
a. [ 1 2 3]
b. [ 2 3 ]
c. [ 9 7 ]
d. [ 5 9 7]
19
Question
Consider the following MATLAB code:
G= [ 2, 8, 9, 6; 8, 6, 9, 3; 9, 5, 7, 3]H=G(1, [2, 3])
Then H will evaluate to:
a. [ 9 8]
b. [ 9; 8 ]
c. [ 8 9 ]
d. [ 8; 9]
20
Question
Consider the following MATLAB code:
for k=1:3 L(k+1)=k+10;enddisp(L)
what is the value of L:
21
11. Cell array
Mixed data type To grab the content, you need {} inputdlg() accepts its input arguments as cell array and
return a cell array of strings. msgbox() accepts string as its input arguments
22
12. Programmer defined function Overall Idea? Lots of advantages? Vocabulary
Function-header Function-definition Syntax? Filename? Directory? Keyword? Position of return-values and parameter list Using all the parameters Assigning all the return-Function-call Arguments vs. parameters Return-values
23
(string must be included in single quote marks)
24
Question
Consider the following MATLAB code:
str='7-Eleven'letterE= strfind(str,'e')
then the variable letterE will evaluate to:
25
plotting
plot(), plot3(), hold on, figure(), title(), xlabel(), ylabel() pie(), pie3(), bar() Polyfit(), polyval()
26
Files Why stores the data to file? When we should use high level functions, when to use
low level functions?
27
28