Geometric probability and checking by simulation ·… | StemPy Lab
Course 23.3·Lesson 3 of 3
Geometric probability and checking by simulation
When a point is chosen at random on a line or in a square, there are too many outcomes to count. Then the probability of an event is a length or an area divided by the whole. This lesson uses lengths and areas for a bus, a rod and two friends who meet. Then it checks answers by a short simulation, and says how far a simulation can be trusted.
about 30 min1 simulation1 practice question
Lesson 3 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
What you will be able to do
find a probability as a ratio of lengths on a line, or of areas in a square;
set up the unit square for two numbers chosen at random;
check an answer with a simulation, and say how large the usual error is.
The bus that comes every fifteen minutes
A bus arrives at a stop every 15 minutes. You reach the stop at a random moment. What is the chance that you wait at most 5 minutes? The moments in a gap of 15 minutes are too many to list. But they are spread evenly. So the chance of an event is the length of the time that makes it happen, divided by the whole length. You wait at most 5 minutes if you arrive in the last 5 of the 15 minutes, so the chance is 155=31.
The rule
If a point is chosen at random on a line segment, with all positions equally likely, then
P(point in a part)=length of the segmentlength of the part.
In a region of the plane, replace length with area. This is called geometric probability. Three facts are worth remembering.
The words "at random" mean that every position is equally likely. Say it, because in geometry another meaning would give another answer.
The chance that the point lands on one exact position is 0, and yet the point lands somewhere. So an event of chance 0 is not always impossible.
The chance of a part does not depend on where the part is, only on its size.
A rod. A rod of length 12cm is cut at a random point. For both pieces to be at least 3cm, the cut must lie between 3cm and 9cm from one end. That is a length of 6cm, so the chance is 126=21.
Two numbers at random: the square
Two friends each arrive at a random time in one hour, and each waits 15 minutes. The pair of arrival times is a point (x,y) in a square with sides from 0 to 60 minutes. Every point of the square is equally likely. They meet when ∣x−y∣≤15. This is a band along the diagonal. The part of the square where they do not meet is two triangles, each with sides 45 minutes. So
P=1−6022×21×452=1−169=167.
Two small diagrams. On the left a line segment of length 20 from 0 to 20 has the part from 5 to 15 drawn thick in orange, labelled favourable, which is half of the segment. On the right a square with sides from 0 to 60 has a diagonal band shaded orange between two lines that are 15 units either side of the diagonal. The two white corner triangles are labelled with their sides, 45. The band is 7 over 16 of the square.
Checking an answer by simulation
Sometimes a probability is hard to be sure about. A simulation lets a computer repeat the experiment many times with random numbers, and counts how often the event happens. The fraction of successes is an estimate of the probability.
How good is the estimate? With N trials and a true probability p, the usual size of the error is about Np(1−p). For N=10000 and p=0.5 that is 0.005. Ten times more trials make the error only about 3 times smaller.
Three rules for a simulation.
It estimates. It does not prove. It can show that a formula is off by a lot, or that it is plausible.
The error shrinks slowly. Quote the answer as close to the estimate, never as equal.
The seed. A seed makes the random numbers the same every run, so you can repeat a result. A different seed gives a slightly different estimate, and both are fine.
A graph with the number of trials on a logarithmic horizontal axis from 10 to 100000. Three thin lines in different colours show the running estimate of the chance of a shared birthday in a group of 23, from three different runs of a simulation. They start far apart and wobble at first, then all settle near a dashed line at 0.5073 as the trials increase.
A worked example
Estimate the chance that the two friends meet, when each waits 15 minutes, by simulation. Then compare with 167.
The experiment. Choose x and y at random between 0 and 60. The event is ∣x−y∣≤15.
The estimate. In 20000 trials, a run of the program below gives a number near 0.44. The exact value is 167=0.4375.
The error. The usual error is 200000.4375×0.5625≈0.0035. A result between 0.43 and 0.445 is expected. A result of 0.40 would be a warning that something is wrong.
Practise with new numbers
Try it in Python
The program simulates two experiments from this chapter: a shared birthday in a group of 23, and two friends who meet. It prints each estimate next to the exact value, and the usual size of the error.
Common mistakes
Not saying what "at random" means. Equally likely positions give lengths and areas. Another rule gives another answer.
Using a length in a two-dimensional problem. Two random numbers need the square, and an area.
Trusting one short simulation. With 200 trials the error can be about 0.035.
Calling an estimate exact. A simulation gives an estimate.
Remember these
Geometric probability: total lengthlength on a line, total areaarea in a region.
Two numbers in [0,a]: the sample space is a square of side a. Two friends who wait w meet with probability 1−(aa−w)2.
A simulation has a usual error of about Np(1−p).
A simulation checks an answer. It does not prove it.
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
A point is chosen at random on a segment of length 30cm. Find the probability that it lies within 4cm of the midpoint.
A bus comes every 20 minutes. You arrive at random. Find the probability that you wait more than 5 minutes.
Two friends arrive at random in one hour and each waits 10 minutes. Find the probability that they meet.
A simulation of 10000 trials estimates a probability near 0.2. About how large is the usual error?
Why is the chance of hitting one exact point on a line equal to 0, although the point must land somewhere?
References
OpenStax, Introductory Statistics, Chapter 5, sections on continuous probability functions and the uniform distribution.
Enroll free in Dice Sums, Matching and Geometric Probability
Every lesson is open to read. Enrolling also lets you:
Mark lessons done and carry on where you stopped.
Take the tests of this lesson and its course.
Count the course towards the certificate for its chapter.