Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.

Similar presentations


Presentation on theme: "Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators."— Presentation transcript:

1 Programming with MATLAB

2 Relational Operators

3 The arithmetic operators has precedence over relational operators

4 Logical Operators

5 Order of precedence for operators

6

7 Logical variables Logical variables can take only two values:  <> 0 (true)  0 (false)

8 The if statement End Start

9 The if statement If x is greater than or equal 5, the statement y = sqrt(x-5) gets executed Otherwise, the statement does not execute

10 The if statement The value of z and w are computed only if both x and y are nonnegative. If any of x or y is negative, both w and z retain their initial values

11 The else statement

12

13 If x is nonnegative, y = sqrt(x) is executed If x is negative, an error message is displayed

14 The elseif statement

15 Example: Numeric grade to letter grade Write a program to display your course letter grade knowing your numeric grade  Example: If your numeric grade is 93, then the program displays the letter A If your numeric grade is 70, then the program displays the letter C

16

17 Nested if statement =

18 This statement gives the same result as the previous one =

19 Examples Write a function that accepts one variable, which is the year and returns a logical variable: true (if the year is leap) or false (if the year is not leap) A leap year is characterized by  All years evenly dividable by 400 are leap  All years that are evenly dividable by 4 and are not evenly dividable by 100 are leap

20 Examples


Download ppt "Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators."

Similar presentations


Ads by Google