💻

Module 9 Video - Relational and Logical Operators

Mar 7, 2025

Lecture on Relational Questions in MATLAB

Overview of Linear Programming

  • Linear programming involves writing code that executes instructions in a sequential order.
  • The program executes each instruction one time without skipping or repeating.

Introduction to Relational Questions

  • To make programs dynamic, they need to be able to ask questions and make decisions based on the answers.
  • This lecture focuses on how to ask relational questions in MATLAB.

Relational Operators

  • Relational operators help ask questions about the relationship between two items.
  • There are six relational operators:
    • Greater than (>)
    • Greater than or equal to (>=)
    • Less than (<)
    • Less than or equal to (<=)
    • Equal to (==)
    • Not equal to (~=)

Examples of Relational Operators

  • Greater than:
    • Example: S1 > 10 where S1 = 10 returns 0 (false).
  • Greater than or equal to:
    • Example: S1 >= 10 returns 1 (true).
  • Less than:
    • Example: S1 < 33 returns 1 (true).
  • Less than or equal to:
    • Example: S1 <= 9 returns 0 (false).
  • Not equal to:
    • Denoted by ~=.
    • Example: S1 ~= 10 where S1 = 10 returns 0 (false).
  • Equal to:
    • Denoted by == to distinguish from assignment.
    • Example: S1 == 10 returns 1 (true).

Additional Relational Questions

  • Relational questions can involve computations and comparisons between variables.
  • Examples:
    • S1 > S2 checks if S1 is greater than S2.
    • S1 < S2 - 25 checks if 10 < 5 (returns 0).
    • S1 * 2 > sqrt(13 * S2) evaluates to true as 20 > sqrt(400).

Relational Questions with Vectors

  • Example: 2 * S1 < V1 * V2' involves matrix multiplication.
    • Multiplies a row vector by a column vector to produce a scalar.
    • Result: 1 (true).

Conclusion

  • Understanding how to use relational operators allows for greater flexibility in programming.
  • Next presentation will cover using relational questions with vectors and scalars.