MATLAB Laboratory 10/07/10 Lecture. Chapter 7: Flow Control in Programs
|
|
- Imogen Atkinson
- 5 years ago
- Views:
Transcription
1 MATLAB Laboratory 10/07/10 Lecture Chapter 7: Flow Control in Programs Lisa A. Oberbroeckling Loyola University Maryland L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 1 / 17
2 Relational and Logical Operators Both operators take on form expression1 OPERATOR expression2 and evaluate to either TRUE (1) or FALSE (0) L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 2 / 17
3 Relational and Logical Operators Both operators take on form expression1 OPERATOR expression2 and evaluate to either TRUE (1) or FALSE (0) Relational operators: < > <= <= == = L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 2 / 17
4 Relational and Logical Operators Both operators take on form expression1 OPERATOR expression2 and evaluate to either TRUE (1) or FALSE (0) Relational operators: < > <= <= == = Example >> 1 < 2 ans = 1 >> 1 > 2 ans = 0 L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 2 / 17
5 Relational and Logical Operators Both operators take on form expression1 OPERATOR expression2 and evaluate to either TRUE (1) or FALSE (0) Relational operators: < > <= <= == = Example >> 1 < 2 ans = 1 >> 1 > 2 ans = 0 The relational operators produce matrices of 0s and 1s if one of the arguments is a matrix. L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 2 / 17
6 Logical Operators &, && AND (eager version,short-circuit version), OR (eager version, short-circuit version) NOT xor Exclusive OR all TRUE if all elements of vector are nonzero any TRUE if any elements of vector are nonzero L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 3 / 17
7 Logical Operators &, && AND (eager version,short-circuit version), OR (eager version, short-circuit version) NOT xor Exclusive OR all TRUE if all elements of vector are nonzero any TRUE if any elements of vector are nonzero Eager version will evaluate both expressions no matter what. The Short-circuit versions are only good on scalars and will only evaluate the second expression if needed. L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 3 / 17
8 Logical Operators &, && AND (eager version,short-circuit version), OR (eager version, short-circuit version) NOT xor Exclusive OR all TRUE if all elements of vector are nonzero any TRUE if any elements of vector are nonzero Eager version will evaluate both expressions no matter what. The Short-circuit versions are only good on scalars and will only evaluate the second expression if needed. Pros and cons to each version in complicated programs - search for Short-circuit evaluation on Wikipedia for examples. L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 3 / 17
9 Logical Operators &, && AND (eager version,short-circuit version), OR (eager version, short-circuit version) NOT xor Exclusive OR all TRUE if all elements of vector are nonzero any TRUE if any elements of vector are nonzero Eager version will evaluate both expressions no matter what. The Short-circuit versions are only good on scalars and will only evaluate the second expression if needed. Pros and cons to each version in complicated programs - search for Short-circuit evaluation on Wikipedia for examples. The eager version of AND, OR, and NOT logical operators produce matrices of 0s and 1s if one of the arguments is a matrix. L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 3 / 17
10 Examples >> x = [-1 1 1]; y = [1 2-3]; >> x>0 & y >0 ans = >> x>0 y>0 ans = >> xor(x>0,y>0) ans = >> any(x>0) ans = 1 >> all(x>0) ans = 0 >> if x>0 && sin(1/x)<0.5 % one use of short-circuit L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 4 / 17
11 Order of Precedence More functions in book! Precedence Operation 1 Parentheses 2 Exponents 3 Logical NOT 4 Multiplication/division 5 Addition/subtraction 6 Relational operators 7 Logical AND (&) 8 Logical OR ( ) L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 5 / 17
12 Flow Control 1 if- L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 6 / 17
13 Flow Control 1 if- 2 if-else- L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 6 / 17
14 Flow Control 1 if- 2 if-else- 3 if-elseif... else- L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 6 / 17
15 Flow Control 1 if- 2 if-else- 3 if-elseif... else- 4 switch L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 6 / 17
16 Flow Control 1 if- 2 if-else- 3 if-elseif... else- 4 switch 5 for L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 6 / 17
17 Flow Control 1 if- 2 if-else- 3 if-elseif... else- 4 switch 5 for 6 while L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 6 / 17
18 Flow Control 1 if- 2 if-else- 3 if-elseif... else- 4 switch 5 for 6 while The first four are conditional statements L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 6 / 17
19 Flow Control 1 if- 2 if-else- 3 if-elseif... else- 4 switch 5 for 6 while The first four are conditional statements The last two are loops L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 6 / 17
20 IF statement if some test expression statement(s) Example if b ~=0 && (a == 5 a==3) y=a/b; z=a+b; L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 7 / 17
21 IF ELSE and IF ELSEIF... ELSE if some test expression statement(s) else statement(s) Example if x >= 0 absx = x; else absx = -x; if some test expression statement(s) elseif some test expression statement(s). else statement(s) L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 8 / 17
22 sgn.m function s = sgn(x) % SGN(X) computes the sign or signum of the number X % % LAO if x < 0 s = -1; elseif x > 0 s = 1; else s = 0; L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 9 / 17
23 sgn2.m function s = sgn2(x) % SGN2(X) Computes the sign or signum of the number X. % First checks that X is a number. % LAO if length(x) ~= 1 error( Input of sgn2 function is not a number ) if x < 0 s = -1; elseif x > 0 s = 1; else s = 0; L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 10 / 17
24 Pseudocode and Testing Pseudocode (from dictionary.com) a program code unrelated to the hardware of a particular computer and requiring conversion to the code used by the computer before the program can be used. Pseudocode is especially useful to plan out your program(s) on scratch paper before typing - what variables do you need? What conditional statements need to be done, and how? How to set up the loops, etc. L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 11 / 17
25 Pseudocode and Testing Pseudocode (from dictionary.com) a program code unrelated to the hardware of a particular computer and requiring conversion to the code used by the computer before the program can be used. Pseudocode is especially useful to plan out your program(s) on scratch paper before typing - what variables do you need? What conditional statements need to be done, and how? How to set up the loops, etc. Testing: try and think of easy accuracy checks, but also error checks. L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 11 / 17
26 SWITCH statement switch expression case value blah blah case value blah blah. otherwise blah blah L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 12 / 17
27 SWITCH statement switch expression case value blah blah case value blah blah. otherwise blah blah switch mod(n,2) case 0 disp( n is even! ) case 1 disp( n is odd! ) otherwise disp( n is not an integer! ) L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 12 / 17
28 SWITCH statement switch expression case value blah blah case value blah blah. otherwise blah blah switch mod(n,2) case 0 disp( n is even! ) case 1 disp( n is odd! ) otherwise disp( n is not an integer! ) This can be easier in some instances than an if-elseif-else statement L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 12 / 17
29 FOR loop for indexvariable = a:i:b MATLAB command(s) L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 13 / 17
30 FOR loop for indexvariable = a:i:b MATLAB command(s) indexvariable does not need to be declared before; it can be new (and probably should be new) L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 13 / 17
31 FOR loop for indexvariable = a:i:b MATLAB command(s) indexvariable does not need to be declared before; it can be new (and probably should be new) a:i:b or a:b has the indexvariable start at a and at (or going no further than) b, with an increment of i. (remember, if the increment is left out, the increment is 1). L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 13 / 17
32 FOR loop for indexvariable = a:i:b MATLAB command(s) indexvariable does not need to be declared before; it can be new (and probably should be new) a:i:b or a:b has the indexvariable start at a and at (or going no further than) b, with an increment of i. (remember, if the increment is left out, the increment is 1). indexvariable = vector also works (see forex2.m) L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 13 / 17
33 FOR loop for indexvariable = a:i:b MATLAB command(s) indexvariable does not need to be declared before; it can be new (and probably should be new) a:i:b or a:b has the indexvariable start at a and at (or going no further than) b, with an increment of i. (remember, if the increment is left out, the increment is 1). indexvariable = vector also works (see forex2.m) There is no need to increment the indexvariable; that is automatically done L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 13 / 17
34 FOR loop for indexvariable = a:i:b MATLAB command(s) indexvariable does not need to be declared before; it can be new (and probably should be new) a:i:b or a:b has the indexvariable start at a and at (or going no further than) b, with an increment of i. (remember, if the increment is left out, the increment is 1). indexvariable = vector also works (see forex2.m) There is no need to increment the indexvariable; that is automatically done GOOD FOR SERIES! L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 13 / 17
35 Example geomseries.m function s = geomseries(r, n) % GEOMSERIES(N) computes the sum of the geometric sequence % of R from k=0 to N % % LAO s = 0; for k=0:n s = s + r^k; L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 14 / 17
36 WHILE loop PSEUDOCODE while something is true do something L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 15 / 17
37 WHILE loop PSEUDOCODE while something is true do something Statements are executed as long as expression is true. L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 15 / 17
38 WHILE loop PSEUDOCODE while something is true do something Statements are executed as long as expression is true. Nice commands: break and continue read about it (also can be used in FOR loops) L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 15 / 17
39 WHILE loop PSEUDOCODE while something is true do something Statements are executed as long as expression is true. Nice commands: break and continue read about it (also can be used in FOR loops) Something must change so loop isn t infinite! L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 15 / 17
40 WHILE loop PSEUDOCODE while something is true do something Statements are executed as long as expression is true. Nice commands: break and continue read about it (also can be used in FOR loops) Something must change so loop isn t infinite! Read Chapter 7 and the H-drive for more details, syntax and examples! L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 15 / 17
41 While Example whileex1a.m function y = whileex1a(n) % WHILEEX1A(N) adds the numbers from 1 to N % L Oberbroeckling y=0; k=1; while k <= n y = y+k; k = k+1; L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 16 / 17
42 Notes on Nesting Loops and conditional statements can be nested within themselves Keep organized by having nice spacing (USE TABS) nest1 nest2 nest3 L. Oberbroeckling (Loyola University) MATLAB 10/07/10 Lecture 17 / 17
Relational and Logical Operators. MATLAB Laboratory 10/07/10 Lecture. Chapter 7: Flow Control in Programs. Examples. Logical Operators.
Relational and Logical Operators MATLAB Laboratory 10/07/10 Lecture Chapter 7: Flow Control in Programs Both operators take on form expression1 OPERATOR expression2 and evaluate to either TRUE (1) or FALSE
More informationChapter 7: Programming in MATLAB
The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Computer Programming (ECIV 2302) Chapter 7: Programming in MATLAB 1 7.1 Relational and Logical Operators == Equal to ~=
More information7 Control Structures, Logical Statements
7 Control Structures, Logical Statements 7.1 Logical Statements 1. Logical (true or false) statements comparing scalars or matrices can be evaluated in MATLAB. Two matrices of the same size may be compared,
More informationfunction [s p] = sumprod (f, g)
Outline of the Lecture Introduction to M-function programming Matlab Programming Example Relational operators Logical Operators Matlab Flow control structures Introduction to M-function programming M-files:
More informationProgramming for Experimental Research. Flow Control
Programming for Experimental Research Flow Control FLOW CONTROL In a simple program, the commands are executed one after the other in the order they are typed. Many situations require more sophisticated
More informationC/C++ Programming for Engineers: Matlab Branches and Loops
C/C++ Programming for Engineers: Matlab Branches and Loops John T. Bell Department of Computer Science University of Illinois, Chicago Review What is the difference between a script and a function in Matlab?
More informationStarting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to.
Starting Matlab Go to MATLAB Laboratory 09/09/10 Lecture Lisa A. Oberbroeckling Loyola University Maryland loberbroeckling@loyola.edu http://ctx.loyola.edu and login with your Loyola name and password...
More informationENGR 1181 MATLAB 09: For Loops 2
ENGR 1181 MATLAB 09: For Loops Learning Objectives 1. Use more complex ways of setting the loop index. Construct nested loops in the following situations: a. For use with two dimensional arrays b. For
More informationControl Structures. March 1, Dr. Mihail. (Dr. Mihail) Control March 1, / 28
Control Structures Dr. Mihail March 1, 2015 (Dr. Mihail) Control March 1, 2015 1 / 28 Overview So far in this course, MATLAB programs consisted of a ordered sequence of mathematical operations, functions,
More informationRelational and Logical Operators
Relational and Logical Operators Relational Operators Relational operators are used to represent conditions (such as space 0 in the water tank example) Result of the condition is either true or false In
More informationProgramming in MATLAB
2. Scripts, Input/Output and if Faculty of mathematics, physics and informatics Comenius University in Bratislava October 7th, 2015 Scripts Scripts script is basically just a sequence of commands the same
More informationConstraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial
1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the
More informationCOGS 119/219 MATLAB for Experimental Research. Fall 2016 Week 1 Built-in array functions, Data types.m files, begin Flow Control
COGS 119/219 MATLAB for Experimental Research Fall 2016 Week 1 Built-in array functions, Data types.m files, begin Flow Control .m files We can write the MATLAB commands that we type at the command window
More informationMATLIP: MATLAB-Like Language for Image Processing
COMS W4115: Programming Languages and Translators MATLIP: MATLAB-Like Language for Image Processing Language Reference Manual Pin-Chin Huang (ph2249@columbia.edu) Shariar Zaber Kazi (szk2103@columbia.edu)
More informationBoolean Logic & Branching Lab Conditional Tests
I. Boolean (Logical) Operations Boolean Logic & Branching Lab Conditional Tests 1. Review of Binary logic Three basic logical operations are commonly used in binary logic: and, or, and not. Table 1 lists
More informationDr. Khaled Al-Qawasmi
Al-Isra University Faculty of Information Technology Department of CS Programming Mathematics using MATLAB 605351 Dr. Khaled Al-Qawasmi ١ Dr. Kahled Al-Qawasmi 2010-2011 Chapter 3 Selection Statements
More informationMATLAB TUTORIAL WORKSHEET
MATLAB TUTORIAL WORKSHEET What is MATLAB? Software package used for computation High-level programming language with easy to use interactive environment Access MATLAB at Tufts here: https://it.tufts.edu/sw-matlabstudent
More informationStructure Array 1 / 50
Structure Array A structure array is a data type that groups related data using data containers called fields. Each field can contain any type of data. Access data in a structure using dot notation of
More informationIntroduction to MATLAB
Introduction to MATLAB Dr./ Ahmed Nagib Mechanical Engineering department, Alexandria university, Egypt Spring 2017 Chapter 4 Decision making and looping functions (If, for and while functions) 4-1 Flowcharts
More informationSelection Statements
Selection Statements by Ahmet Sacan selection statements, branching statements, condition, relational expression, Boolean expression, logical expression, relational operators, logical operators, truth
More informationFlow Control. Spring Flow Control Spring / 26
Flow Control Spring 2019 Flow Control Spring 2019 1 / 26 Relational Expressions Conditions in if statements use expressions that are conceptually either true or false. These expressions are called relational
More information21-Loops Part 2 text: Chapter ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie
21-Loops Part 2 text: Chapter 6.4-6.6 ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie While Loop Infinite Loops Break and Continue Overview Dr. Henry Louie 2 WHILE Loop Used to
More informationFiles and File Management Scripts Logical Operations Conditional Statements
Files and File Management Scripts Logical Operations Conditional Statements Files and File Management Matlab provides a group of commands to manage user files pwd: Print working directory displays the
More informationAPPM 2460: Week Three For, While and If s
APPM 2460: Week Three For, While and If s 1 Introduction Today we will learn a little more about programming. This time we will learn how to use for loops, while loops and if statements. 2 The For Loop
More informationPractice Reading for Loops
ME 350 Lab Exercise 3 Fall 07 for loops, fprintf, if constructs Practice Reading for Loops For each of the following code snippets, fill out the table to the right with the values displayed when the code
More informationRelational and Logical Statements
Relational and Logical Statements Relational Operators in MATLAB A operator B A and B can be: Variables or constants or expressions to compute Scalars or arrays Numeric or string Operators: > (greater
More informationIntroduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop
Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #16 Loops: Matrix Using Nested for Loop In this section, we will use the, for loop to code of the matrix problem.
More informationMcTutorial: A MATLAB Tutorial
McGill University School of Computer Science Sable Research Group McTutorial: A MATLAB Tutorial Lei Lopez Last updated: August 2014 w w w. s a b l e. m c g i l l. c a Contents 1 MATLAB BASICS 3 1.1 MATLAB
More informationRepetition Structures
Repetition Structures Chapter 5 Fall 2016, CSUS Introduction to Repetition Structures Chapter 5.1 1 Introduction to Repetition Structures A repetition structure causes a statement or set of statements
More informationRelational & Logical Operators
Relational & Logical Operators ELEC 206 Prof. Siripong Potisuk 1 Objectives Learn how to change the flow of execution of a MATLAB program through some kind of a decision-making process within that program
More informationSelection Statements. Chapter 4. Copyright 2013 Elsevier Inc. All rights reserved 1
Selection Statements Chapter 4 Copyright 2013 Elsevier Inc. All rights reserved 1 Recall Relational Expressions The relational operators in MATLAB are: > greater than < less than >= greater than or equals
More informationCondition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.
Repetition Structures Introduction to Repetition Structures Chapter 5 Spring 2016, CSUS Chapter 5.1 Introduction to Repetition Structures The Problems with Duplicate Code A repetition structure causes
More informationMATLAB Operators, control flow and scripting. Edited by Péter Vass
MATLAB Operators, control flow and scripting Edited by Péter Vass Operators An operator is a symbol which is used for specifying some kind of operation to be executed. An operator is always the member
More informationRelational & Logical Operators, Selection Statements
Relational & Logical Operators, Selection Statements by Ahmet Sacan selection statements, branching statements, condition, relational expression, Boolean expression, logical expression, relational operators,
More informationIntroduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices
Introduction to Interactive Calculations Matlab is interactive, no need to declare variables >> 2+3*4/2 >> V = 50 >> V + 2 >> V Ans = 52 >> a=5e-3; b=1; a+b Most elementary functions and constants are
More informationAn Introduction to MATLAB
An Introduction to MATLAB Day 1 Simon Mitchell Simon.Mitchell@ucla.edu High level language Programing language and development environment Built-in development tools Numerical manipulation Plotting of
More informationCS 221 Lecture. Tuesday, 11 October 2011
CS 221 Lecture Tuesday, 11 October 2011 "Computers in the future may weigh no more than 1.5 tons." - Popular Mechanics, forecasting the relentless march of science, 1949. Today s Topics 1. Announcements
More informationSelections. Zheng-Liang Lu 91 / 120
Selections ˆ Selection enables us to write programs that make decisions on. ˆ Selection structures contain one or more of the if, else, and elseif statements. ˆ The end statement denotes the end of selection
More informationRepetition Structures Chapter 9
Sum of the terms Repetition Structures Chapter 9 1 Value of the Alternating Harmonic Series 0.9 0.8 0.7 0.6 0.5 10 0 10 1 10 2 10 3 Number of terms Objectives After studying this chapter you should be
More informationControl Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003
Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an
More informationCS227-Scientific Computing. Lecture 3-MATLAB Programming
CS227-Scientific Computing Lecture 3-MATLAB Programming Contents of this lecture Relational operators The MATLAB while Function M-files vs script M-files The MATLAB for Logical Operators The MATLAB if
More informationIntroduction. C provides two styles of flow control:
Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if
More informationMAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB
MATLAB sessions: Laboratory MAT 75 Laboratory Matrix Computations and Programming in MATLAB In this laboratory session we will learn how to. Create and manipulate matrices and vectors.. Write simple programs
More informationIntroduction to Engineering gii
25.108 Introduction to Engineering gii Dr. Jay Weitzen Lecture Notes I: Introduction to Matlab from Gilat Book MATLAB - Lecture # 1 Starting with MATLAB / Chapter 1 Topics Covered: 1. Introduction. 2.
More informationMini-Matlab Lesson 5: Functions and Loops
Mini-Matlab Lesson 5: Functions and Loops Writing Functions and Scripts Contents Relational and logical operators IF loops FOR loops WHILE loops Scripts and functions Defining and using functions Anonymous
More informationRELATIONAL AND LOGICAL OPERATORS
Contents RELATIONAL AND LOGICAL OPERATORS... Relational Operators... Logical Operators... Using Relational and Logical Operators with Scalars... 2 Using Relational Operators with Numerical Arrays... 5
More informationIntroduction to MATLAB LAB 1
Introduction to MATLAB LAB 1 1 Basics of MATLAB MATrix LABoratory A super-powerful graphing calculator Matrix based numeric computation Embedded Functions Also a programming language User defined functions
More informationIntroduction to Matlab. By: Hossein Hamooni Fall 2014
Introduction to Matlab By: Hossein Hamooni Fall 2014 Why Matlab? Data analytics task Large data processing Multi-platform, Multi Format data importing Graphing Modeling Lots of built-in functions for rapid
More informationDr. Iyad Jafar. Adapted from the publisher slides
Computer Applications Lab Lab 5 Programming in Matlab Chapter 4 Sections 1,2,3,4 Dr. Iyad Jafar Adapted from the publisher slides Outline Program design and development Relational operators and logical
More informationDigital Image Processing
Digital Image Processing Introduction to MATLAB Hanan Hardan 1 Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The name MATLAB is an interactive system
More informationChapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the
More informationComputer Programming ECIV 2303 Chapter 6 Programming in MATLAB Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering
Computer Programming ECIV 2303 Chapter 6 Programming in MATLAB Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering 1 Introduction A computer program is a sequence of computer
More informationOrdinary Differential Equation Solver Language (ODESL) Reference Manual
Ordinary Differential Equation Solver Language (ODESL) Reference Manual Rui Chen 11/03/2010 1. Introduction ODESL is a computer language specifically designed to solve ordinary differential equations (ODE
More informationLecture 3 MATLAB programming (1) Dr.Qi Ying
Lecture 3 MATLAB programming (1) Dr.Qi Ying Objectives Data types Logical operators/functions Branching Debugging of a program Data types in MATLAB Basic: Numeric (integer, floating-point, complex) Logical:
More informationCS302: Self Check Quiz 2
CS302: Self Check Quiz 2 name: Part I True or False For these questions, is the statement true or false? Assume the statements are about the Java programming language. 1.) The result of an expression with
More informationCEMTool Tutorial. Control statements
CEMTool Tutorial Control statements Overview This tutorial is part of the CEMWARE series. Each tutorial in this series will teach you a specific topic of common applications by explaining theoretical concepts
More informationFlow Control. Statements We Will Use in Flow Control. Statements We Will Use in Flow Control Relational Operators
Flow Control We can control when how and the number of times calculations are made based on values of input data and/or data calculations in the program. Statements We Will Use in Flow Control for loops
More informationChapter 3: Programming with MATLAB
Chapter 3: Programming with MATLAB Choi Hae Jin Chapter Objectives q Learning how to create well-documented M-files in the edit window and invoke them from the command window. q Understanding how script
More informationMATLAB provides several built-in statements that allow for conditional behavior if/elseif/else switch menu
Chapter 3 What we have done so far: Scripts/Functions have executed all commands in order, not matter what What we often need: A piece of code that executes a series of commands, if and only if some condition
More informationEL2310 Scientific Programming
Lecture 4: Programming in Matlab Yasemin Bekiroglu (yaseminb@kth.se) Florian Pokorny(fpokorny@kth.se) Overview Overview Lecture 4: Programming in Matlab Wrap Up More on Scripts and Functions Wrap Up Last
More informationThe Many Lessons in Fractals
The Many Lessons in Fractals Lisa Oberbroeckling loberbro@loyola.edu MAA Mathfest Washington, D.C. L. Oberbroeckling (Loyola U MD) Fractals Mathfest, 05 Aug 2015 1 / 15 Course Programming in Mathematics
More informationProgramming 1. Script files. help cd Example:
Programming Until now we worked with Matlab interactively, executing simple statements line by line, often reentering the same sequences of commands. Alternatively, we can store the Matlab input commands
More informationProgramming in MATLAB
Programming in MATLAB Scripts, functions, and control structures Some code examples from: Introduction to Numerical Methods and MATLAB Programming for Engineers by Young & Mohlenkamp Script Collection
More informationProblem One: A Quick Algebra Review
CS103A Winter 2019 Solutions for Week One Handout 01S Problem One: A Quick Algebra Review In the first week of CS103, we'll be doing a few proofs that will require some algebraic manipulations and reasoning
More informationVariables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB:
Contents VARIABLES... 1 Storing Numerical Data... 2 Limits on Numerical Data... 6 Storing Character Strings... 8 Logical Variables... 9 MATLAB S BUILT-IN VARIABLES AND FUNCTIONS... 9 GETTING HELP IN MATLAB...
More informationCSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Functions
1 CSCE 314: Programming Languages Dr. Flemming Andersen Haskell Functions 2 Outline Defining Functions List Comprehensions Recursion 3 Conditional Expressions As in most programming languages, functions
More informationSelection Statements
Selection Statements 1 Introduction Matlab has two basic selection statements: the if statement and the switch statement. The if statement has optional else and elseif. The relational/comparison and logical
More informationEL2310 Scientific Programming
(pronobis@kth.se) Overview Overview Wrap Up More on Scripts and Functions Basic Programming Lecture 2 Lecture 3 Lecture 4 Wrap Up Last time Loading data from file: load( filename ) Graphical input and
More informationVariable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.
MATLAB Introduction Accessing Matlab... Matlab Interface... The Basics... 2 Variable Definition and Statement Suppression... 2 Keyboard Shortcuts... More Common Functions... 4 Vectors and Matrices... 4
More informationCS 221 Lecture. Tuesday, 13 September 2011
CS 221 Lecture Tuesday, 13 September 2011 Today s Agenda 1. Announcements 2. Boolean Expressions and logic 3. MATLAB Fundamentals 1. Announcements First in-class quiz: Tuesday 4 October Lab quiz: Thursday
More informationIntro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming
Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals
More informationChapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2014 Pearson Addison-Wesley. All rights reserved.
Chapter 4 Procedural Abstraction and Functions That Return a Value 1 Overview 4.1 Top-Down Design 4.2 Predefined Functions 4.3 Programmer-Defined Functions 4.4 Procedural Abstraction 4.5 Local Variables
More informationComputer Vision. Matlab
Computer Vision Matlab A good choice for vision program development because Easy to do very rapid prototyping Quick to learn, and good documentation A good library of image processing functions Excellent
More informationME 461 C review Session Fall 2009 S. Keres
ME 461 C review Session Fall 2009 S. Keres DISCLAIMER: These notes are in no way intended to be a complete reference for the C programming material you will need for the class. They are intended to help
More informationREPETITIVE EXECUTION: LOOPS
Contents REPETITIVE EXECUTION: LOOPS... 1 for Loops... 1 while Loops... 6 The break and continue Commands... 8 Nested Loops... 10 Distinguishing Characteristics of for and while Loops Things to Remember...
More informationVariables and Assignments
Variables and Assignments ˆ A variable is used to keep a value or values. ˆ A box which contains something. ˆ In most languages, a statement looks like var = expression, where var is a variable and expression
More informationMAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB
MAT 75 Laboratory Matrix Computations and Programming in MATLAB In this laboratory session we will learn how to. Create and manipulate matrices and vectors.. Write simple programs in MATLAB NOTE: For your
More informationLecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan
Lecture 08-1 Programming in C++ PART 1 By Assistant Professor Dr. Ali Kattan 1 The Conditional Operator The conditional operator is similar to the if..else statement but has a shorter format. This is useful
More informationChapter 4. Flow of Control
Chapter 4. Flow of Control Byoung-Tak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr Sequential flow of control
More informationIntroduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.
Introduction to Visual Basic and Visual C++ Arithmetic Expression Lesson 4 Calculation I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Arithmetic Expression Using Arithmetic Expression Calculations
More informationAttia, John Okyere. Control Statements. Electronics and Circuit Analysis using MATLAB. Ed. John Okyere Attia Boca Raton: CRC Press LLC, 1999
Attia, John Okyere. Control Statements. Electronics and Circuit Analysis using MATLAB. Ed. John Okyere Attia Boca Raton: CRC Press LLC, 1999 1999 by CRC PRESS LLC CHAPTER THREE CONTROL STATEMENTS 3.1 FOR
More informationLECTURE 1. What Is Matlab? Matlab Windows. Help
LECTURE 1 What Is Matlab? Matlab ("MATrix LABoratory") is a software package (and accompanying programming language) that simplifies many operations in numerical methods, matrix manipulation/linear algebra,
More informationProgramming in MATLAB Part 2
Programming in MATLAB Part 2 A computer program is a sequence of computer commands. In a simple program the commands are executed one after the other in the order they are typed. MATLAB provides several
More informationYOLOP Language Reference Manual
YOLOP Language Reference Manual Sasha McIntosh, Jonathan Liu & Lisa Li sam2270, jl3516 and ll2768 1. Introduction YOLOP (Your Octothorpean Language for Optical Processing) is an image manipulation language
More informationRelational Expressions. Boolean Expressions. Boolean Expressions. ICOM 4036 Programming Languages. Boolean Expressions
ICOM 4036 Programming Languages Ch7. Expressions & Assignment Statements Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment
More informationCSE200 Lecture 6: RECURSION
Table of Contents Review of functions (using factorial example)... 1 Recursion... 1 Step by step run through of recursive factorial... 2 Recursion vs. iteration (for and while loops)... 3 Helper functions:...
More informationThese are notes for the third lecture; if statements and loops.
These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern
More informationIntroduction to C Programming
1 2 Introduction to C Programming 2.6 Decision Making: Equality and Relational Operators 2 Executable statements Perform actions (calculations, input/output of data) Perform decisions - May want to print
More informationWhy use MATLAB? Mathematcal computations. Used a lot for problem solving. Statistical Analysis (e.g., mean, min) Visualisation (1D-3D)
MATLAB(motivation) Why use MATLAB? Mathematcal computations Used a lot for problem solving Statistical Analysis (e.g., mean, min) Visualisation (1D-3D) Signal processing (Fourier transform, etc.) Image
More informationREPETITION CONTROL STRUCTURE LOGO
CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of
More informationPhysics 326 Matlab Primer. A Matlab Primer. See the file basics.m, which contains much of the following.
A Matlab Primer Here is how the Matlab workspace looks on my laptop, which is running Windows Vista. Note the presence of the Command Window in the center of the display. You ll want to create a folder
More informationOUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.
1 LECTURE 3 OUTLINES Variable names in MATLAB Examples Matrices, Vectors and Scalar Scalar Vectors Entering a vector Colon operator ( : ) Mathematical operations on vectors examples 2 VARIABLE NAMES IN
More informationMATLAB Laboratory 09/23/10 Lecture. Chapters 5 and 9: Plotting
MATLAB Laboratory 09/23/10 Lecture Chapters 5 and 9: Plotting Lisa A. Oberbroeckling Loyola University Maryland loberbroeckling@loyola.edu L. Oberbroeckling (Loyola University) MATLAB 09/23/10 Lecture
More informationArrays. ˆ An array, is a linear data structure consisting of a collection of elements, each identified by one array index. ˆ For math, arrays could be
Arrays ˆ An array, is a linear data structure consisting of a collection of elements, each identified by one array index. ˆ For math, arrays could be ˆ row vectors: u R 1 n for any positive integer n ˆ
More informationMA 511: Computer Programming Lecture 3: Partha Sarathi Mandal
MA 511: Computer Programming Lecture 3: http://www.iitg.ernet.in/psm/indexing_ma511/y10/index.html Partha Sarathi Mandal psm@iitg.ernet.ac.in Dept. of Mathematics, IIT Guwahati Semester 1, 2010-11 Last
More informationLe L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators
Course Name: Advanced Java Lecture 2 Topics to be covered Variables Operators Variables -Introduction A variables can be considered as a name given to the location in memory where values are stored. One
More informationStokes Modelling Workshop
Stokes Modelling Workshop 14/06/2016 Introduction to Matlab www.maths.nuigalway.ie/modellingworkshop16/files 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 1 / 16 Matlab As part of this crash
More informationCompact Matlab Course
Compact Matlab Course MLC.1 15.04.2014 Matlab Command Window Workspace Command History Directories MLC.2 15.04.2014 Matlab Editor Cursor in Statement F1 Key goes to Help Information MLC.3 15.04.2014 Elementary
More information3.4. FOR-LOOPS 65. for <v a r i a b l e > in < sequence >:
3.4. FOR-LOOPS 65 3.4 For-loops In the previous section we looked at while-loops, Python s basic looping structure. There is a second loop construct in Python called a for-loop. This is more specialized.
More information