Chapter4-33 - IterationControlStructure (Moreon)...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Iteration Control Structure (More on) min / max  Operations sort  Operation And a new (unrelated, but sometimes useful) function  mod()
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Min/Max and Sort Operations MATLAB has functions to do these – min() , max() and sort() , but this is an exercise in algorithm development (logical sequence of steps to solve a problem). Let’s start with min (max is identical except for 1 simple change).
Background image of page 2
Min Operation Problem – Find the minimum value (and its position) in a row vector of an arbitrary number of numbers. To assist in visualization, let’s make a row vector of numbers [3 5 2 4] (except maybe show them vertically) 3 5 2 4 See if you can determine a technique (algorithm) to manually find the minimum value (and its position) in a list (row vector) of numbers (other than “I can see 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
You would (I assume) save the 1st number in position (index) 1 as the smallest. You would then scan the list starting with the 2nd number down until (or if) you found a smaller number than the 1st number If you found a small number than the 1 st , you would replace the 1 st (until then smallest) number with the one you found and replace (until then the smallest number) position with the position of the number you found. You would continue this process until the end of the
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

Chapter4-33 - IterationControlStructure (Moreon)...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online