For Loops 1 ENGR 1181 MATLAB 8. For Loops and Looped Programming in Real Life Looping within programs has long been a useful tool for completing mundane.

Slides:



Advertisements
Similar presentations
Looping Structures: Do Loops
Advertisements

Array Operations ENGR 1181 MATLAB 4. Aerospace Engineers use turbulence data to calculate how close other planes can fly near the wake of a larger plane.
2D Plots 1 ENGR 1181 MATLAB 12.
Programming with Microsoft Visual Basic th Edition
Input and Output ENGR 1181 MATLAB 5. Input and Output In The Real World Script files (which provide outputs given inputs) are important tools in MATLAB.
Flow Charts, Loop Structures
CMPS 1371 Introduction to Computing for Engineers
Program Design ENGR 1181 MATLAB 11. MATLAB Program Design in Real Life Complex manufacturing processes require careful logic mapping to determine what.
 Control structures  Algorithm & flowchart  If statements  While statements.
Repeating Actions While and For Loops
ITC 240: Web Application Programming
MatLab – Palm Chapter 4, Part 3 For and While Loops
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Pseudocode and Algorithms
Chapter 4 Loops and Character Manipulation Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Precedence Parentheses Arithemetic ^ * / + - (exception logical not ~ ) Relational > =
Control Structures - Repetition Chapter 5 2 Chapter Topics Why Is Repetition Needed The Repetition Structure Counter Controlled Loops Sentinel Controlled.
Loops are MATLAB constructs that permit us to execute a sequence of statements more than once. There are two basic forms of loop constructs: i. while.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Agenda Control Flow Statements Purpose test statement if / elif / else Statements for loops while vs. until statements case statement break vs. continue.
For Loops 2 ENGR 1181 MATLAB 9. For Loops and Looped Programming in Real Life As first introduced last lecture, looping within programs has long been.
Functions 1 ENGR 1181 MATLAB 14.
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 6.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
MATLAB FUNDAMENTALS: CONTROL STRUCTURES – LOOPS HP 100 – MATLAB Wednesday, 10/1/2014
Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined.
Loops CS 103 February 19, 2007 Presented by Nate.
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
MAT 4725 Numerical Analysis Section 1.4 Loops with “do” statements
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
read and learn from example loop programs develop modular program
Today’s Announcements Assignment 8 is due Project 2 is due 7/27/04 We will be skipping chapter 22 Test 3 (chapters 18-21) will be on 7/29/04 Tip of the.
2D Plots 2 ENGR 1181 MATLAB 13. Plotting in the Real World 2D plots generated by MATLAB can be used in a variety of fields, including the one shown here,
While Loops ENGR 1181 MATLAB 10.
Array Creation ENGR 1181 MATLAB 2. Civil engineers store seismic data in arrays to analyze plate tectonics as well as fault patterns. These sets of data.
Introduction to Loops Iteration Repetition Counting Loops Also known as.
Matlab Programming for Engineers
ENG College of Engineering Engineering Education Innovation Center 1 Basic For Loops in MATLAB Programming in MATLAB / Chapter 6 Topics Covered:
Array Operations ENGR 1181 MATLAB 4.
Repetition Statements (Loops) The do while Loop The last iteration structure in C++ is the do while loop. A do while loop repeats a statement or.
Array Creation ENGR 1187 MATLAB 2. Today’s Topics  Arrays: What are they?  Vectors  Matrices  Creating Arrays.
Excel Graphing ENGR 1181 Class 5. Why use Excel?  Excel is a powerful spreadsheet program that can be used for: Creating graphical displays of data Performing.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Lecture 15: Course Review BJ Furman ME 30 16MAY2011.
EGR 115 Introduction to Computing for Engineers Loops and Vectorization – Part 1 Monday 13 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Array Accessing and Strings ENGR 1187 MATLAB 3. Today's Topics  Array Addressing (indexing)  Vector Addressing (indexing)  Matrix Addressing (indexing)
Beginning Programming for Engineers Matlab Conditional Computation.
Logical Expressions ENGR 1181 MATLAB 6. Logical Expressions in Real Life Sorting objects in manufacturing processes can be accomplished automatically.
EE 201 1C10-2 Spring 2012 LOOPS For.  Achieve Comprehension LOL of using Loops in programming. Class Learning Objectives 2C10-2 Spring 2012.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Computer Application in Engineering Design
Chapter 4 MATLAB Programming
CS1371 Introduction to Computing for Engineers
( Iteration / Repetition / Looping )
Agenda Control Flow Statements Purpose test statement
Control Structures - Repetition
Chapter 5 Repetition.
MATLAB – Basic For Loops
Looping and Random Numbers
Types of Flow of Control
Array Creation ENGR 1181 MATLAB 02.
Print the following triangle, using nested loops
Week 7: Computer Tools for Problem Solving and Critical Thinking
LOOPS For EE 201 C10-1 SPRING 2012.
Electrical and Computer Engineering Department SUNY – New Paltz
Presentation transcript:

For Loops 1 ENGR 1181 MATLAB 8

For Loops and Looped Programming in Real Life Looping within programs has long been a useful tool for completing mundane tasks over and over again. The focus of today’s lesson is fixed number looping although later you will learn about indefinite looping (while looping). Internal combustion engines use a combination of these loops for controlling the spark plugs and valves during a four stage cycle. The engine completes these four stages (for loop) while the car is engine is running indefinitely (while loop, to be learned later).

Today's Learning Objectives  After today’s class, students will be able to: Explain the iterative nature of loops. Use loops properly for repetitive processes, including the utilization of loop indices as counters and variables.

What is a Loop ?  A loop allows a group of commands in a program to be repeated.  Each repetition of the loop is called a pass.  Either the number of passes can be fixed.  Or the loop can be terminated after some condition is satisfied.

Examples of basic for–end Loops for k = 1:3 disp(k) end Output: 1 2 3

X=[5, 10, 15, 20]; for i = 1: length(X) disp(X(i)) end Examples of basic for–end Loops Output:

for–end loops with vectors v = [ ] ; for k = 1 : 4 vs(k) = v(k)^2 end Output: vs = 4 vs = 4 16 vs = vs = Create the vector v = [ ]. Calculate and print the square of each element.

Additional Example  Calculate the factorial of integers 1 through 5 inclusive. clc clear %This script file calculates the factorial of a number %Declare the number you wish to calculate the factorial for n = 5; %Calculate factorial using a for loop x = 1; for i = 1:n x = x*i; end fprintf(‘The factorial of %i is %i\n’,n,x)

Important Takeaways  A loop allows a group of commands to be repeated.  A for loop repeats a specified number of times and the loop index variable determines when the for loop ends.  The for loop index variable can also be used to index values from arrays.

Preview of Next Class  For Loops 2 Review of basic for loops Nesting conditional statements in for loops ‘Break’ and ‘Continue’ Loops

What’s Next?  Review today’s Quiz #08  Open the in-class activity from the EEIC website and we will go through it together.  Then, start working on MAT-08 homework.  Prepare for next class by reading about computer problem solving in MATLAB.