Docsity

Homework 7 – Simulation in Maple or MATLAB | MATH 381, Assignments of Mathematics

Toggle sidebar
bg1
Math 381 Dr. Gunnar Gunnarsson
Homework #7 July 17, 2007
Simulations in Maple or Matlab
Reading Assignment: Chapter 4 and Introduction to Maple on Athena (see classlog for
weblink).
Maple or Matlab Code: Programming in Maple or Matlab will be an important component
of many homework assignments throughout the remainder of the quarter. For this homework
assignment, download two files ”dice.mw” and “fishtankmc2.mw” from the Maple Demos link
or “dice.m” and “fishtankmc2.m” from the Matlab Demos link on our course web page
http://www.math.washington.edu/~gunni/381Sum07/Maple.demos/
http://www.math.washington.edu/~gunni/381Sum07/Matlab.demos/
The .mw files are Maple worksheet files. Note, if you have any trouble downloading the
worksheet, try using the .mpl version instead with the “read” command.
Homework due Monday, July 23: For each of the problems below, explain your answer
fully. No credit will be given for a simple numerical answer.
1. Write a procedure to draw a card from a deck of 52 cards uniformly. Submit the code
and your confirmation it is working.
2. Write a procedure to calculate the probability of getting less than khits in ntrials of
a Bernoulli process with the probability of a hit on a single trial being p. Try your
procedure for a few different values of k, n, and p. Display the data. Submit the code.
3. Draw 10 cards independently from 10 different decks and count the number of Jacks.
Repeat this experiment 100 times. How often is the count under 2? Compare this with
the probability computed in Problem 2.
4. Write a procedure to draw a hand of kcards from the deck uniformly. Use this to
approximate the probability of getting a pair of any kind, three-of-a-kind, and a straight
in a 5 card hand. Submit the code and your confirmation it is working.
5. Download the code dice.mw (maple) or dice.m (matlab) if you haven’t already. The
program in this worksheet is set up to use a random variable Ywith the following
probability distribution:
y123456
p(y) 1/6 1/6 1/6 1/6 1/6 1/6
1
pf2

Partial preview of the text

Download Homework 7 – Simulation in Maple or MATLAB | MATH 381 and more Assignments Mathematics in PDF only on Docsity!

Math 381 Dr. Gunnar Gunnarsson Homework #7 July 17, 2007

Simulations in Maple or Matlab

Reading Assignment: Chapter 4 and Introduction to Maple on Athena (see classlog for weblink).

Maple or Matlab Code: Programming in Maple or Matlab will be an important component of many homework assignments throughout the remainder of the quarter. For this homework assignment, download two files ”dice.mw” and “fishtankmc2.mw” from the Maple Demos link or “dice.m” and “fishtankmc2.m” from the Matlab Demos link on our course web page

http://www.math.washington.edu/~gunni/381Sum07/Maple.demos/ http://www.math.washington.edu/~gunni/381Sum07/Matlab.demos/

The .mw files are Maple worksheet files. Note, if you have any trouble downloading the worksheet, try using the .mpl version instead with the “read” command.

Homework due Monday, July 23: For each of the problems below, explain your answer fully. No credit will be given for a simple numerical answer.

  1. Write a procedure to draw a card from a deck of 52 cards uniformly. Submit the code and your confirmation it is working.
  2. Write a procedure to calculate the probability of getting less than k hits in n trials of a Bernoulli process with the probability of a hit on a single trial being p. Try your procedure for a few different values of k, n, and p. Display the data. Submit the code.
  3. Draw 10 cards independently from 10 different decks and count the number of Jacks. Repeat this experiment 100 times. How often is the count under 2? Compare this with the probability computed in Problem 2.
  4. Write a procedure to draw a hand of k cards from the deck uniformly. Use this to approximate the probability of getting a pair of any kind, three-of-a-kind, and a straight in a 5 card hand. Submit the code and your confirmation it is working.
  5. Download the code dice.mw (maple) or dice.m (matlab) if you haven’t already. The program in this worksheet is set up to use a random variable Y with the following probability distribution:

y 1 2 3 4 5 6 p(y) 1/6 1/6 1/6 1/6 1/6 1/

This distribution allows us to consider Y as the random variable determined by any one of the six possible outcomes that can be observed when a fair die is rolled. The files simulate the rolling of a fair die number of rolls times. (Note that number of rolls is a variable in the code.) The sample average for the outcomes y 1 , y 2 ,... , ynumber of rolls is found and recorded in a histogram. The process of rolling the die number of rolls times, finding the sample average, and recording the result in a histogram is repeated number of experiments times. The program outputs a histogram of the probability distribution and also for the sample averages of the repeated experiments.

(a) Run this program twice. Insert^1 2 the histograms of sample averages for both experiments into a document and answer the following:

  • Are the histograms exactly the same? Why or why not?
  • What underlying distribution do the histograms follow? How do you know? (b) What underlying distribution will the histogram of sample averages follow if you set number of rolls = 1? Explain your answer. (c) Change the program to the following probability distribution:

y 1 2 3 4 5 6 p(y) 4/24 1/12 1/24 1/24 1/24 15/

Set number of rolls = 3. Run the program several times and copy a characteristic histogram of the sample averages into a document. Repeat this for number of rolls = 10 and number of rolls = 100 and answer the following question. What underlying distribution appears with increasing number of rolls? Explain what you see. If you have any doubts in your answer, submit your code. Otherwise, you don’t need to submit the code for this problem.

  1. Use the fishtank code that you downloaded to practice making mathematical predictions with a model. In particular, identify the optimal value for the variable fixed-delivery by trying various values for yourself. Once you have decided what you think is the optimal value, write a report to the store owner interpreting your model. Summarize your recom- mendation and how the store should implement it. Justify your recommendation with some persuasive data. Explain the shortfalls and the benefits of your recommendation. This exercise is meant to practice the last two phases of modeling. You will be graded on clarity of exposition and how convincing your argument is that your recommendation is optimal.
  2. (Bonus: (10 pts) Consider the Bernoulli process with a fair coin. A run is a sequence of trials in a row all coming up heads or all coming up tails. Let Mn be the random variable that counts the maximum length of any run of heads in n trials. For example, M 16 (HT T HHT T HHHT T T T T H) = 3 corresponding to the run of three heads starting in position 8. What is the expected value and variance of Mn for 1 ≤ n ≤ 64? An exact formula would be best but a good approximation will suffice.

(^1) To insert a Maple plot into Word (or LATEX) use File/Export-As in Maple and choose a format like JPG

(or EPS for LATEX) and then insert the graphic into a document accordingly. (^2) To insert a Matlab plot use save as... and choose the appropriate format.