EGR 103/Fall 2017/Lab 3
- In 3.4.2, there was a line that said "...grabbing every ninth column and sixteenth row." which should be "grabbing every ninth row and sixteenth column."
This lab involves loading data sets, making graphs and images, and analyzing data sets in terms of averages and extrema. Note: every script for this week has been started for you - be sure to look at the files you copied over and work from there. You are responsible for adding the community standard to the top - you can use either the one where you created the code yourself or the one where the code is based on something I gave you.
See main EGR 103 page for links to these
3.3 Getting Started
Same as it ever was.
3.4.1 Random Numbers
Note that you have the code for getting a NetID, converting the NetID to a seed for the random number generator, and calculating the number of bins for the histogram. You will need to change the
N = 0 line to get input from the user.
could prove useful here! Note: the hist command should be run without assigning the results to a variable. That is, you will have code similar to
and not code similar to
something = hist(a,b)
because the second version will not graph a histogram - it will tell you the bin counts but won't graph them!
Also, you will be using
fprintf to print an integer, a strong, and six numbers using scientific notation. See
along with pages 62-63 in Chapra if the class notes are insufficient.
Finally, use the commands
to generate your random numbers. The random command is something else entirely. Though we discussed these in class, for more information see Chapra 14.2.1 and 14.2.2 (but keep in mind this is 11 chapters past our reading so some of what they discuss is more complex than we need right now!).
On checking your work
You can check your work by using
mrg and 5000 as the inputs - you should get the values in the lab handout. However - this assumes you calculated the uniformly distributed numbers first and the normally distributed numbers second!
Calculating them this way gives you:
Information for 5000 random numbers for mrg: Uniform: min: +8.509e-05 avg: +5.020e-01 max: +9.998e-01 Normal: min: -3.396e+00 avg: -5.274e-03 max: +3.911e+00
as listed in the lab manual. If you calculated them in the other order (normal and then uniform), you would get:
Information for 5000 random numbers for mrg: Uniform: min: +6.652e-05 avg: +5.004e-01 max: +9.999e-01 Normal: min: -3.513e+00 avg: +9.290e-03 max: +3.592e+00
and the histograms will be slightly different as well. We will accept either set of answers!
3.4.2 Hidden Images
Note that you have the code to load, display, title, and save the original array. You also have the code to create a new figure and save a second figure. For that one, you need to fill in the space between starting the figure and saving it. Think about how to extract every 9th row and every 16th column from the original matrix. For instance, if you wanted to pull every even row and every third column out of a matrix called MyNumbers, you could write
NewMatrix = MyNumbers(2:2:end, 1:3:end);
Once you have done that, apply code that is very similar to that for the original data set. After that, think about how you are going to experiment with different starting points to find the other hidden images (another hint - there are more than two hidden images).
Also - some code is nearly repeated. Learn how to copy and paste in MATLAB by select-dragging the code you want to copy, pointing to where you want the copy, and middle clicking. Later in the course we will look at writing functions to run similar codes, but for now, having some copies will work.
3.4.3 Chapra 2.18-2.19
You can put the code for both graphs in a single script. The commands for starting and saving figures are in the skeleton already. This problem is similar to Cantilever in that you will be producing a graph that has both data points and a model line - the main difference is the model equation is given to you rather than something you would need to find.
3.4.4 Chapra 2.22
The commands for starting and saving the figure are in the skeleton already, as are the commands for breaking the figure into two rows and one column of subplots.
3.4.5 Weather Data Analysis
The commands for starting and saving the figure are in the skeleton already, as are the commands for the diary. There are several things you will have eventually do with this script - just take one little piece at a time and always make sure you have code that works!
This section is not in the lab report but rather has some items in it that span multiple problems in the lab.
- See MATLAB:Diary for more information about diaries. Your will be brought into your lab report with the
listinginputcommand in LaTeX.
-depscto print in color,
-depsfor black and white.