lecture09bw - Lecture 9: Transfer of Control Relational...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 9: Transfer of Control if Relational operators, Logical operators, Conditionals if/else if/elseif/else switch/case end 1 E7, Sept 29, 2008, M. Frenklach branching IF statement if condition action end 2 RELATIONAL OPERATORS < Less than <= Less than or equal > Greater than >= Greater than or equal == Equal ~= Not equa Not equal 3 X and Y are scalars X Y X < Y rue false 1 0 logical varibles 4 Example: Calculate y=sin(x)/x But what if x = 0 ? if x ~= 0 y = sin(x)/x; end 5 LOGICAL OPERATORS ~ Not ~ (5>6) (3==3) & (2<1) & And O | (3==3) | (2<1) Or 6
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
X and Y are arrays X > Y X Y [ 1 1 0 . .. 1 0 ] logical array 7 LOGICAL FUNCTIONS any(x) any(any(A)) all(x) find(x) find(x < 1) 8 >> x = [ 1 0 1 0 1 0 0 0 1 1 0 0 ]; >> any(x) ans = 1 1 1 0 >> any(any(x)) ans = 1 >> all(x) ans = 1 0 0 0 >> all(all(x)) ans = 0 9 >> x = [ 1 0 1 0 1000 1 0 0 0 1 1 0 0 ]; >> [i,j] = find(x) i = >> find(x) ans = 1 2 3 1 2 3 1 3 6 7 j = 1 1 1 2 3 10 >> x = [ -1 2 8 9 -3 7 0 1 5 4 6 -2 ]; >> [i,j,v] = find(x > 1); >> [i j v] >> find(x > 1) ans = ans = 2 1 1 411 2 4 4 1 1 1 2 1 4 2 1 5 8 9 1 3 1 2 3 1 331 10 11 3 3 1 11 branching IF-ELSE statement if condition1 action1 else action2 end 12
Background image of page 2
Example: Calculate y=sin(x)/x
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/01/2009 for the course ENGLISH 7 taught by Professor Sengupta during the Spring '09 term at University of California, Berkeley.

Page1 / 4

lecture09bw - Lecture 9: Transfer of Control Relational...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online