Summary: In this laboratory, you will explore the use of PHP to provide some simple simulations.
Prerequisites: Basic PHP.
As you may know, Grinnell's Statistics faculty encourage their students to
ground their learning of probability and statistics through
experimentation. Recently, students in computer science have been helping
these faculty build Web-based applications to support such learning.
In this laboratory, we will build some applications that could potentially help students explore the impact of small probability differences. (Along the way, we will explore what writing these applications tells us about program design.)
Let's start by exploring the rules to two similar games. (These rules are
taken from Henry Walker's description at
Racquetball is a game played by two players on an indoor, enclosed court. Scoring proceeds as follows:
A player can only score points while she has the serve. A player loses the serve when she loses a volley, but no points are scored on the change of serve. Play continues until either the score is 11-0, which is a shut-out, or one player scores 21 points. (The rules do not require a player to win by two points.)
Volleyball is a game played on a court by two teams, separated by a net. Scoring proceeds much the same way as in racquetball (as explained above). In particular, scoring starts at 0-0. A team can only score points while it serves. A team loses the serve when it loses a volley, but no points are scored on the change of serve. Play continues until one team scores 15 points, and a team must win by at least two points (if the score is 15-14, play must continue until one team leads by 2 points). There is no special rule for ending a game due to a shut-out.
a. Log in to your MathLAN workstation. (Of course, you've probably already done that if you're reading this laboratory.)
b. Open a terminal window into which you can type commands.
c. Create a directory for this laboratory (e.g.,
d. Open a Web browser so that you can explore the pages that you create.
Create a PHP application that
Note that this is a very simple model. It assumes that the probability that A wins a volley is independent of whether or not she serves. For now, we'll live with the simple model.
Often, our statistics faculty would have students use the application you created in the previous exercise as follows: Students would run the application some number of times and count each of the events. They would then summarize the probability of A winning a game based on the probability of winning a volley.
Of course, it makes sense to have the computer simulate multiple games, rather than to have the user keep track by hand.
Write a PHP application that
You, too, can pretend to be a statistics student.
a. If A wins 55% of the volleys, about how many games do you expect A to win out of 1000 games?
b. Check your answer experimentally.
For the game of volleyball, Write a PHP application that
Yes, I know it makes no sense to print the number of shutouts, given that shutouts in volleyball are simply 15-0, but we're striving for consistency.
Write a PHP application that
Many folks, upon reading the descriptions above, would find themselves dismayed at the simplicity of the simulation. In particular, they might worry that the likelihood of A winning a volley depends on whether A or B serves. (It may be, for example, that A wins 55% of the volleys in which she serves, but only 50% of the volleys in which B serves.)
Add inputs to make the simulation more realistic. You might, for example, take as inputs the probablities that (a) B successfully returns one of A's serves, (b) B successfully returns one of A's shots; (c) A successfully returns one of B's serves; and (d) A successfully returns one of B's shots.
Sunday, 5 September 2010 [Samuel A. Rebelsky]
I usually create these pages
on the fly, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Mon Nov 29 09:06:20 2010.
The source to the document was last modified on Sun Sep 5 19:28:00 2010.
This document may be found at
A PDF version of this document may be found at
You may wish to validate this document's HTML ; ;Samuel A. Rebelsky, email@example.com