Presentation is loading. Please wait.

Presentation is loading. Please wait.

General Computer Science for Engineers CISC 106 Lecture 04 Roger Craig Computer and Information Sciences 9/11/2009.

Similar presentations


Presentation on theme: "General Computer Science for Engineers CISC 106 Lecture 04 Roger Craig Computer and Information Sciences 9/11/2009."— Presentation transcript:

1 General Computer Science for Engineers CISC 106 Lecture 04 Roger Craig Computer and Information Sciences 9/11/2009

2 Lecture Objectives If statements (nested) Logical Operators Matlab Output

3 IF Statements Nested if statements can be used when two things have to be true for a command to execute

4 IF Statements Using nested if statements if (x < 5) if ( x > 2) y = 500 else y = 300 end else y= 200 end

5 IF Statements Using nested if statements if (x < 5) if ( x > 2) y = 500 else y = 300 end else y= 200 end Using multiple conditions in one if statement if ( x 2) y = 500 else y = 200 end

6 Logical Operators - AND & && A & B A TF B TTF FFF

7 Logical Operators - OR | || A | B A TF B TTT FTF

8 Logical Operators - NOT ~ ~A TF FT

9 Numbers as True/False What do you think would happen here: if (5) disp(‘5 is a true value’); else disp(‘5 is a false value’); end

10 Numbers as True/False Group activity: evaluate the following as true or false for x=5:  x < 7 & 3 < x 2. ˜ (x / 2 > 1 & x < 0)  x ˜ = 5 & x + 2 > 6 | x > 5  x + x == 2 * x && ˜ x

11 Matlab Output ◦ How do we see information about what is going on in our program?

12 Matlab Output ◦ How do we see information about what is going on in our program? ◦ disp()

13 Matlab Output Formatted Output Example: ◦ “There are 5 widgets in inventory” ◦ fprintf(‘There are %d widgets in inventory’, widgets);

14 Matlab Output Formatted Output Example: ◦ “There are 5 widgets in inventory” ◦ fprintf(‘There are %d widgets in inventory’, widgets); %d acts as a place holder for widget variable at end of command and is known as a conversion character. Conversion characters specify the notation of the output. Note the variable widgets as the second argument.

15 Matlab Output Lets look at the syntax ◦ count = fprintf(fid, format, A,...) ◦ count – the number of bytes written ◦ fid – refers to opened file ◦ format – is a format string in between single quotes If fid is set to one or omitted the output goes to the screen.

16 Arrays

17 Arrays

18 Arrays Fundamental unit of data in MATLAB Collection of data into rows and columns (MATrix LABoratory) 1 dimensional, vector 2 dimensional, matrix 0 dimensional, scalar (a 1x1 array) Row vector, column vector, transpose

19 Arrays

20 Array commands a = [1 2 3 4] b = [1; 2; 3; 4] c = [1 2; 3] (error) d = [1 2; 3 4] f = d(1,2) g(4,5) = 7

21 Arrays continued zeros(), ones(), eye() scalar vs. array arithmetic +, -, * (.*), / (./) ^ etc.


Download ppt "General Computer Science for Engineers CISC 106 Lecture 04 Roger Craig Computer and Information Sciences 9/11/2009."

Similar presentations


Ads by Google