


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These lecture notes from week 4 of the engineering analysis and matlab course cover the concepts of looping in matlab, including the syntax and examples of for-end and while-end loops. The notes also include activities and practical examples.
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Week 4 Lecture notes: 9/16/
MATLAB Programming (Engineering Analysis and MATLAB 7 - Chapter 8 p 233-240)
Goals:
Notes: -When we started MATLAB, we started with the SEQUENCES, which were just a series of commands executed one after another
-Last week we introduced a selection structure that allowed for relational or logical operators to drive the direction in which the program proceeds
-Examples of these selection structures?
-If we need a program to proceed multiple times consider using a Repetition Structure
Repetition Structures - also known as a loop, causes a group of statements to be executed multiple times if needed. The number times executed depends on a counter or a logical condition. Understanding looping is required for fundamental understanding of programming!
Loop can be executed 0, 1, or multiple times depending on a counter or logical condition
For-end loops (p 233): Used when you know how many times you need to repeat a set a commands. ¾ SYNTAX For index = expression (generally a vector, and the statements are repeated as many times as there are columns in the expression matrix) MATLAB statements (instructions that will be repeated) end ¾ Any variable can be used as a loop index statement, but k is often used ¾ k is an integer ¾ It is in the form k = initial value:increment:limit value (looks like when we generate a vector matrix).
¾ Activity #1 - p 233. Demonstrate a for loop to calculate 5 raised to the 100 th power total = 1; %sets an initial condition for k=1: total = total*5 %do not suppress the output here to see how it runs end
answer of 5^100
¾ Study the for loop rules p 234
Assume this Program starts at 8 am at Kure Beach
time=8 % sets the initial condition - 8 means 8:00 am while (time<=15) % 1500 means 15:00 hours or 3:00pm if rain >= 0. Collect sample Deliver sample to Tritest Shut off power to sampler Leave power on to measure flow time= end time=time+
end
Go home to escape Hanna
End of program
More in-depth discussion of for loop indexing if time permits