Difference between revisions of "EGR 103/Fall 2023/Lab 3"
(→Summary of Due Dates) |
|||
Line 63: | Line 63: | ||
=== Summary of Due Dates === | === Summary of Due Dates === | ||
− | * End of lab (or at the latest this | + | * End of lab (or at the latest this Friday at 11:59 pm): |
** Group Gradescope Problems | ** Group Gradescope Problems | ||
* Tuesday 10/3 at 10 pm, with technical grace to 11:59 pm: | * Tuesday 10/3 at 10 pm, with technical grace to 11:59 pm: |
Revision as of 11:29, 20 September 2023
Contents
- 1 Typographical errors
- 2 Self-Guided Run-through
- 3 Lab Document Supporting Information
- 3.1 3.1 Introduction
- 3.2 3.2 Resources
- 3.3 3.3 Getting Started
- 3.4 3.4 Notes on figures
- 3.5 3.5 Assignment
- 4 General Concepts
Typographical errors
- None yet.
Self-Guided Run-through
The following will take you through what you need to do during the lab period today. It will generally follow the order of the lab handout with some exceptions.
3.3 Get the files
See EGR 103/Fall 2023/Beginning of Lab and follow those instructions for Lab 3. After you get the files from the public archive, note that every script for this week has a starter file.
3.4 Notes on Figures
- The typical code for making a figure will include the following:
import matplotlib.pyplot # near the top of the script figN = plt.figure(num=N, clear=True) # replace N with a number figN.set_size_inches(6, 8, forward=True) # sets the figure to 6 inches wide and 8 inches tall axN = figN.add_subplot(1, 1, 1) # assuming just 1 subplot; may have more # plotting commands figN.tight_layout() # adjusts figure figN.savefig("FILENAME.ext") # ext will usually be png
3.5.1 Group Gradescope
This week, there are two programs that you should work on in small groups during lab and then submit to a system called Gradescope. Note: both Gradescope problems have already been started and those codes are included in the set you got from Lab03Files
. Be sure to use those starter files!
Accessing Gradescope
To access Gradescope, go the the Canvas site for the class and use the Gradescope link along the left side of the page. If there is not a list of words including Gradescope along the left side, click the hamburger button at the top left of the window. Active assignments should be in the Dashboard section of Gradescope, whereas all assignments will be available through the Assignments section.
Uploading for Gradescope
To turn in an assignment, click the name of the assignment; for this example, imagine that you want to get keep_time.py
checked. Since keep_time.py
is already a part of the files you got for this week, you can try to get the version currently available to you graded. All you need to do is find it and drag it into the "Submit Programming Assignment" panel or click in the "DRAG & DROP" part of the panel and navigate to the code. Once found, click "Upload" and Gradescope will let you know if it got it (or not). If it got it, it will run several tests on it and give you a grade based on that. The starter code will actually succeed for the first test since Gradescope checks what happens if you use 0 seconds as an argument. Every other test will fail!
You can always get back to this testing panel from Gradescope by clicking on the class, then Dashboard, then the assignment. You can see all the times you have submitted answers with the "Submission History" at the bottom left of the results page. Near the top, there is a toggle to look at either the results or the code - if something truly strange happens with the autograder, click the "Code" button to make sure you uploaded the right thing. You can resubmit as many times as you would like before the deadline without penalty. Do not try to hardcode the test answers! Gradescope randomizes how it tests the code. There is more information below on how to get this and the other Group Gradescope assignments done.
Gradescope Grades
Gradescope grades are not immediately transferred to Canvas; usually the grades will show up in Canvas few days after the deadline for those assignments. At the moment, there does not appear to be a way to look at all your grades in Gradescope at once.
3.5.2 Individual Connect
Important: the Connect problems will often show you solutions once you get the problem right; these solutions may differ from what we have been writing in class in a couple ways. First, the book uses pylab
versus matplotlib.pyplot
to make plots. Second, the book uses commands like np.max(A)
to find the maximum value for an array while we will be using A.max()
.
Connect Problems
When you begin an assignment, it will give you assignment details such as how many points are available and when the assignment is due. While these assignments are due by 10 PM ET on the date listed, I will generally give until just before midnight just in case something happens at or just before 10 PM ET on the day it is due. You are allowed as many attempts as needed before the due date. You are also allowed to "Check my work" but please note that checking your work is not the same as submitting your work! Be sure to actually submit when you are ready to turn something in.
When you Continue to the assignment, you will go to the first problem, which for this week is Problem 02.005 (or 2.5). At left, there are icons; you can click them to:
- See the relevant parts of the Chapra book,
- Get a hint about the problem,
- Print the problem, or
- Look at the references for the problem.
For this and other problems in Connect, you may be given numbers in the assignment that are different from the book - use the numbers on Connect for the Connect work.
Once you are done with a question, you can use the navigation section at the bottom center of the screen to change questions. "Next" will take you to the next question and "Prev" will take you to the previous one. If you click on the 3x3 grid, that will show you all the problems in a particular assignment. For this assignment, go ahead and click on the grid and note that there is a set of two chain links between Questions 4 and 5 -- that means that they are linked together and that you are expected to answer Question 4 before moving on to Question 5. If you skip a linked part and Connect does not let you go back, you can simply Submit your answers to that point; when you go back to the assignment, it will let you in to the earlier Questions. There is more information in the lab handout run-through below regarding each of the other problems in the Connect part of the lab for this week.
3.5.3 Individual Lab Report
The individual lab report consists of work that you will document in a manner similar to that of Lab 2. Note that you will be including just the codes and graphs for the final two problems (Chapra 2.12 and Chapra 2.14) in the PDF of your lab report; there will be a brief discussion for the first problem.
Summary of Due Dates
- End of lab (or at the latest this Friday at 11:59 pm):
- Group Gradescope Problems
- Tuesday 10/3 at 10 pm, with technical grace to 11:59 pm:
- Individual Connect Lab 03 assignment
- Individual Lab Report
Lab Document Supporting Information
The following parts of this document follow the sections / subsections in the lab handout.
3.1 Introduction
This lab involves functions and graphs. Every script has been started. That will not always happen.
3.2 Resources
See main EGR 103 page for links to these
3.3 Getting Started
3.4 Notes on figures
- See above
3.5 Assignment
3.5.1 Group Gradescope Problems
P&E 1.31
- Integer division is given by // and the values can be ints or floats or a combination thereof; if either or both of the arguments are floats the answer is a float.
- The remainder operator is given by %.
- Think about how you need to update the number of seconds after accounting for some with hours or minutes.
- Remember to return the three items in a tuple in the correct order.
- Note the starter test code that has been provided for you in the script.
Based on P&E 1.31
- Main thing here is to figure out how to get defaults to work. Remove the
*blah, **more_blah
and replace it with three inputs. Note that two of them need default cases. To put a default case in the parameters of a function, put the local variable name followed by = and a default value. For instance, if your third parameter in the function definition weresecs=17
and you called your function with only two arguments, the function would automatically assign 17 tosecs
. - The test codes do not always have three input parameters when the function gets called, meaning the defaults have to work for the tests to work.
3.5.2 Individual Connect Problems
Chapra 2.12
Your program needs to perform the following tasks:
- Define a function that takes in $$z$$ values and returns $$f(z)$$ values using the equation in the problem.
- In the main part of the script:
- Create a linearly spaced array of 101 $$z$$ values between -4 and 4
- Calculate 101 $$f$$ values using your function and your $$z$$ array
- Find and print the maximum value of $$f$$ using floating point format with four digits after the decimal point. You should use the
f.max()
command to retrieve the maximum value from the $$f$$ array. - Note: for the lab report later, you will need to extend this script to include a graph
Chapra 2.13
Your program needs to perform the following tasks:
- Define a function that takes in $$F$$ and $$x$$ values and returns $$k$$ and $$U$$ values using the equations in the problem.
- In the main part of the script:
- Store the Force ($$F$$) values in an array
- Store the Displacement ($$x$$) values in an array
- Calculate the $$k$$ and $$U$$ values for each pair using your function
- Find and print the maximum value of $$U$$ using floating point format with four digits after the decimal point. You should use the
U.max()
command to retrieve the maximum value from the $$U$$ array.
Chapra 2.14
Your program needs to perform the following tasks:
- Define a function that takes in $$T$$ values in $$^{\circ}C$$ and returns $$\rho$$ values using the equation in the problem.
- Define a function that takes in $$T$$ values in $$^{\circ}F$$ and returns $$T$$ values in $$^{\circ}C$$ using the other equation in the problem.
- In the main part of the script:
- Create an array of temperature values from 32 to 212 $$^{\circ}F$$ with a spacing of 3.6 $$^{\circ}F$$ -- be sure 212 is included!
- Convert those temperatures to $$^{\circ}C$$ and store those values
- Determine values of $$\rho$$ for those temperatures using your function
- Find and print the maximum value of $$\rho$$. You should use the
f.max()
command to retrieve the maximum value from the $$\rho$$ array. You do not need to format the results. - Find and print the temperature in $$^{\circ}C$$ at which that density occurs. The code for this is given - note that the result is an array. You do not need to format the results.
- Note: for the lab report later, you will need to extend this script to include a graph
Chapra 2.21
Your program needs to perform the following tasks:
- Define a function that takes $$A$$, $$m$$, and $$v_t$$ values and returns $$C_D$$ values using the equations in the problem.
- The function should also locally define $$g$$ and $$\rho$$
- In the main part of the script:
- Create arrays for $$A$$, $$m$$, and $$v_t$$ as given in the problem
- Use your function to calculate $$C_D$$ for those arrays
- Tell NumPy to use four digits of precision
- Print out the entire $$C_D$$ array
- Use array methods to find the average, minimum, and maximum values of $$C_D$$ in the array and print those out - they do not need to be formatted any particular way.
3.5.3 Individual Lab Report
Once again, these are individual exercises. You should not look at anyone else's work for this nor should you allow anyone other than a TA or instructor to look at your work. These scripts and graphs will go in a written lab report that will be uploaded to Sakai. There is no autograder for these parts.
3.5.3.1 Sinusoidal Functions
Sometimes the three-part format specifier (color, linestyle if there is one, pointstyle if there is one) will be sufficient to modify how a curve is plotted. If further tweaks are necessary, here are the most common keyword argument used in EGR 103 with the plot command:
- To change the line connecting the data points:
linestyle="STYLE"
orls="STYLE"
whereSTYLE
is one of - -- -. :- This is usually set in the format specifier that comes as the third argument to the plot command
color="COLOR"
orc="COLOR"
- If the color is one of the nine with a nickname, this is usually set in the format specifier that comes as the third argument to the plot command
linewidth=VAL
orlw=VAL
whereVAL
indicates the width of the line
- To change the markers at each data point:
marker="STYLE"
whereSTYLE
is one of the marker styles - see matplotlib.markers at the matplotlib project- This is usually set in the format specifier that comes as the third argument to the plot command
markersize=VAL
orms=VAL
changes the size of the markermarkerfacecolor="COLOR"
ormfc="COLOR"
indicates the color of the interior of the markermarkeredgecolor="COLOR"
ormec="COLOR"
indicates the color of the edge of the marker- Either the face or edge color may be given in the format specifier if one or the other is one of the nine with a nickname, or if both are the same color and one of the nine with a nickname
markeredgewidth=VAL
ormew=VAL
changes the width of the marker edgemarkevery=VAL
changes how often markers are shown - this is useful for using lots of points to make a smooth curve but putting a marker only every so often
- "COLOR" above can mean:
- A string with a single character in it, denoting the nickname for one of the nine colors with nicknames (r, y, g, b, c, m, y, k, or w) (see Base Colors at the matplotlib project)
- A string with a known color name in it (see Tableau Palette and CSS Colors at the matplotlib project)
- A tuple with red-green-blue values represented as three component values (with components between 0 and 1) or as a string with three or six-character hexadecimal values between 0 and f (15) or 00 and ff (255) for each component.
Here are some examples of different ways to represent colors (along with other modifications):
See the Python:Plotting page as well as the matplotlib.pyplot.plot page for information about the additional pieces of information you can give the plt.plot()
(or, in our case, ax.plot()
) command to change sizes and colors.
3.5.3.2 Chapra 2.12
Extend the code you already wrote to create a graph of $$f(z)$$ as a function of $$z$$ for 101 linearly spaced values of $$z$$ between -4 and 4. Be sure to set the size of the figure and use fig.tight_layout()
. Read the lab handout carefully for other details. Save the graph as a .png file.
3.5.3.3 Chapra 2.14
Extend the code you already wrote to create a graph of $$\rho$$ as a function of $$T$$ in $$^{\circ}C$$ for the temperature values specified in the problem statement. Be sure to set the size of the figure and use fig.tight_layout()
. Read the lab handout carefully for other details. Save the graph as a .png file.
General Concepts
This section is not in the lab report but rather has some items in it that span multiple problems in the lab. We will cover these during the lab.
- If your script defines one or more functions, and you want to put test code or the main code in the script, a great way to do that is to put the tester code or main code at the bottom of your script in a section headed by the statement:
if __name__ == "__main__":
- That way the test code will only run when you run the script and not when you (or other programs) import the script.