Chapter 2: coins simulation

To simulate this situation, label the drawers 1 through 6 and (to simplify the programming) assume the first half of the drawers contain gold coins and the latter half silver; then choose drawers using the pseudorandom number generator. First, find those instances in which the chosen drawer number is greater than or equal to 4. These cases satisfy your background information that a silver coin was found in one drawer; only these will be used to compute the final probability. Second, for each of these instances determine whether the drawer number is greater than 4. When this latter condition is satisfied, both drawers contain silver coins. The ratio of the number of instances in which the drawer number is greater than or equal to 4 (corresponding to the given background information), and instances in which the drawer number is greater than 4 (both drawers contain silver) is then the desired probability.

REPS=100000;

Dsamp=randi(6,[REPS 1]); %vector of pseudorandom numbers bet 1 and 6

S1=sum(Dsamp>=4); %which Dsamp numbers are at least 4?

S2=sum(Dsamp>4); %which Dsamp numbers are at least 5?

p=S2/S1 %approximation to probability that both drawers contain silver