ECE 1304 Introduction to Electrical and Computer Engineering

Slides:



Advertisements
Similar presentations
Bernstein’s Conditions. Techniques to Exploit Parallelism in Sequential Programming Hierarchy of levels of parallelism: Procedure or Methods Statements.
Advertisements

CMPS 1371 Introduction to Computing for Engineers
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Control Structures Nested ifs, switch statements.
Fall 2004ENGR 111A MatLab – Palm Chapter 4, Part 2 The if and switch structure Class 10.1 Sections: 4.4 and 4.6.
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
Lesson 4: Basic Algorithm Tools If, While Do For Loop, Else, Switch Case.
MATLAB Loops and Branching.
ENGG 1801 Engineering Computing MATLAB Lecture 2: Background for Week 4 Tutorial Simple Programming in MATLAB.
Branches and Loops Selim Aksoy Bilkent University Department of Computer Engineering
Precedence Parentheses Arithemetic ^ * / + - (exception logical not ~ ) Relational > =
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
General Computer Science for Engineers CISC 106 Lecture 05 Dr. John Cavazos Computer and Information Sciences 2/20/2009.
Precedence Parentheses Arithemetic ^ * / + - (exception logical not ~ ) Relational > =
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.
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
February 21, 2005 Lecture 10 - By Paul Lin 1 CPET 190 Problem Solving with MATLAB Lecture 10
How to think through your program [ principles of good program design ] Rachel Denison MATLAB for Cognitive Neuroscience ICN, 13 December 2007.
Selection Programming EE 100. Outline introduction Relational and Logical Operators Flow Control Loops Update Processes.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
ENG 1181 College of Engineering Engineering Education Innovation Center MAT – Conditional Statements Topics: 1.Conditional statements if-end if-else-end.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
CMPS 1371 Introduction to Computing for Engineers CONDITIONAL STATEMENTS.
CMPS 1371 Introduction to Computing for Engineers MatLab.
ENGR-25_Programming-3.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.
Synthesis ENGR 1181 MATLAB 11. Topics  No new material  Covers topics that will be on the Midterm 2 Exam MATLAB 01 – Program Design MATLAB 02 – Introduction.
Conditionals CS 103 February 16, Blast from the Past: C14 Dating Problem Statement: Calculate the age of a fossil from its C-14 radioactivity Problem.
Control Structures CPS120: Introduction to Computer Science Lecture 5.
Advanced Program Design. Review  Step 1: Problem analysis and specification –Specification description of the problem’s inputs and output –Analysis generalize.
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
ENG 1181 College of Engineering Engineering Education Innovation Center P. 1 MAT - Conditional Statements Topics Covered: 1. if based conditional statements.
ENGR-25_Programming-4.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 1 Bruce Mayer, PE Licensed Electrical.
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.
1 ECE 1304 Introduction to Electrical and Computer Engineering Section 1.7 Linear Algebra with MATLAB.
Digital Image Processing Lecture 6: Introduction to M- function Programming.
Digital Image Processing Introduction to M-function Programming.
Programming Numerical Computing with. MATLAB for Scientists and Engineers.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
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.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 4 Monday 06 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
Loops and Conditional Statements Dr.Abbas Lab 4 1ENG. Ahmad Alaql.
Matlab Programming for Engineers
ITEC 2600 Introduction to Analytical Programming
ECE 1304 Introduction to Electrical and Computer Engineering
Computer Application in Engineering Design
The switch Statement, and Introduction to Looping
Unit-1 Introduction to Java
Matlab Training Session 4: Control, Flow and Functions
ECE 1304 Introduction to Electrical and Computer Engineering
Chapter 4 MATLAB Programming
Selection Statements by Ahmet Sacan
ENGG 1801 Engineering Computing
Introduction to Programming for Mechanical Engineers (ME 319)
Control Structures.
Introduction to MATLAB
Topics discussed in this section:
CPS120: Introduction to Computer Science
Introduction to pseudocode
Introduction to Matlab LAB 4
MatLab – Palm Chapter 4, Part 2 The if and switch structure
MatLab – Palm Chapter 4, Part 2 The if and switch structure
Conditional Statements
Selection Statements Chapter 3.
CPS120: Introduction to Computer Science
ME 123 Computer Applications I Lecture 11: More on For loop 3/27/03
Announcements Exercise Sets 2 and 3 Due Thursday.
Presentation transcript:

ECE 1304 Introduction to Electrical and Computer Engineering Section 1.10 Program Structures in MATLAB

What is a Computer Program? A series of commands that instruct the computer to take information and do something useful with it.

Simple Procedural Program Start Input Data Perform Calculations Output Data End

Program with a Branching Structure Start Input Data 1 Option 1 Calculations ? Option 0 Calculations Output Data End

Program with a Branching Structure 1 ? 1 ? ? 1

Program with a Branching Structure 1 ? 1 1 ? ?

Program with a Looping Structure Start Input Data Loop Calculations 1 ? Output Data End

A Menu Driven Structure Method Main Menu 1. Option 1 2. Option 2 End Input Choice? Start 1 1 ? Option 1 1 2 ? Option 2 1 End ? End

Programming Structures in MATLAB MATLAB provides for programming structures using Conditional Statements Loops

Conditional Statements The general form for conditional statements is if (conditional_expression) statements end The conditional expressions use one of the relational operators, ==, >, >=, etc.

Conditional Statements The general form for conditional statements is if (conditional_expression_1) statements_1 elseif (conditional_expression_2) statements_2 else statements_3 end The conditional expressions use one of the relational operators, ==, >, >=, etc.

Example Conditional Statements Assuming x has a scalar value if (x >= 0) y = sqrt(x) end else y = -sqrt(-x)

Example Conditional Statements Assuming x has a scalar value if (x >= 25) y = 50*sqrt(x) elseif (x >= 0) y = 10*x else y = 0 end

Loops MATLAB has two structures for loops: for (counter = start:increment:end) statements end while (conditional_expression)

Example Loops m = 0; x(1) = 10; for k = 2:3:11; m = m + 1; x(m+1) = x(m) + k^2; end

Example Loops x = 5; k = 0; while (x < 25); k = k + 1; y(k) = 3*x; x = 2*x-1; end

Switch – Case Structure switch switch_expression case case_expression statements ... otherwise end

Switch – Case Structure n = input('Enter a number: '); switch n case -1 disp('negative one') case 0 disp('zero') case 1 disp('positive one') otherwise disp('other value') end