MTH208a: Assignment 1
A tennis match runs on the concept of: “best-of-five”. The two tennis players play at most 5 sets. If a clear
winner is determined by set number 𝑥 (<5), then the rest of the 5 − 𝑥 sets are not played. (For example, if
player 𝐴 plays against player 𝐵, and the win sequence is 𝐴𝐵𝐴𝐴, the winner is clearly 𝐴, so the last set will
not be played.)
Let 𝑝 be the probability of player 𝐴 winning a set.
1. Write an R function that returns the number of sets that are played (𝑥) in one simulated tennis match.
Call this function tennis. It should take as input, the probability of success 𝑝 and should output the
number of games played, 𝑥. The function should look like:
tennis <- function(p)
{
...
return(x)
}
2. Repeat the simulation 1000 times for 𝑝 = 0.70 and save the output in a vector called matches. Save
the average number of matches, mean(matches) in object ans. So your code should look like:
matches <- …
for(i in 1:1000)
{
matches[i] <- ….
}
ans <- mean(matches)
3. Copy all relevant code and paste it in the assignment1.R file in your Assignment GitHub repository.
Your code you copy and paste should run without any errors. The last line of the code
should be ans <- mean(matches).