This preview shows pages 1–2. Sign up to view the full content.
Last Revised: 9/10/2008
1
EE 150 Lab 2
–
Going Broke
1
Introduction
In this exercise you will program a simulation of a simple coinflipping game to find
the average number of flips before one of the players goes broke.
The scenario is
that of three bored students with a large number of quarters (presumably for the
laundry machine).
To ease their boredom they agree to play a game where all
three flip one of their coins examining the resulting combination of heads and tails.
If all three coins match (heads or tails), each player takes their coin back.
Otherwise, whoever threw the one coin that does NOT match the two others gets
all three coins, and the game repeats.
Assuming, all players start with n coins, what
is the average number of flips before one player goes broke?
1
2
What you will learn
This lab exercise will familiarize you with more programming constructs, primarily
conditional/selection mechanisms (i.e. if statements).
In addition, you will learn
how to use the random number generation capabilities of Matlab to perform a type
of Monte Carlo simulation that was discussed in class.
3
Background Information and Notes
As a Monte Carlo simulation, we will execute a large number of game simulations
to arrive at an average duration for each game.
This can be easily accomplished by
bracketing a single game simulation within a loop and iterating over that loop for
some large number of times (say 100,000).
By tracking how many flips occurred
over the course of 100,000 game simulations and then dividing by 100,000 we can
arrive at the duration (in flips) of an average game.
Note: While every game has an
integral number of flips, the average may not be an integer.
One of the primary reasons that it may be easier to simulate this problem rather
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 Fall '08
 Dr.Burke

Click to edit the document details