The week of 12

Description
Engage!!!
Categories
Published

View again

All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
Share
Transcript
1 WELCOME EF 105 Fall 2006 Week 12  2 Topics: 1.Program Flows ã More on loops (While)  3 MATLAB program Structures Control Structures In the last lecture three types of control structures were described: ã  Straight line control ã  Conditional control (or branching structures) ã  Iterative control (or looping structures) Conditional structures were covered in the last lecture. The focus of this lecture will be iterative structures. Iterative Structures MATLAB offers two types of iterative structures: ã  for loops  –   primarily used to execute a block of statements a specified number of times ã  while loops  –   used to execute a block of instructions while a certain logical test is true  4 The for   loop The for loop is used to execute a block of statements a specified number of times. It has the form shown to the right. for loopVar = loopVector Command 1 Command 2 …  Command n end Example Evaluate the following summation:    101i3 i Sum >> for1 Sum = 3025 >> for2 Sum = 3025 >> % filename: for1.m % Example: Use a for loop to find sum(i^3) for i = 1 to 10. Sum = 0; %Initialize variable to zero for i = 1:1:10 Sum = Sum + i^3; end fprintf('Sum = %0.0f\n',Sum); % filename: for2.m % Example: Use a for loop to find sum(i^3) for i = 1 to 10. Sum = 0; %Initialize variable to zero for i = [1,2,3,4,5,6,7,8,9,10] Sum = Sum + i^3; end fprintf('Sum = %0.0f\n',Sum); Results:

Jul 23, 2017

CV.pdf

Jul 23, 2017
Search
Similar documents

View more...
Tags

Related Search