Please read ALL the instructions carefully. Read the whole assignment before you begin.
For this assignment, you may use a Python program or a JupyterLab notebook.
NOTE: This HW maybe more challenging. Start early and come to office hours if you need help!
(0) Completion of Labs and Reading
If you have not yet completed the in-class work or the weekly reading, then you may want to finish that first. Recent lecture notes on Collab may also be useful...
(1) Checkout the repository:
Use this link to accept the assignment and create your repository on GitHub: ???
After you accept the assignment and the repository and it exists in your GitHub, clone the repository into your working area on Rivanna.
(2) BITE!!! - A simple simulation using probability distributions and random numbers (5 Points)
For this exercise, you will perform a simulation of a real-world situation. Consider the following, it is a hot and damp August on Grounds and the mosquitoes are very hungry. For any given meter you walk, there are 100 mosquitoes that may draw blood. Fortunately, mosquitoes aren't very well organized, so the probability of a given mosquito biting is only 0.0001. But another 100 mosquitoes await you in the next meter, et cetera…
The basic binomial nature of this problem should be evident (mosquitos either bite you or don't). For each meter, you are “flipping 100 coins with a probability of heads of 0.0001”. Review the slides from the lecture about probability distributions for a more complete understanding.
Perform a discrete simulation of this scenario where you run your program for walks of 200m and 2500m. Start with the program from your repository named bite.py (or you may make a Jupyter Notebook), then use the following guidelines:
- For each meter walked, give each mosquito a chance to bite and count the number of bites (you need to draw a random number from the correct probability distribution)
- Repeat until the entire distance is covered, counting the total number of bites
- Enter the total number of bites in a histogram for the walk
- Repeat the walk many times, say 500, entering the total number for that walk into the histogram each time
- Plot your histogram to the screen and save as a .png file
Write your program so the distance walked is easy to enter at the command line (or if you use a Jupyter Notebook, use the 'input' function in the first block of code to let the user provide the distance walked).
Usage: python bite.py <distance>
Comment on these in your code:
- Compare your plots with the Poisson Distribution and the Gaussian ("Normal") Distribution.
- Which distribution is most similar to each of your plots?
Your program should check “argv” (or the value from the input in Jupyter) to make sure the user has supplied a valid distance value and tell them to add one if they've left it off.
Submit the histograms with your code, where you should have one for the two discrete simulations: bite_200.png and bite_2500.png.
(3) Simulated Falling - 10,000 times (5 Points)
Main Idea: Create pseudo-experiments to simulate an object falling, then fit the simulations to extract values for acceleration due to gravity (g) with the uncertainty (part d).
In the last several classes, we used the simple example of an object falling under the force of gravity to discuss using the chi-squared value to compare levels of agreement between the data and different models. We also used it as a simple example for learning about fitting.
In science, we often call it a pseudo-experiment when we simulate data for a fake experiment. In class, we made one pseudo-experiment for the falling object. Now I want you to write a program (falling.py or falling.ipynb) that:
a) Generates 10,000 pseudo-experiments for the falling object. In each simulated experiment, you will generate the data for the first 10 seconds using the equation v=9.8*t, but you will randomly 'smear' the calculated velocities. Using a random number from a uniform distribution you should add a +/- variation of 20% for each velocity generated (we did this in the class work Notebook, so look there to get started).
b) Each pseudo-experiment will have 10 data points, so fit those data points using the model v=atto extract the parameter 'a'.
c) Make a histogram of all of the resulting 'a' values obtained from your 10,000 fake experiments (save as falling_a.png). What are the features of this plot? Is it uniform? Why or why not? Try to fit this distribution to a Gaussian and extract the mean and sigma. Draw the best-fit line on the histogram.
d) Want to be an A student? Try this part for 1 point:
Make a histogram of all of the resulting fit uncertainties on the 'a' values obtained from your fake experiments (save as falling_a_error.png). What are the features of this plot? Is it uniform? Why or why not? Try to fit this distribution to a Gaussian and extract the mean and sigma. Draw the best-fit line on the histogram.
For problem 2 (this part), you will turn in:
Done? Make sure you answered any questions, then clean up your code and include some useful comments, then post bite.py, bite_200.png, bite_2500.png, falling.py(or .ipynb), falling_a.png, and falling_a_error.png to GitHub.