Presentation is loading. Please wait.

Presentation is loading. Please wait.

REVIEW 2 Exam 3 1. 1.History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.

Similar presentations


Presentation on theme: "REVIEW 2 Exam 3 1. 1.History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper."— Presentation transcript:

1 REVIEW 2 Exam 3 1

2 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

3 2.Getting Started with Matlab Before coding anything, what are the 5 steps to follow? S________________________________ I________________________________ M________________________________ C________________________________ T________________________________ 3

4 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

5 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

6 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

7 4.Operators and Operands Consider the following MATLAB code: num=10 num_condition= (num > 0) && (mod(num,4)~=0) then num_condition will evaluate to: a. 0 b. 1 c. 2 d. 3 7

8 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

9 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

10 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

11 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

12 9. Loops 12 Loops WHILE FOR choosing a loop infinite loops Changing control-loop variable in body Range operator Running Totals Running 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()

13 10. Array 13 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

14 10. Array 14 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

15 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

16 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

17 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

18 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

19 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

20 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

21 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

22 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

23 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

24 (string must be included in single quote marks) 24

25 Question Consider the following MATLAB code: str='7-Eleven' letterE= strfind(str,'e') then the variable letterE will evaluate to: 25

26 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 27

28 28


Download ppt "REVIEW 2 Exam 3 1. 1.History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper."

Similar presentations


Ads by Google