Being able to convert an idea to a word description, maybe...

12
Last class we developed the selection sorting algorithm. We start today with developing the bubble sorting algorithm. See the hilighted text below on Wikipedia. This word description is what we want to convert to pseudo-code first, then convert that to Matlab and debug. Being able to convert an idea to a word description, maybe with a sketch, and then to pseudo code, and finally to a working program is the goal of your work in this class!

Transcript of Being able to convert an idea to a word description, maybe...

Page 1: Being able to convert an idea to a word description, maybe ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20170828.pdf · pseudo-code first, then convert that to Matlab

Last class we developed the selection sorting algorithm. We start today with developing the bubble sortingalgorithm. See the hilighted text below on Wikipedia. This word description is what we want to convert topseudo-code first, then convert that to Matlab and debug.

Being able to convert an idea to a word description, maybe with a sketch, and then topseudo code, and finally to a working program is the goal of your work in this class!

Page 2: Being able to convert an idea to a word description, maybe ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20170828.pdf · pseudo-code first, then convert that to Matlab

“repeatedly steps through the list to be sorted...” means that we are going to need a repeat - we want a “for” repeat since we know the size of the list

“compares each pair...and swaps them if they are in the wrong order...” means that we are going to need an “if” decision structure inside our “for” repeat.

“The pass through the list is repeated until...” means that we are going to put the “for” repeat inside an outer repeat - we want a “while” repeat since we don't know how many times to do this.

Now we start converting the word description of the bubble sort algorithm into pseudo code

Being able to convert an idea to a word description, maybe with a sketch, and then topseudo code, and finally to a working program is the goal of your work in this class!

Page 3: Being able to convert an idea to a word description, maybe ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20170828.pdf · pseudo-code first, then convert that to Matlab

A “flag” variable is one whose value stores some state of our program. Similar to puttingup a flag along a train track when there is a passenger waiting, or a flag when there isa letter waiting for pickup in a mail box

Page 4: Being able to convert an idea to a word description, maybe ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20170828.pdf · pseudo-code first, then convert that to Matlab

This is the basic bubble sort algorithm. Since I did this, you should implement atleast one of the optimizations mentioned in the Wikipedia article.

Page 5: Being able to convert an idea to a word description, maybe ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20170828.pdf · pseudo-code first, then convert that to Matlab

One of our homework problems ask us to make subplots. In class we did a couple examples.The inputs to subplot() are, in order, rows of plots, columns of plots, linear index of this plot in thatarray of plots. Here is a plot with 3-row by 1-column subplots. Remember to create a new figure beforeeach main plot (not each subplot) for PUBLISHING your work (we didn’t do that here).

Page 6: Being able to convert an idea to a word description, maybe ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20170828.pdf · pseudo-code first, then convert that to Matlab

Here is a plot with 2-row by 2-column subplots. Remember to create a new figure before each main plot (not each subplot) for PUBLISHING your work (we didn’t do that here).

Page 7: Being able to convert an idea to a word description, maybe ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20170828.pdf · pseudo-code first, then convert that to Matlab

A couple of your homework problems involves saving and loading data from disk. Here is aquick example.

Page 8: Being able to convert an idea to a word description, maybe ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20170828.pdf · pseudo-code first, then convert that to Matlab

NOW TAKE A LOOK AT THE GEO INFO PROJECT in the homework…

Page 9: Being able to convert an idea to a word description, maybe ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20170828.pdf · pseudo-code first, then convert that to Matlab

These numbers are the elevation above or below mean sea level in meters

Page 10: Being able to convert an idea to a word description, maybe ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20170828.pdf · pseudo-code first, then convert that to Matlab

In this code section, we load the data and display it using the image function. There is not good color resolution of the elevations in the default colormap.

Page 11: Being able to convert an idea to a word description, maybe ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20170828.pdf · pseudo-code first, then convert that to Matlab

Here we try using the ‘jet’ colormap. Hmmm. Same bad color resolution….

Page 12: Being able to convert an idea to a word description, maybe ...reactorlab.net/resources-folder/matlab/pdf-link-folder/bb_20170828.pdf · pseudo-code first, then convert that to Matlab

The problem was that the min-max scale of our raw data spans a range outside the range of the image function. So we try the imagesc (image scaled) function and get good color resolution. Read the article atReactorLab.net, Resources, Matlab, More notes, Color resolution with functions image and imagesc