07-May-2019 07:50:35 DUELING_IDIOTS_TEST Test the DUELING_IDIOTS programs. ASH: A champ plays a chump at N games of chess. P is the probability that an individual game is won by the champ. Q is the probability that an individual game ends in a tie. For this code, P = Q = 1/3. Probablity of a tie is 0.0487686 Probability the champ wins is 0.475616 Probability the challenger wins is 0.475616 BALLS: An urn contains N numbered balls. A ball is drawn repeatedly from the urn, examined, and replaced. This file calculates: (1) E(n), the average number of drawings (with replacement) of numbered balls before a repetition occurs; (2) T, the largest number of drawings that still allows the probability there is NOT a repetition is still greater than 1/2. E = 3.66022 T = 4 BALLS: An urn contains N numbered balls. A ball is drawn repeatedly from the urn, examined, and replaced. This file calculates: (1) E(n), the average number of drawings (with replacement) of numbered balls before a repetition occurs; (2) T, the largest number of drawings that still allows the probability there is NOT a repetition is still greater than 1/2. E = 12.21 T = 12 BALLS: An urn contains N numbered balls. A ball is drawn repeatedly from the urn, examined, and replaced. This file calculates: (1) E(n), the average number of drawings (with replacement) of numbered balls before a repetition occurs; (2) T, the largest number of drawings that still allows the probability there is NOT a repetition is still greater than 1/2. E = 39.3032 T = 37 BALLS: An urn contains N numbered balls. A ball is drawn repeatedly from the urn, examined, and replaced. This file calculates: (1) E(n), the average number of drawings (with replacement) of numbered balls before a repetition occurs; (2) T, the largest number of drawings that still allows the probability there is NOT a repetition is still greater than 1/2. E = 124.999 T = 118 BALLS: An urn contains N numbered balls. A ball is drawn repeatedly from the urn, examined, and replaced. This file calculates: (1) E(n), the average number of drawings (with replacement) of numbered balls before a repetition occurs; (2) T, the largest number of drawings that still allows the probability there is NOT a repetition is still greater than 1/2. E = 396 T = 372 BASEBALL This m-file calculates and plots (as a function of p) the ratio of the probabilities of a team winning at least 81p games out of 81 games to the probability of winning at least 162p games out of 162 games, where p is the probability of winning any individual game. Present results graphically. BIASED: A game of odd man out is played, in which N people each flip a coin. If one person's coin does not match all the others, that person is the odd man out. In this version, N-1 people have fair coins, and one has a biased coin whose probability of heads is Q. Estimate the average number of games played. Average number of games = 1.36 Theoretical number = 1.33333 BIASED: A game of odd man out is played, in which N people each flip a coin. If one person's coin does not match all the others, that person is the odd man out. In this version, N-1 people have fair coins, and one has a biased coin whose probability of heads is Q. Estimate the average number of games played. Average number of games = 1.329 Theoretical number = 1.33333 BIASED: A game of odd man out is played, in which N people each flip a coin. If one person's coin does not match all the others, that person is the odd man out. In this version, N-1 people have fair coins, and one has a biased coin whose probability of heads is Q. Estimate the average number of games played. Average number of games = 1.346 Theoretical number = 1.33333 BIASED: A game of odd man out is played, in which N people each flip a coin. If one person's coin does not match all the others, that person is the odd man out. In this version, N-1 people have fair coins, and one has a biased coin whose probability of heads is Q. Estimate the average number of games played. Average number of games = 2.027 Theoretical number = 2 BIASED: A game of odd man out is played, in which N people each flip a coin. If one person's coin does not match all the others, that person is the odd man out. In this version, N-1 people have fair coins, and one has a biased coin whose probability of heads is Q. Estimate the average number of games played. Average number of games = 2.024 Theoretical number = 2 BIASED: A game of odd man out is played, in which N people each flip a coin. If one person's coin does not match all the others, that person is the odd man out. In this version, N-1 people have fair coins, and one has a biased coin whose probability of heads is Q. Estimate the average number of games played. Average number of games = 2.033 Theoretical number = 2 BIASED: A game of odd man out is played, in which N people each flip a coin. If one person's coin does not match all the others, that person is the odd man out. In this version, N-1 people have fair coins, and one has a biased coin whose probability of heads is Q. Estimate the average number of games played. Average number of games = 3.079 Theoretical number = 3.2 BIASED: A game of odd man out is played, in which N people each flip a coin. If one person's coin does not match all the others, that person is the odd man out. In this version, N-1 people have fair coins, and one has a biased coin whose probability of heads is Q. Estimate the average number of games played. Average number of games = 3.136 Theoretical number = 3.2 BIASED: A game of odd man out is played, in which N people each flip a coin. If one person's coin does not match all the others, that person is the odd man out. In this version, N-1 people have fair coins, and one has a biased coin whose probability of heads is Q. Estimate the average number of games played. Average number of games = 3.209 Theoretical number = 3.2 BIASED: A game of odd man out is played, in which N people each flip a coin. If one person's coin does not match all the others, that person is the odd man out. In this version, N-1 people have fair coins, and one has a biased coin whose probability of heads is Q. Estimate the average number of games played. Average number of games = 5.428 Theoretical number = 5.33333 BIASED: A game of odd man out is played, in which N people each flip a coin. If one person's coin does not match all the others, that person is the odd man out. In this version, N-1 people have fair coins, and one has a biased coin whose probability of heads is Q. Estimate the average number of games played. Average number of games = 5.153 Theoretical number = 5.33333 BIASED: A game of odd man out is played, in which N people each flip a coin. If one person's coin does not match all the others, that person is the odd man out. In this version, N-1 people have fair coins, and one has a biased coin whose probability of heads is Q. Estimate the average number of games played. Average number of games = 5.3 Theoretical number = 5.33333 BINOMIAL: 6-Choose-0 = 1 BINOMIAL: 6-Choose-1 = 6 BINOMIAL: 6-Choose-2 = 15 BINOMIAL: 6-Choose-3 = 20 BROWNIAN BROWNIAN simulates Brownian motion, a random walk by a particle suspended in a fluid and being hit by molecules. At successive increments of time, the particle performs independent motions of random length, uniform from -1 to 1, in arbitrary units, in both the x and the y directions. The walk duration, that is, the total number of steps, where a step is a delta-x and a delta-y pair, is defined by the user. A walk always starts at the origin. Display results graphically. BULB: BULB calculates and plots the probability of a bulb, wired in series/parallel with sheets of switches, glowing. Graphics saved as "bulb.png" BULB: BULB calculates and plots the probability of a bulb, wired in series/parallel with sheets of switches, glowing. Graphics saved as "bulb.png" CASINO: This m-file simulates 10,000 games of "Chuck-a-Luck" and calculates the average winnings. That is, you bet $1 each and the winnings (W) are how much MORE money you have over and above the $10,000 betting money. The average winnings are, of course, W/10,000. Three dice are rolled, and you can bet on any number between 1 and 6. If one die comes up with your number, you win as much as you bet. If two or three dice come up with your number, you win twice or three times your bet. Average winnings per game is -0.07649 dollars CC: This program generates a random vector, X, of length 20,009 and then calculates the correlation coefficient X(n) and X(n+j) for j = 0,1,2,...,9. J Cor(X(i),X(i+j)) 0 0.986481 1 -0.00333768 2 -0.00698909 3 -0.00746122 4 -0.00440463 5 0.00117104 6 -0.0123197 7 0.00736841 8 0.00053616 9 -0.00439692 CHESS This m-file computes the probabilities, in an N-game chess match, of the match ending in a tie, in a win for the champ, or in a win for the challenger. The probability the champ wins an individual game is p, and the probability an individual game ends in a tie is q. Present the results graphically. Graphics saved as "chess.png" CHESS This m-file computes the probabilities, in an N-game chess match, of the match ending in a tie, in a win for the champ, or in a win for the challenger. The probability the champ wins an individual game is p, and the probability an individual game ends in a tie is q. Present the results graphically. Graphics saved as "chess.png" CORRELATION: Plotting X(I) versus X(I+J) can exhibit patterns if there is correlation in the data. If not, the scatter plot will be patternless. CPM Execute the Critical Path Method for a particular project. Total time required for the project = 6 early start task time slack 2 0 0 3 0 1 4 2 0 5 2 1 6 3 0 7 5 0 ESIM: Sample N points in the unit interval. Put them into N bins of equal width. Let Z be the number of empty bins. N/Z is an estimate of E. Estimate for E = 2.71003 Exact value = 2.71828 ESIM: Sample N points in the unit interval. Put them into N bins of equal width. Let Z be the number of empty bins. N/Z is an estimate of E. Estimate for E = 2.73823 Exact value = 2.71828 FLYCIRCLE Two flies land at random spots in the unit circle. What is the probability they are more than 1 unit apart? Probability flies are more than 1 unit apart = 0.00461 FLYSQUARE Two flies land at random spots on the unit square. What is the probability they are more than 1 unit apart? Probability flies are more than 1 unit apart = 0.0242 GAS: This m-file simulates the diffusion of gas molecules in a sealed container by using the Ehrenfest ball exchange rules. The simulation starts with n molecules (i.e., balls) of one type (i.e., black) on one side of the container, and n more molecules of another type (i.e., white balls) on the other side. The two urns play the roles of the two sides of the container. To simulate the ball (molecule) movements, the program selects two random numbers from 0 to 1, which are then compared to the current probabilities of selecting a black ball from urn I and a white ball from urn II. If BOTH random numbers are greater than these two probabilities then a white ball has been selected from urn I and a black ball has been selected from urn II, and so the number black balls in urn I is increased by one while the number of white balls in urn II is increased by one. If BOTH random numbers are less than or equal to these two probabilities then a black ball has been selected from urn I and a white ball has been selected from urn II and so the number of black balls in urn I is decreased by one while the number of white balls in urn II is decreased by one. If one of the random numbers is greater than its corresponding probability while the other random number is less than its corresponding probability, then no action is taken because then a white (black) ball moves from urn I to urn II at the same time a white (black) ball moves in the opposite direction. That is, there is no net change. Then, the ball selection probabilities are recalculated and another ball exchange is simulated. GENERATOR A histogram of 100,000 random values will show whether they are uniformly distributed or not. IDIOTS1: A and B fight a duel, but they only have one gun, a six-shot revolver. A will spin the cylinder and fire at B. If the gun does not fire, then B will spin the cylinder and fire at A. They continue to alternate until one of them is shot. What is the probablity that A will win? What is the average number of trigger pulls? The probability A wins is 0.5414 The average number of trigger-pulls/duel is 5.9446 IDIOTS2 Simulate a Russian roulette duel between A and B. A fires at B one time. If A misses, B fires at A two times. If B misses, A fires at B three times, and so on. Each shot is preceded by spinning the revolver cylinder, so there is a 1/6 chance that the revolver will fire. Calculate the probability that A survives. Probability that A survives = 0.523919 KIDS This m-file simulates 10,000 families that have children until a child is born that is the same sex as the first child, where p is the probability of a boy. Average number of children in each family = 2.9829 MARKOV We have four states, 1, 2, 3, 4. If we are in state I, then on the next step we will move to state J with a proability P(I,J). Simulate this process over many steps. Display the results graphically. MATCH This m-file computes the probability that N people, flipping fair coins n times, will each get the same number of heads. Match probability is 0.176197 MATCH This m-file computes the probability that N people, flipping fair coins n times, will each get the same number of heads. Match probability is 0.0355442 MATCH This m-file computes the probability that N people, flipping fair coins n times, will each get the same number of heads. Match probability is 0.00759002 MATCH This m-file computes the probability that N people, flipping fair coins n times, will each get the same number of heads. Match probability is 0.0795892 MONTY: There are three doors. A prize is behind one of the doors. You name a door. The host then opens one of the other doors, which is guaranteed not to conceal a prize. You may now choose to switch your choice to the remaining door, or not. What is the better strategy? Number of trials is 10,000 No-switch strategy wins 3405 times Switch strategy wins 6595 times NEEDLE: A circular table top has radius r. A needle of length 2*a <= 2*r is dropped onto the table. * how many times does one end stick out over the edge? * how manu times do both ends stick out? * how many times does neither end stick out? Report the results graphically. NORMAL: Displaying a histogram of 100,000 normal random numbers illustrates how they tend to be distributed. ODD: This m-file simulates 1,000 games of odd-person-out, for N people as defined by the user, with each person flipping a fair coin. The elements of the row vector duration are the number of games of length i, i.e., duration(i)=# of games that require i flips to complete, where i=1,2,3... The average number of flips for 2 players is 1.964 ODD: This m-file simulates 1,000 games of odd-person-out, for N people as defined by the user, with each person flipping a fair coin. The elements of the row vector duration are the number of games of length i, i.e., duration(i)=# of games that require i flips to complete, where i=1,2,3... The average number of flips for 3 players is 1.324 ODD: This m-file simulates 1,000 games of odd-person-out, for N people as defined by the user, with each person flipping a fair coin. The elements of the row vector duration are the number of games of length i, i.e., duration(i)=# of games that require i flips to complete, where i=1,2,3... The average number of flips for 4 players is 1.984 ONEDWALK This m-file simulates the one-dimensional, symmetrical walk with an absorbing barrier at the right. The map and connections: 1 <--> 3 <--> 4 --> 2 We start at location 1, and will stop at location 2. How long is the average walk? Average walk duration = 8.9721 ONEWAYTODOIT This M file generates 10,000 normal random values by using the Box-Muller transformation on uniform rnadom numbers. Display results as a histogram. ONION This m-file uniformly slices the unit interval, from left to right, ten times, and forms the sum of the widths of the slices. It does this 5000 times and then plots the distribution function of the sum. PARADOX: A simple system has an average lifetime of A. For reliability, a complex system is constructed of three simple systems. The complex system will only fail if at least two of the simple systems fail. What is the average lifetime of the complex system? Present the results graphically. PATHS: This m-file estimates the distribution and density functions of the random variable L denoting random path lengths across a unit square. Report results graphically. PERT: This m-file executes the Critical Path Method algorithm modified to incorporate random task completion times for Fig.21.5 in the text. PISIM: Sample N points (x,y) in a square. The number of points M with x^2+y^2 <= 1 lie inside the quarter circle. M/N is an estimate of pi/4. Estimate for PI is 3.1576 RADAR: As the number of observations N increases, compute * PD, the probability of detection. * PFA, the probability of false alarm. Present results graphically. RANDOMSUM: Add a sequence of random values until you exceed 1. Let N be the number of terms in this sequence. Repeating this process M times, let D(N) be the number of times that N terms were required. Then E can be approximated by 1*D(1) + 2*D(2) + ... * I * D(I) + ... Estimate for E = 2.71487 Exact value = 2.71828 SPIDER: A web consists of locations 1 through 9. The web is connected, and each location is connected to some of the others. A spider begins at location 1, and a fly is trapped at location 2. By choosing random moves on the web, how long does it take the spider to find the fly? Average number of steps to reach the fly = 15.4099 STIRLING1: Compare the logarithms of n! and Stirling's approximation Present the results graphically. STIRLING2 Stirling approximates n! by sqrt(2*pi*n) * n^n * exp(-n). Display a plot of absolute and relative errors. STIRLING3: Compare n! and Stirling's approximation. Present the results graphically. THEORY: A line is drawn through the unit square by choosing a point x in [0,1] and then choosing a random angle between 0 and 180 degrees. This m-file plots the theoretical distribution of the length of the line between x and the intersection with the square's boundary. THIEF A thief is in a room with three doors. He chooses one at random. One door leads immediately to freedom. Another leads back to the room, after S hours. The third leads back to the room, after L hours. If the thief is returned to the room, he randomly tries a door again. How long is the average imprisonment? Estimated average total time in prison = 3.9623 Exact value is 4 TUB: This m-file computes the optimal allocation of search boats looking for the UNSINKABLE TUB. The tub is sinking either 10 miles south (probability P1) or 10 miles north of the station (probability P2 = 1 - P1). N search boats are available, and each has a PS probability of locating the tub. How can we maximize the chance of locating the tub? Report results graphically. TUB: This m-file computes the optimal allocation of search boats looking for the UNSINKABLE TUB. The tub is sinking either 10 miles south (probability P1) or 10 miles north of the station (probability P2 = 1 - P1). N search boats are available, and each has a PS probability of locating the tub. How can we maximize the chance of locating the tub? Report results graphically. TUB: This m-file computes the optimal allocation of search boats looking for the UNSINKABLE TUB. The tub is sinking either 10 miles south (probability P1) or 10 miles north of the station (probability P2 = 1 - P1). N search boats are available, and each has a PS probability of locating the tub. How can we maximize the chance of locating the tub? Report results graphically. UNDERDOG1 The World Series of Baseball involves up to 7 games between two teams. Suppose the stronger team has probability P of winning any one game. What is the probability that the weaker team will actually win the series? Report the results graphically. UNDERDOG2: The World Series of Baseball involves up to 7 games between two teams. Suppose the stronger team has probability P of winning any one game. What is the average duration of the World Series? Report the results graphically. XPLUSY: This m-file produces 5,000 values of the sum of N random variables, each variable uniform from 0 to 1, and independent. It then plots a histogram of the sums using 100 bins. XPLUSY: This m-file produces 5,000 values of the sum of N random variables, each variable uniform from 0 to 1, and independent. It then plots a histogram of the sums using 100 bins. XPOWERY This m-file plots the probability density function of X^Y, where X and Y are independent, and both uniform from 0 to 1. XYHISTO This m-file produces 20,000 values of X raised to the Y power, where X and Y are both uniform from 0 to 1, and independent. It then plots a histogram of the values using 100 bins. Z: This m-file simulates the random variable Z=X/(X-Y), where X and Y are independent and uniform from 0 to 1. The output is a histogram of Z. DUELING_IDIOTS_TEST Normal end of execution.