29p. Logical operators and functions _printable_

29p. Logical operators and functions _printable_ - Logical...

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

View Full Document Right Arrow Icon
1 ©2009 by L. Lagerstrom Logical Operators and Functions • Logical operations and combinations • Truth tables • Matlab symbols • Exclusive or • Logical functions: any, all, find, etc. • Solving a projectile problem ©2009 by L. Lagerstrom Logical Operations Logical operators are used to do things such as "and" and "or" searches. For example, in a search engine we might enter "George" and " Washington" if we were looking for documents that contained both the words "George" and "Washington". If, however, we entered "George" or "Washington" it would return documents that contained either the word "George" (without "Washington"), or the word "Washington" (without "George"), or both words. A third logical operator is the "not" operator. As an example, we might enter the following for a search: not "George" This search would return all documents that did not contain the word "George" (which presumably would be a lot of documents). ©2009 by L. Lagerstrom Logical Combinations A more complete expression for the search query "George" and "Washington" is (a) "George" is true and (b) "Washington" is true For this combination to be true, both the (a) and (b) parts have to be true. If either is false, or both are false, then the combination is false. For example, if "George" is true (i.e., "George" is found in a document) but "Washington" is false ("Washington" is not found in the document), then the result is false. On the other hand, the combination "George" or "Washington" means (a) "George" is true or (b) "Washington" is true This combination is true for three situations: (1) "George" is true but "Washington" is false; (2) "George" is false but "Washington" is true; and (3) "George" is true and "Washington" is true. ©2009 by L. Lagerstrom Truth Tables Once upon a time in a math class somewhere, you probably encountered truth tables. A truth table lists the true and false results for the basic combinations of logical operations. An example is below. Note that "A" and "B" represent statements such as: "George" is true. So, for example, the combination "A and B" might represent "George is true and Washington is true". A B not A A and B A or B true true false true true true false false false true false true true false true false false true false false Note that "A and B" is true in only one case out of the four, while "A or B" is true in three cases out of the four.
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 ©2009 by L. Lagerstrom Matlab Symbols In Matlab we use the "&" symbol to represent "and", the "|" symbol (a vertical bar, which is usually shift-backslash on your keyboard) to represent "or", and the "~" symbol to represent "not". In addition, as pointed out in the lesson on relational operations, Matlab uses 1 and 0 to represent true and false, respectively. So we can rewrite the truth table as follows: A B ~A A | B 1 1 0 1 1 1 0 0 0 1 0 1 1 0 1 0 0 1 0 0 ©2009 by L. Lagerstrom Exclusive Or We previously pointed out that the combination "A or B" is true when A is true and B is false, or A is false and B is true, or both A and B
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/23/2010 for the course ENG 42325 taught by Professor Lagerstrom during the Spring '10 term at UC Davis.

Page1 / 6

29p. Logical operators and functions _printable_ - Logical...

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

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