Difference between revisions of "EGR 103/Spring 2018/Lab 3"
Line 24: | Line 24: | ||
because the second version will not graph a histogram - it will tell you the bin counts but won't graph them! | 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 <code>fprintf</code> to print an integer, a | + | Also, you will be using <code>fprintf</code> to print an integer, a string, and six numbers using scientific notation. See |
help fprintf | help fprintf | ||
− | along with pages 62-63 in Chapra | + | along with pages 62-63 in Chapra. For a deeper dive, go to [https://www.mathworks.com/help/matlab/ref/fprintf.html MATLAB's fprintf reference]. |
Finally, use the commands | Finally, use the commands |
Latest revision as of 15:10, 31 January 2018
Typographical errors
- None yet!
3.1 Introduction
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.
3.2 Resources
See main EGR 103 page for links to these
3.3 Getting Started
Same as it ever was.
3.4 Assignment
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.
help hist
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
hist(a, b)
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 string, and six numbers using scientific notation. See
help fprintf
along with pages 62-63 in Chapra. For a deeper dive, go to MATLAB's fprintf reference.
Finally, use the commands
rand randn
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 Ranged Random Numbers
Several of the test cases have a rather large number of values in them - this is in the hopes that the random numbers you generate nearly span the entire possible range from the minimum to the maximum. Please be sure to use your NetID when running the test program so that you get your own personalized set of results.
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!
General Concepts
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
listinginput
command in LaTeX. - Use
-depsc
to print in color,-deps
for black and white.