Chapter 8: MuPAD Programming I Conditional Control and Loops MATLAB for Scientist and Engineers Using Symbolic Toolbox.

Slides:



Advertisements
Similar presentations
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Advertisements

Chapter 6: MuPAD Objects II Sequence, List, Set, Function MATLAB for Scientist and Engineers Using Symbolic Toolbox.
CMPS 1371 Introduction to Computing for Engineers
CHAPTER 5: LOOP STRUCTURES Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
ITEC113 Algorithms and Programming Techniques
COMP 14 Introduction to Programming Miguel A. Otaduy May 21, 2004.
Loop Statements (Iteration). Iteration  A portion of a program that repeats a statement or group of statements is called a loop.  Each repetition of.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Chapter 4 MATLAB Programming Logical Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
INTRODUCTION TO PYTHON PART 3 - LOOPS AND CONDITIONAL LOGIC CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
Agenda Control Flow Statements Purpose test statement if / elif / else Statements for loops while vs. until statements case statement break vs. continue.
Python Control Flow statements There are three control flow statements in Python - if, for and while.
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Chapter 9: MuPAD Programming II Procedures MATLAB for Scientist and Engineers Using Symbolic Toolbox.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Chapter 5 Loops. Overview u Loop Statement Syntax  Loop Statement Structure: while, for, do-while u Count-Controlled Loops u Nested Loops u Loop Testing.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
ITEC113 Algorithms and Programming Techniques
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
Overview of Java Loops By: Reid Hunter. What Is A Loop? A loop is a series of commands that will continue to repeat over and over again until a condition.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (for) Outline 4.1Introduction 4.2The.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
Control Structures II: Repetition.  Learn about repetition (looping) control structures  Explore how to construct and use count-controlled, sentinel-controlled,
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Matlab Programming for Engineers
Looping ROBERT REVAES. Logical Operators  && AND  Both have to be true for it to evaluate to be true.  || OR  One or the other has to be true for.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Midterm Review Important control structures Functions Loops Conditionals Important things to review Binary Boolean operators (and, or, not) Libraries (import.
September 7, 2004ICP: Chapter 3: Control Structures1 Introduction to Computer Programming Chapter 3: Control Structures Michael Scherger Department of.
Repetition Intro to Computer Science CS1510 Dr. Sarah Diesburg.
The If Statement There are no switch statements in Python. You need to use just if statements. There are no switch statements in Python. You need to use.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 5 Control Structures II: Repetition.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Java Programming: From Problem Analysis to Program Design, 3e Chapter 5 Control Structures II: Repetition.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2B) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Python – Part 4 Conditionals and Recursion. Conditional execution If statement if x>0:# CONDITION print (‘x is positive’) Same structure as function definition.
Learning Javascript From Mr Saem
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
PH2150 Scientific Computing Skills Control Structures in Python In general, statements are executed sequentially, top to bottom. There are many instances.
Control Flow (Python) Dr. José M. Reyes Álamo.
Chapter 4 Repetition Statements (loops)
Repetition Structures Chapter 9
Chapter 3: Decisions and Loops
Chapter 4 MATLAB Programming
Warm-up Program Use the same method as your first fortune cookie project and write a program that reads in a string from the user and, at random, will.
CiS 260: App Dev I Chapter 4: Control Structures II.
JavaScript: Control Statements.
Agenda Control Flow Statements Purpose test statement
Introduction to MATLAB
The Linux Command Line Chapter 29
Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CPS120: Introduction to Computer Science
CSC215 Lecture Flow Control.
CSC215 Lecture Control Flow.
Logical Operations In Matlab.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Program Flow.
Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski.
CSC215 Lecture Control Flow.
Presentation transcript:

Chapter 8: MuPAD Programming I Conditional Control and Loops MATLAB for Scientist and Engineers Using Symbolic Toolbox

You are going to See that MuPAD provides flow control mechanism, such as if and loops Get to know how to use if and case statements Use for, while, repeat statements to iterate various loops 2

type and testtype Useful for checking some conditions 3 Cf. domtype() For all available Types

IF statement if condition 4 if condition – else x<0 S1 x<0 S1 T F S2 T F S1 S2

Multiple Conditions Logical Operations 5 and or not xor ==>

F F if – elif – else – end_if F Nested IF 6 if S1 S2 T elif S3 S4 T T S1 S2 S3 S4

Case Statement 7 Define a new procedure.

Return Value Result of the last executed command 8 Abs is a function. One of them becomes the return value. One of them becomes the return value.

Displaying Intermediate Results No automatic display inside conditional statements. Use print to display something. 9

Exercise In if statements the system evaluates composite conditions with Boolean operators one after the other. The evaluation routine stops prematurely if it can decide whether the final result is TRUE or FALSE (“lazy evaluation”). Are there problems with the following statements? What happens when the conditions are evaluated? 10

For Loops : Fixed No. of Iterations for loop with step 11

For Loops Down to Lists, Matrices 12

While and Repeat while Repeat 13

Nested Loops Loop in a Loop 14

Exiting a Loop break – exit from the nearest loop 15 Empty List List Concatenation

Exercise Write the expected output from the previous commands without using MuPAD. 16

Skipping Part of Iteration next 17 Skip this. Go to the end of the loop. Skip this. Go to the end of the loop.

Return Value of a Loop The result of the last executed statement Use a colon to suppress displaying the return value. 18

Key Takeaways Now, you are able to control a conditional execution of a set of statements using if and case, use for loop to repeat some actions for a fixed number of times, check loop exit condition using while and repeat – until statements, and to control looping actions using next and break statements. 19

Notes 20