matlab4 CMU ECR 200 Computer Aided Problem Solving for Engi
Solution
1)
Relational and Logical Operators used in MATLAB:
In General an operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
MATLAB is specially designed to operate primarily on whole matrices and arrays, thereforeoperators in MATLAB work both on scalar and non scalar data.
Relational Operators:
These operators also work on both scalar and non scalar data, these for arrays perform element by element comparisons between two arrays and return a logical array of the same size, with elements set to logical 1(true) where the relation is true and the elements set to logical 0 (false) where it is not the case.
Following are the relational operators available in MATLAB:
Example:
Apart from above mentioned operators, MATLAB also provides functions/commands used for the same purpose.
Logical Operators:
MATLAB offers two types of logical operators and functions
Element wise logical operators operate element by element on logical arrays, the symbols used are
Short circuit logical operators allow short circuiting on logical operations, the symbols used are:
Example:
Only the first question has been answered.
| eq(a, b) | Tests whether a is equal to b |
| ge(a, b) | Tests whether a is greater than or equal to b |
| gt(a, b) | Tests whether a is greater than b |
| le(a, b) | Tests whether a is less than or equal to b |
| lt(a, b) | Tests whether a is less than b |
| ne(a, b) | Tests whether a is not equal to b |
| isequal | Tests arrays for equality |
| isequaln | Tests arrays for equality, treating NaN values as equal |
