Relational Operators

  • This is used for comparison of similar parameters whether scalar or non-scalar. With scalars, the operators just output a 1 or 0 signifying true or false for the command statement being considered. When acting on matrices of the same size, the operators carry out an element-by-element comparison thereby creating an output matrix of 1’s and 0’s. The relational operators include:
Operator Description
<  Less than
<= Less than or equal to
>  Greater than
>= Greater than or equal to
== Equal to
~= Not equal to

 

  • Some sample code using relational operators is seen below:

1     2

3 4 5

 

EXERCISE 5

Using the matrices (shown below) carry out the following:

6  65

  1. Find the product of B and C (name the matrix D). Find the product of C and B (name the matrix E).
  2. Find the element-by-element product of the matrices B and C (name it F).
  3. Carry out a C greater than B comparison and name the resulting matrix G (do it by hand first)
  4. Carry out element-by-element exponentiation of B by G (name H).
  5. Compute the columnar product of the elements of H.

MISCELLANEOUS EXERCISE

Complete the sequences observed in matrix C to make a 4-by-6 matrix K (negative integers are allowed).

Convert M into every possible size it could have given the number of elements it possesses.

[Show]