0% found this document useful (0 votes)
7 views1 page

Tennis Match Simulation in R

The document outlines an assignment for a tennis match simulation using R programming. It requires the creation of a function to determine the number of sets played based on the probability of player A winning. Additionally, it instructs to simulate this function 1000 times for a specified probability and calculate the average number of matches played, which should be saved in a GitHub repository file without errors.

Uploaded by

sahachinmoy2022
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Tennis Match Simulation in R

The document outlines an assignment for a tennis match simulation using R programming. It requires the creation of a function to determine the number of sets played based on the probability of player A winning. Additionally, it instructs to simulate this function 1000 times for a specified probability and calculate the average number of matches played, which should be saved in a GitHub repository file without errors.

Uploaded by

sahachinmoy2022
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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).

You might also like