MATH 1180: Calculus for Biologists II (Spring 2011) Lab Meets: February 16, 2011 Report due date: February 23, 2011 Section 002: Wednesday 9:40−10:30am Section 003: Wednesday 10:45−11:35am Lab location − LCB 115 Lab instructor − Erica Graham, graham@math.utah.edu Lab webpage − www.math.utah.edu/~graham/Math1180.html Lab office hours − Monday, 9:00 − 10:30 a.m., LCB 115 Lab 05 General Lab Instructions In−class Exploration Review: Last time, we looked at an autonomous two−dimensional system of ODEs that described the interactive behavior of glucose and insulin. Background: This week, we’ll explore some of the random number tools in Maple’s Statistics package before we put them to use. restart; with(Statistics): Maple has a number of useful commands that allows us to generate random numbers. For example, suppose we wanted to toss a fair (unbiased) coin 100 times and see how many times it landed on heads (= 1) and how many on tails (= 2). We can use the rand( ) command, a process that generates an integer within a specified interval with equal probability as every other integer in the interval. So, if our interval is 1..2, the only two results we could get are 1 and 2, and we should achieve both values an equal number of times on average. To choose a random number this way, we create the function ’toss.’ It doesn’t take any arguments, but it sets rand( ) in motion. toss:=rand(1..2): We could execute toss( ) repeatedly to see what we get. toss(); To simulate the coin tosses, we use a ’do’ loop and save all 100 results from tossing an imaginary coin to a list called ’faircoin.’ Just for fun, we’ll plot each of our tosses individually. N_toss:=100: for j from 1 to N_toss do; faircoin[j]:=toss(); end do: plot([seq([j,faircoin[j]],j=1..N_toss)],1..100,0.75..2.25,color= "Black",style=point,labels=["toss number","result"]); Then we can use the Histogram( ) command in the Statistics package to show us exactly how many times the ’faircoin’ landed on heads or tails. The ’frequencyscale=absolute’ option shows us the absolute number of times each number was chosen. Histogram([seq(faircoin[j],j=1..N_toss)], frequencyscale=absolute,color="LawnGreen",labels=["heads = 1, tails = 2","frequency"]); Now suppose we had a biased coin in which there was a 0.9 probability that it landed on heads, and a 0.1 probability it landed on tails. We could use the ProbabilityTable( ) command to simulate this setting. First, we need to define our two probabilities in a list P, so that they add up to 1. Then we need to define a random variable Xp using RandomVariable( ). This creates a structure, of sorts, that can change probabilistically according to the rules we’ve set up in P, once Maple reads the information into a probability table. Using Sample( ), we will draw some numbers from Xp, the total amount of which we can also specify to be N_toss. P:=[0.9,0.1]; ## 0.9 for heads, 0.1 for tails Xp:= RandomVariable(ProbabilityTable(P)): biasedcoin:=Sample(Xp,N_toss): Histogram(biasedcoin,frequencyscale=absolute,color="LawnGreen"); Let’s take a look at the normal distribution. This is the traditional ’bell curve’ that you’ve probably encountered at some point. To generate a single normally distributed number, we need to create another random variable, but this time the argument to RandomVariable( ) willl be Normal(mean, st.dev). Notice that the normal distribution takes two arguments: the mean and the standard deviation, which represent the average value and the spread of all values, respectively. Here, we will construct a normal distribution with mean 0 and standard deviation 10, and take 2 sets of samples. Xn:=RandomVariable(Normal(0,10)): bellcurve1:=Sample(Xn,2500): bellcurve2:=Sample(Xn,10000): We can also see the results of two histograms simultaneously. Notice the plot order used in plots[display]. p1:=Histogram(bellcurve1,frequencyscale=absolute,color= "LightGray"); p2:=Histogram(bellcurve2,frequencyscale=absolute,color="LawnGreen") ; plots[display](p1,p2); Please copy the entire section below into a new worksheet, and save it as something you’ll remember. Lab 05 Homework Problems Your Full Name: Your (registered) Lab Section: Useful Tip #1: Read each problem carefully, and be sure to follow the directions specified for each question! I will take a vow of silence if you ask me a question that is clearly stated in a problem. Useful Tip #2: Try to minimize your code by not simply copying and pasting absolutely everything we do in class. See if you can eliminate unnecessary commands by knowing what it is you have to do and what tools you (minimally) need to do it. Useful Tip #3: Don’t be afraid to troubleshoot! Does your answer make sense to you? If not, explore why. If you’re still unsure, ask me. Useful Tip #4: When in doubt, restart! Paper−saving tip: Make the size of your output graphs smaller to save paper when you print them. Please ask me if you’re unsure of how to do this. (You can see how much paper you’d use beforehand by going to File Print Preview.) Also, please DO NOT attach printer header sheets (usually yellow, pink or blue) to your assignment. Recycle them instead! NOTE: For this assignment, you should re−define/assign any parameters or functions we used in class, as needed. This will require an understanding of what’s being asked of you. Again, everything that we did in class does not necessarily need to be done here. (0) Import the Statistics package we used in class. While you’re at it, read the useful tips again. with(Statistics): (1) Go to Help −> Maple Help, and type ’distributions,Statistics’ in the search box and explore some distributions that are different from the ones we used in class. This means you will have to click on a few distributions and see how they work. You don’t have to understand the formulas, just usage (i.e. syntax and arguments). List your 4 favorite distributions, in order from 1= "awesome!" to 4 = "eh." (They can’t all be "eh," by the way.) 1. 2. 3. 4. (1)(a) For distribution #1, choose appropriate parameters where applicable, and generate 2 lists of random numbers, one with 2500 and the other with 10000. ## feel free to use this space (b) Save separate histograms for both lists and plot them simultaneously, as we did in class. Required: [1] Use the frequencyscale=absolute option. [2] Specify a different color for each histogram. ## histograms (c) Compare the results of your two samples. What’s different? What’s the same? (2)(a) For distribution #2, choose appropriate parameters where applicable, and generate 2 lists of random numbers, one with 2500 and the other with 10000. ## feel free to use this space (b) Save separate histograms for both lists and plot them simultaneously, as we did in class. Required: [1] Use the frequencyscale=absolute option. [2] Specify a different color for each histogram. ## histograms (c) Compare the results of your two samples. What’s different? What’s the same? (3)(a) For distribution #3, choose appropriate parameters where applicable, and generate 2 lists of random numbers, one with 2500 and the other with 10000. ## feel free to use this space (b) Save separate histograms for both lists and plot them simultaneously, as we did in class. Required: [1] Use the frequencyscale=absolute option. [2] Specify a different color for each histogram. ## histograms (c) Compare the results of your two samples. What’s different? What’s the same? (4)(a) For distribution #4, choose appropriate parameters where applicable, and generate 2 lists of random numbers, one with 2500 and the other with 10000. ## feel free to use this space (b) Save separate histograms for both lists and plot them simultaneously, as we did in class. Required: [1] Use the frequencyscale=absolute option. [2] Specify a different color for each histogram. ## histograms (c) Compare the results of your two samples. What’s different? What’s the same? (5) Suppose you were in possession of an unfair die, in which the probability p of rolling each number is as follows: roll 1 −− p = 1/16 roll 2 −− p = 1/4 roll 3 −− p = 2/16 roll 4 −− p = 3/8 roll 5 −− p = 2/16 roll 6 −− p = 1/16. (a) Create a list P illustrating these probabilities. ## create P (b) Following the process we used in class for the biasedcoin, make a sample of 1000 numbers, and demonstrate their frequency on histogram. Required: [1] Use the frequencyscale=absolute option. [2] Put grid lines in your plot. ## histogram etc. (c) About how many times was each side of the die rolled? (d) How do these results compare to the probabilities you specified in part (a)? (6) List and describe the functions of no fewer than 6 new commands you used today (either in class or in the homework). You will get absolutely no credit if you fail to describe what every command you list does (or if you list something that’s not a command). Did you remember to save paper?