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

Slides:



Advertisements
Similar presentations
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Advertisements

Selection (decision) control structure Learning objective
Lesson 5 - Decision Structure By: Dan Lunney
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
1 9/26/08CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
Basic Elements of Programming A VB program is built from statements, statements from expressions, expressions from operators and operands, and operands.
true (any other value but zero) false (zero) expression Statement 2
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 4- 1.
Lecture 13 Decision structures
1 9/25/06CS150 Introduction to Computer Science 1 Nested Ifs, Logical Operators, exit() Page 194.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
Chapter 4: Control Structures: Selection
Chapter 4 Making Decisions
Chapter 4 MATLAB Programming Logical Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Fall 2006AE6382 Design Computing1 Relational and Logical Operators Use relational operators to test two values Work with values of true and false Compare.
1 9/28/07CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
CMSC 104, Version 8/061L11Relational&LogicalOps.ppt Relational and Logical Operators Topics Relational Operators and Expressions The if Statement The if-else.
1 Conditional statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Lecture-2 Operators and Conditionals. Variables(again???) Type: Representation of “bits” in memory Variables: Name for a memory object. Starts with letters,
CMPS 1371 Introduction to Computing for Engineers CONDITIONAL STATEMENTS.
CONTROLLING PROGRAM FLOW
Lesson NUMERIC-FIELDPIC 9(5). 05 ALPHANUMERIC-FIELDPIC X(5).... IF NUMERIC-FIELD = 10...(valid entry) IF NUMERIC-FIELD = ‘10’... (invalid entry)
Computer Science 111 Fundamentals of Programming I Making Choices with if Statements.
Chapter 5 - VB 2005 by Schneider1 Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
PROBLEM SOLVING & ALGORITHMS CHAPTER 5: CONTROL STRUCTURES - SELECTION.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
MULTIPLE ALTERNATIVES IF… THEN… ELSEIF SELECT CASE.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Making Decisions.
Basic Control Structures
Agenda Basic Logic Purpose if statement if / else statement
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
The IF-statements 31-Jan-2005 Venkatesh Ramamoorthy.
Introduction to Engineering MATLAB - 13 Agenda Conditional statements  If – end  If – else – end  if – elseif – else - end.
Review if imag(x) > 0 fprintf('Sorry, but I don''t understand complex numbers.\n'); return end if x < 10 % leave this out, type the next line first, and.
Chapter Making Decisions 4. Relational Operators 4.1.
Digital Image Processing Lecture 6: Introduction to M- function Programming.
Digital Image Processing Introduction to M-function Programming.
Structured Programming II: If Statements By the end of this class you should be able to: implement branching in a program describe and use an “if” statement.
1 Agenda If Statement True/False Logical Operators Nested If / Switch Exercises & Misc.
Conditional Logic in MATLAB By Bruce Raine. How to do a basic IF – END structure in MATLAB if MATLAB Commands end i.e. do the MATLAB commands if the conditional.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
ARITHMETIC OPERATORS COMPARISON/RELATIO NAL OPERATORS LOGIC OPERATORS ()Parenthesis>Greater than &&And ^Exponentiation=>=
Chapter 2 Excel Fundamentals Logical IF (Decision) Statements Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
1 Structured Programming EEN170 Programming in MATLAB.
Today… Operators, Cont. Operator Precedence Conditional Statement Syntax. Winter 2016CISC101 - Prof. McLeod1.
Making Choices with if Statements
Sequence, Selection, Iteration The IF Statement
Chapter 4: Making Decisions.
Chapter 4 MATLAB Programming
Chapter 4: Control Structures
If statement.
Selection Statements Chapter 4 Attaway MATLAB 4E.
Logical Operations In Matlab.
Conditional Statements
Conditional Logic Presentation Name Course Name
Controlling Program Flow
Chapter 5 Decisions.
Relational and Logical Operators
Relational and Logical Operators
Selection Statements Chapter 4 Attaway MATLAB 5E.
REPETITION Why Repetition?
Presentation transcript:

Programming with MATLAB

Relational Operators

The arithmetic operators has precedence over relational operators

Logical Operators

Order of precedence for operators

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

The if statement End Start

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

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

The else statement

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

The elseif statement

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

Nested if statement =

This statement gives the same result as the previous one =

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

Examples