20120419_Review2_Exam3

advertisement
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)
b)
c)
d)
built-in function
User-defined function
Language construct
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

a.
b.
c.
d.
Consider the following MATLAB code:
num=10
num_condition= (num > 0) && (mod(num,4)~=0)
then num_condition will evaluate to:
0
1
2
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.
b.
Yes
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
Loops
WHILE
FOR
choosing a loop
infinite loops
Using While loops to:
• validate input
• repeat the program – based on user’s
selection
Nesting Loops
Changing control-loop
Numerical Methods
variable in body
• Iterative solutions – “close enough” to a
Range operator
solution. Remember to use abs()
Running Totals
Running Products
12
10. Array
Array Terminology
Types of arrays
"row", "column"
empty vector [ ]
Matrix Math
Differences for:
addition
subtraction
multiplication
division
exponentiation
Defining arrays
Hard-coded
Range operator
linspace()
Re-defining array elements
Eliminating array elements
Augmenting arrays
Array building
Diminishing arrays
Referencing arrays
Slices
13
10. Array
Searching
Linear search – “one by one”
Binary search – “sorted
search”
Matrix Math
Using scalars
Using vectors & matrices
vs. element-per-element
Logical operations
Logical vectors
Find the values - Logical
indexing
Find the indices - find()
Applying &, | to logical
operations on arrays
14
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?
13579
How to extract a new vector as 5 9?

15
Question
156
890
432
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
32
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.
b.
c.
d.
Error
2.5
6.5
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.
b.
c.
d.
Error
[ 1 1 1 1]
[0101]
[1010]
18
Question

Consider the following MATLAB code:
D= [ 5 9 7]
F=find(D>5)
then F will be equal to:
a.
b.
c.
d.
[ 1 2 3]
[23]
[97]
[ 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.
b.
c.
d.
[ 9 8]
[ 9; 8 ]
[89]
[ 8; 9]
20
Question

Consider the following MATLAB code:
for k=1:3
L(k+1)=k+10;
end
disp(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()
Files


Why stores the data to file?
When we should use high level functions, when to use
low level functions?
26
27
28
Download