James C. Squire P.E., Ph.D., Julie Phillips Brown Ph.D., in
Programming for Electrical Engineers, 2021 A logical expression is a statement that evaluates to either “true” or “false.” Relational
operators are a type of logical operator, and compare two values such as 5 > 4 [true] or 3 ≤ −4 [false]. matlab returns a 1 to indicate true and 0 to indicate false. matlab has several types of relational operators; some of the most common are listed below:
There are some common combinations that are useful to know.
In the following table, A and B may be expressions or references to cells containing the values TRUE or FALSE. You may wish to experiment with these nested formulas on Sheet1.
Read full chapter URL: //www.sciencedirect.com/science/article/pii/B9780128182499000054 Leonid Burstein, in Matlab® in Quality Assurance Sciences,
2015 Logical operators are designed for operations with the true or false values within the logical expressions. They can be used as addresses in another vector, matrix or array; see, for instance, the last three example commands. In MATLAB®, there are three logical operators: &
[logical AND], | [logical OR], and ~ [logical NOT]. Like the relational operators, they can be used as arithmetical operators and with scalars, matrices and arrays. Comparison is element-by-element with logical 1 or 0 accordingly as the result is true or false respectively. MATLAB® also has equivalent logical functions: and[A,B] equivalent to A&B, or[A,B] - to A|B, not[A,B] - to A~B. If the logical operators are performed on logical variables, the results are according to the rules of
Boolean algebra. In operations with logical and/ or numerical variables, the results are logical 1 or 0. Some examples are: Among the MATLAB® logical functions is find, which in its simplest forms reads as i=find[x] or i=find[A>c] where i is a vector of the place addresses [indices], where non-zero elements of the x [first form] are located, or are elements of A larger than c [second form; in this case, any of the relational operators can also be used, e.g., = , etc.]; for example, vector T = [11 8.5 5.5 0–1.5], thus >>
i = find[T] i = 1 2 3 5 >> i = find[T 2 + 5. In MATLAB’s implementation of logic, 1 is used to denote true and 0 for false. However, 1 and 0 are still numbers. Therefore, MATLAB will allow abuses such as ≫ [3>2] + [5>4], which will resolve to 2. Although
in formal logic, 1 is used to denote true and 0 to denote false, MATLAB slightly abuses notation and it will take any number not equal to 0 to mean true when used in a logical operation. For example, 3 && 1 will compute to true. Do not utilize this feature of MATLAB. Always use 1 to denote a true statement. A fortnight is a length of time consisting of 14 days. Use a logical expression to determine if
there are more than 100,000 seconds in a fortnight. Read full chapter URL: //www.sciencedirect.com/science/article/pii/B9780124202283000014
Kevin Lano, Shekoufeh Kolahdouz-Rahimi, in
Advances in Computers, 2012 UML-RSDS uses both classical set theory expressions and OCL. It only uses sets and sequences, and not bags or ordered sets, unlike OCL.
Symmetric binary operators such as ∪ and ∩ are written in the classical style, rather than as operators on collections. Likewise for the binary logical operators.
A logical_op is one of =>, &, or. An equality_op is one of =, ∕ =, >, matlab Programming
Relational Expressions
OperatorNameExampleExample result >
Greater than
[5 > 2]
1
= 6
0
5, the result would be TRUE. Excel would compare the letter a [a text data type] with the literal 5 [also a text data type]: the ASCII value for the letter a is 97, and that for the digit 5 is 53. LogicFormulaTRUE returned if NAND = NOT[AND[A,B]]
Not both true
NOR = NOT[OR[A,B]]
Neither is true
Basics
Logical operators
WARNING!
WARNING!
TRY IT!
Model Transformation Specification and Design
Appendix A Expression Syntax of UML-RSDS
< expression >
::=
< bracketed_expression > | < equality_expression > |
< logical_expression > | < factor_expression >
< bracketed_expression >
::=
“[” < expression > “]”
< logical_expression >
::=
< expression > < logical_op > < expression >
< equality_expression >
::=
< factor_expression > < equality_op > < factor_expression >
< factor_expression >
::=
< basic_expression > < factor_op > < factor_expression > |
< factor2_expression >
< factor2_expression >
::=
< expression > “->any[]” |
< expression > “->size[]” |
< expression > “->isDeleted[]” |
< expression > “->exists[” < identifier > “|” < expression > “]” |
< expression > “->exists1[” < identifier > “|” < expression > “]” |
< expression > “->forAll[” < identifier > “|” < expression > “]” |
< expression > “->exists[” < expression > “]” |
< expression > “->exists1[” < expression > “]” |
< expression > “->forAll[” < expression > “]” |
< expression > “->select[” < expression > “]” |
< expression > “->reject[” < expression > “]” |
< expression > “->collect[” < expression > “]” |
< expression > “->includesAll[” < expression > “]” |
< expression > “->excludesAll[” < expression > “]” |
< basic_expression >
< basic_expression >
::=
< set_expression > | < sequence_expression > | < call_expression > |
< array_expression > | < identifier > | < value >
< set_expression >
::=
“{” < fe_sequence > “}”
< sequence_expression >
::=
“Sequence{” < fe_sequence > “}”
< call_expression >
::=
< identifier > “[” < fe_sequence > “]”
< array_expression >
::=
< identifier > “[” < fe_sequence > “]”
Chủ Đề