21-Dec-2022 20:48:05 will_you_be_alive_test(): MATLAB/Octave version 9.8.0.1380330 (R2020a) Update 2. Test will_you_be_alive(). airplane_seat_test(): Airline passengers 1 to N are assigned seats 1 to N. The first passenger to board, #1, is clueless, and chooses a seat randomly. The remaining passengers board in order, choosing their assigned seat if possible, otherwise taking an empty seat at random. What is the probability that the last passenger, N, will be able to sit in the correct assigned seat N? Number of seats available = 100 Number of simulations = 1000 Estimated probability = 0.491 Theoretical probability = 0.5 before_test(): before() estimates the probability that a person, flipping a biased coin repeatedly, will reach 4 heads before reaching 7 tails. bias p(4H before 7T) 0 0 0.05 0.001011 0.1 0.0128456 0.15 0.0499578 0.2 0.120935 0.25 0.224025 0.3 0.350359 0.35 0.485999 0.4 0.617597 0.45 0.734013 0.5 0.82793 0.55 0.898032 0.6 0.945282 0.65 0.974001 0.7 0.989463 0.75 0.996487 0.8 0.999157 0.85 0.999867 0.9 0.99999 0.95 1 1 1 bernoulli_dice_test(): bernoulli_dice() considers the Bernoulli dice game. Players A and B toss a fair die, until a 1 is rolled. On round 1, A gets 1 toss, then B gets 1 toss. On round k, A gets k tosses, then B gets k tosses. What is the probability that A wins? Estimate = 0.596827, exact is 0.596794 bingo_test(): bingo(A,B) simulates a simplified game of bingo. The bingo card is no just a 2x2 array. Player X gets card A, and player Y gets card B. Many random games are played, and the results are reported. There are four possible bingo cards, C1, C2, C3, C4. It turns out to be a nontransitive system, in which every card will beat one of the others, and lose to another. The four bingo cards card(:,:,1) = 1 2 3 4 card(:,:,2) = 2 4 5 6 card(:,:,3) = 1 3 4 5 card(:,:,4) = 1 5 2 6 A A 0, 0, 720 A B 336, 312, 72 A C 288, 288, 144 A D 312, 336, 72 B A 312, 336, 72 B B 0, 0, 720 B C 336, 312, 72 B D 288, 288, 144 C A 288, 288, 144 C B 312, 336, 72 C C 0, 0, 720 C D 336, 312, 72 D A 336, 312, 72 D B 288, 288, 144 D C 312, 336, 72 D D 0, 0, 720 black_test(): A bag of B black and W white marbles is to be emptied in a series of rounds. A round begins when a single ball is drawn from the bag, its color is noted, and the ball is discarded. Then, one at a time, more balls are drawn from the bag. If they match the first ball, they are also discarded. Otherwise, they are replaced in the bag, and the round stops. Rounds are taken until the bag is empty. This function simulates the process of a single round. Estimate the probability P that the last marble in the bag is black. It turns out P=1/2. B W P 1 1 0.5073 1 10 0.4964 2 3 0.5028 3 3 0.4972 5 4 0.5103 7 9 0.5085 18 13 0.4984 15 39 0.4932 chain_test(): chain() estimates the extinction probability of a chain letter. A chain letter asks the recipient to make C copies and send them on. Suppose that, with probability P, any recipient ignores the request, and with probability any recipient complies with it. Estimate the probability E that the chain letter will terminate. Need to solve E = p + ( 1 - p ) * E^c ) C P E 1 0.1 1 1 0.3 1 1 0.5 1 1 0.7 1 1 0.9 1 2 0.1 0.11111 2 0.3 0.428571 2 0.5 0.992188 2 0.7 1 2 0.9 1 3 0.1 0.100925 3 0.3 0.323754 3 0.5 0.618033 3 0.7 0.999948 3 0.9 0.999999 4 0.1 0.10009 4 0.3 0.306149 4 0.5 0.543689 4 0.7 0.8795 4 0.9 1 5 0.1 0.100009 5 0.3 0.301751 5 0.5 0.51879 5 0.7 0.795675 5 0.9 1 double_dart_test(): double_dart() considers the double dart problem. If two darts land randomly in the unit circle, what is the probability that they are at least 1 unit apart? Estimate = 0.413487, exact is 0.413497 double_six_test(): double_six() considers Newton's double six dice problem. What is the expected number of times you must roll a fair die in order to observe two consecutive values of six? Estimate = 42.0572, exact = 42 final_test(): final() estimates the probability, for random A and B that: A^2/3 + B^2/3 < 1 Estimated probability = 0.294722 Exact probability = 0.294524 flips_test(): flips() estimates EVEN, the probability of an even number of heads after N tosses of a biased coin, whose probability of heads on a single toss is P. N P EVEN 9 0.1 0.566928 9 0.99 0.08271 galileo_test(): galileo() reports the number of ways to make each sum from 1 to 18, when three dice are rolled. Total Number of ways Probability 1 0 0 2 0 0 3 1 0.00462963 4 3 0.0138889 5 6 0.0277778 6 10 0.0462963 7 15 0.0694444 8 21 0.0972222 9 25 0.115741 10 27 0.125 11 27 0.125 12 25 0.115741 13 21 0.0972222 14 15 0.0694444 15 10 0.0462963 16 6 0.0277778 17 3 0.0138889 18 1 0.00462963 gamblers_ruin_test(): gamblers_ruin() considers the gambler's ruin problem. Players A and B repeatedly play a game against each other. On each game, player A has a probability P of winning. After each game, the winner gets 1 dollar from the loser. The players begin with A and B dollars, respectively. They play until one is bankrupt. How long will it take for one player to go bankrupt? What is the probability that A is ruined? A B P Prob(ruin) AverageGames 9 1 0.5 0.10001 9.02072 90 10 0.5 0.10052 901.85 9 1 0.45 0.20984 11.0436 99 1 0.4 0.33349 161.698 golf_test(): golf() estimates the probability that a golf ball, randomly landing in the unit square, will be closer to the center than to any edge. Estimate = 0.21893, exact is 0.218951 inside_test(): inside() estimates the probability that, choosing three points at random on the unit circle, the origin will be inside the resulting triangle? Estimate = 0.250117, exact is 0.25 liar_test(): liar() estimates the probability PROB that a true statement, passed sequentially along a chain of N people, will reach the end of the chain as a true statement, given that, with probability P, each person repeats the statement they just hear, or with probability 1-P, repeats the opposite of the statement. N P PROB 1 0.99 0.99002 2 0.99 0.980279 3 0.99 0.970622 41 0.99 0.718571 42 0.99 0.714004 1 0.01 0.0100113 2 0.01 0.9802 3 0.01 0.0294104 41 0.01 0.281378 42 0.01 0.714133 long_test(): long() estimates the probability that a triangle will be after a stick of unit length is randomly broken in two, and then the longer piece is randomly broken again. Estimate = 0.386119, exact is 0.386294 marks_test(): marks() considers a problem in which N sticks are each broken into a long and short piece. Pairs of the 2*N pieces are then randomly combined to form N new sticks. What is PROB, the probability that every new stick will be formed from a long and a short piece? N Prob Exact 1 1 1 2 0.666993 0.666667 3 0.500217 0.5 4 0.40161 0.4 5 0.333278 0.333333 6 0.28602 0.285714 7 0.249853 0.25 8 0.221864 0.222222 9 0.200094 0.2 10 0.181676 0.181818 newton_test(): newton() estimates the probability that A: a fair die rolled 6 times will show 6 at least 1 time; B: a fair die rolled 12 times will show 6 at least 2 times; C: a fair die rolled 18 times will show 6 at least 3 times. Samuel Pepys believed C was more likely than A or B. Newton showed that A was more likely. Case Estimate Exact A: 0.6657 0.6651 B: 0.6173 0.6187 C: 0.5957 0.5973 obtuse1_test(): obtuse1() estimates the probability that an obtuse triangle will be formed, assuming that one side has length 1, and the other two side lengths are chosen uniformly at random between 0 and 1. Estimate = 0.570551, exact is 0.570796 obtuse2_test(): obtuse2() estimates the probability that, after a stick of unit length is randomly broken into three pieces, an obtuse triangle can be formed from the pieces. Estimate = 0.682282, exact is 0.682234 ping_pong_test(): ping_pong() estimates PROB, the probability that a player will win a game of ping pong, assuming the player has a probability P of winning a single point. P PROB Exact 0.3 0.0263899 0.0264 0.4 0.174378 0.1744 0.5 0.5 0.5 0.6 0.825622 0.8256 plums_test(): plums() estimates the expected distance D from the surface to the nearest of N plums randomly placed inside a unit spherical pudding. N D(Estimate) D(Exact) 5 0.0625372 0.0625 6 0.0525631 0.0526316 7 0.0453907 0.0454545 8 0.0399807 0.04 9 0.0357022 0.0357143 10 0.0322256 0.0322581 ratio1_test(): ratio1() estimates the probability PROB that the ratio of two random numbers is greater than K. K Estimated Approximated 2 0.499842 0.5 3 0.333729 0.333333 4 0.250564 0.25 5 0.200298 0.2 6 0.166212 0.166667 7 0.142979 0.142857 8 0.124316 0.125 9 0.111259 0.111111 10 0.100086 0.1 ratio2_test(): ratio2() estimates the probability PROB that, given three random numbers, the ratio of the largest to the smallest is greater than or equal to K. K PROB 2 0.750207 3 0.556263 4 0.437337 5 0.360552 6 0.305327 7 0.265529 8 0.234876 9 0.209724 10 0.189876 spaghetti_test(): spaghetti() estimates E, the expected number of loops created if N strands of spaghetti are randomly joined at the ends. N E 10 2.13326 100 3.28434 1000 4.43563 10000 5.58693 square_adjacent_test(): square_adjacent() estimates S, the expected distance between random points on adjacent sides of a unit square. Exact value is 0.7652 Estimate is 0.764915 square_inside_test(): square_inside() estimates the expected distance between random points inside a unit square. Exact value is 0.5214 Estimate is 0.521498 square_opposite_test(): square_opposite() estimates the expected distance between random points on opposite sides of the perimeter of a unit square. Exact value is 1.0766 Estimate is 1.07673 squash_test(): squash() estimates the probability of winning the game of squash played between two equally good players: P: if you serve first, Q: if you serve second. P Estimate = 0.534863, exact is 0.534863 Q Estimate = 0.465137, exact is 0.465137 steve2_test(): steve2() analyzes Steve's elevator problem. Steve gets on an elevator going up. There are N higher floors. Steve wishes to go up 9 floors. There are K additional riders in the elevator, each of whom has randomly chosen one of the higher floors as destination. On average, how many times S will the elevator stop until Steve reaches his floor? The theoretical value is T. N K S T 11 3 2.98922 2.98948 20 3 2.1411 3.42463 11 10 5.91629 5.91565 20 10 4.20876 7.82147 ten_years_test(): ten_years() estimates the probability that a certain person will still be alive in 1, 2, ..., 10 years. Years Probability 0 1 1 0.989985 2 0.969564 3 0.953996 4 0.932902 5 0.916801 6 0.900314 7 0.877931 8 0.855259 9 0.832281 10 0.808982 top_test(): top() estimates winning ratios for dreidel 2: 0.857683 0.857683 3: 0.679905 0.679905 0.679905 4: 0.523447 0.523447 0.523447 0.523447 5: 0.397746 0.397746 0.397746 0.397746 0.397746 twins_test(): twins() estimates the probability that 2 twins in 20 students will be randomly assigned the same lab group of 4 students. Estimate is 0.158452, exact is 0.157895 will_you_be_alive_test(): Normal end of execution. 21-Dec-2022 20:50:52