This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Rutgers University School of Engineering Spring 2012 14:440:127  Introduction to Computers for Engineers Sophocles J. Orfanidis ECE Department [email protected] week 7 Week 1  Basics – variables, arrays, matrices, plotting (ch. 2 & 3) Week 2  Basics – operators, functions, program flow (ch. 2 & 3) Week 3  Matrices (ch. 4) Week 4  Plotting – 2D and 3D plots (ch. 5) Week 5  Userdefined functions (ch. 6) – Exam 1 Week 6  Inputoutput formatting – fprintf, fscanf (ch. 7) Week 7  Relational & logical operators, if, switch statements (ch. 8) Week 8  Forloops, whileloops (ch. 9) Week 9  Matrix algebra – solving linear equations (ch. 10) Week 10  Cell arrays and structures (ch. 11) – Exam 2 Week 11  Numerical methods – part I (ch. 13) Week 12  Numerical methods – part II (ch. 13) Week 13  Symbolic toolbox (ch. 12) Week 14  Exam 3 Weekly Topics Textbook: H. Moore, MATLAB for Engineers , 3 d ed., Prentice Hall, 2011 Topics Relational and logical operators Precedence rules Logical indexing find function Program flow control if – statements switch – statements Examples: piecewise functions, unitstep function, indicator functions, sinc function, echoes Relational and Logical Operators >> doc is* % list of all 'is' functions >> help logical % convert to logical >> help true % logical 1 >> help false % logical 0 >> help relop % relational operators >> help ops % same as help / >> help find % indices of nonzero elements Relational and logical functions find, logical, true, false, any, all ischar, isequal, isfinite, isinf, isinteger islogical, isnan, isreal >> help precedence & logical AND, e.g., A&B, A,B=expressions  logical OR, e.g., AB ~ logical NOT, e.g., ~A && logical AND for scalars w/ shortcircuiting  logical OR for scalars w/ shortcircuiting xor exclusive OR, e.g., xor(A,B) any true if any elements are nonzero all true if all elements are nonzero Logical Operators == equal ~= not equal < less than > greater than <= less than or equal >= greater than or equal Relational Operators >> help relop Operator Precedence in MATLAB (from highest to lowest): 1. transpose ( .' ), power ( .^ ), conjugate transpose ( ' ), matrix power ( ^ ) 2. unary plus ( + ), unary minus ( ), logical negation ( ~ ) 3. multiplication ( .* ), right division ( ./ ), left division ( .\ ), matrix multiplication ( * ), matrix right division ( / ), matrix left division ( \ ) 4. addition ( + ), subtraction ( ) 5. colon operator ( : ) 6. less than ( < ), less than or equal to ( <= ), greater than ( > ), greater than or equal to ( >= ), equal to ( == ), not equal to ( ~= ) 7. elementwise logical AND ( & ) 8. elementwise logical OR (  ) 9. shortcircuit logical AND ( && ) 10. shortcircuit logical OR (  ) >> help precedence >> a = [1, 0, 2, 3, 7]; >> b = [3, 4, 2, 1, 7]; >> a == b ans = 0 0 1 0 1 >> k = a == b % clearer notation, k = (a==b) ans = 0 0 1 0 1 >> class(k) ans = logical >> a(k) ans = 2 7 logical indexing >> a = [1, 0, 2, 3, 7];...
View
Full Document
 Spring '10
 blase
 Binary numeral system, Bitwise operation, Logical Operators

Click to edit the document details