ENGR 1181 MATLAB 7: Logical Expressions

ENGR 1181 MATLAB 7: Logical Expressions

<p>ENGR 1181 | MATLAB 7: Logical Expressions Classroom Guide</p><p>Learning Objectives 1. Apply logical operations correctly in arrays. 2. Analyze data using logical operators.</p><p>Textbook Reading Chapter 6.1</p><p>Topics This class contains the following topics: 1. Evaluating to True/False 2. Relational Operators 3. Logical Operators 4. Relational and Logical Operators Combined 5. Vectors</p><p>Outline Below is an outline of the topics and the order in which they should be covered:</p><p>1. Evaluating to True/False a. In MATLAB, and programming in general: a.i. 1 = Logical True a.ii. 0 = Logical False b. MATLAB can evaluate mathematical statements and report the result as true or false, or as 1 or 0. c. Any non-zero number will evaluate to TRUE (1) c.i. For example: 8 would evaluate to TRUE (1) d. Zero will evaluate to FALSE (0)</p><p>2. Relational Operators (Classroom Activity – Example 1) a. Relational operators compare two numbers in a comparison statement. a.i. < Less than a.ii. <= Less than or equal to a.iii. > Greater than a.iv. >= Greater than or equal to a.v. == Equal to a.vi. ~= Not equal to b. Evaluating relational operators b.i. When we have MATLAB evaluate statements with relational operators, it’s like we are giving MATLAB a true-false test. b.ii. Show examples of evaluating relational operators. 3. Logical Operators (Classroom Activity – Example 2) a. Logical operators compare two or more operands (numbers) to see if that combination is true or false. The result is assigned as true or false. a.i. & (AND) True if both are true a.ii. | (OR) True if either OR both are true 1 ENGR 1181 | MATLAB 7: Logical Expressions Classroom Guide</p><p> a.iii. ~ (NOT) True if the operand is false b. Show examples evaluating logical operators.</p><p>4. Relational and Logical Operators Combined (Classroom Activity – Example 3) a. Relational and logical operators can be combined in statements and evaluated. b. It is important to follow the MATLAB order of precedence with regard to relational and logical operators. b.i. Parentheses ( ) b.ii. Exponent ^ b.iii. Logical ‘NOT’ ~ b.iv. Multiply, Divide * / b.v. Add, Subtract + - b.vi. Relational Operators < > <= >= == ~= b.vii. Logical ‘AND’ & b.viii. Logical ‘OR’ | c. Show examples evaluating statements combining relational and logical operators.</p><p>5. Vectors (Classroom Activity – Example 4) a. Relational and logical operators can be used on scalars, but it can be used over entire vectors as well. This will give a vector of true/false responses. b. Show examples of using relational and logical operators with vectors.</p><p>6. Students will complete Part 1 of the assignment to turn in by the end of class. Once finished, students may start on Part 2 due by the next class. Students will submit Part 1 of the assignment to the Carmen dropbox as a PDF.</p><p>2</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us