In [ ]:
# Lesson 20 Individual Assignment
Individual means that you do it yourself. You won't learn to code if you don't struggle for yourself and write your own code. Remember that while you can discuss the general (algorithmic) way to solve a problem, you should not even be looking at anyone else's code or showing anyone else your code for an individual assignment.
Review the Group Work guidelines on Cavas and/or ask an instructor if you have any questions.
Be sure to spell all function names correctly - misspelled functions will lose points (and often break anyway since no one is sure what to type to call it). If you prefer showing your earlier, scratch work as you figure out what you are doing, please be sure that you make a final, complete, correct last function in its own cell that you then call several times to test. In other words, separate your thought process/working versions from the final one (a comment that tells us which is the final version would be lovely).
Every function should have at least a docstring at the start that states what it does (see Lesson3 Team Notebook if you need a reminder). Make other comments as necessary.
Make sure that you are running test cases (plural) for everything and commenting on the results in markdown. Your comments should discuss how you know that the test case results are correct.
Copy your Rbox
class definition from Lesson20 Team below, and quickly double check that it works. (If you didn't finish it in the Team Notebook, finish it here and now.)
In [ ]:
In [ ]:
A. Modify your RBox
constructor
and the run_simulation
method so they create and modify the one list that must be created during the simulation to keep track of the history (should be in your answers to Critical Thinking questions in Lesson20 Team). This list must be saved as an instance variable.
Perform some intermediate testing to make sure this list is working correctly (by printing, etc.) but make sure to comment it out once ou are sure that it works well.
In [ ]:
In [ ]:
B. Define a plot_history
method that takes no parameters besides self
.
Inside this new method, create any/all lists that may be created immediately before plotting.
Lists created here do not need to be an instance variable because they will only used by the plot_history
method.
Next, add the Python code to create a line plot of your simulation history using the matplotlib plot
method to your plot_history
method.
This new method will make it easier to quickly create plots using different input parameters for comparison.
In [ ]:
Make sure to run a few test cases to make sure that your code works and makes interpretable plots that make sense.
In [ ]:
Comment on/briefly explain your results.
C. Describe how the simulation history changes over time. Provide graph(s) from your code to support your discussion.
D. Run simulations for the number of particles, N, where N = 16, 64, 400, 800, and 3600 (leave the time constant). How do the results of your simulation depend on the total number of particles, N?
E. When does the system reach equilibrium? Both describe the situation qualitatively (in words) and using a mathematical expression (which you will later implement in code).
How does the time for the system to reach equilibrium depend on N? Perform a few simulations using your code to evaluate your hypothesis.
F. Does the number of particles on the left-hand side of the box change when the system is at equilibrium? As a rough measure of the equilibrium fluctuations, use your code and the graphs it produces to visually estimate the deviation of number of particles on the left-hand side of the box from equilibrium for N = 16, 64, 400, 800, and 3600? Choose a time interval that is twice as long as the estimated time needed to reach equilibrium. How do your results for the deviation from equilibrium depend on N?
In [ ]: