Answered step by step
Verified Expert Solution
Question
1 Approved Answer
6. Suppose you have a blue and red parallel striped floor. Each stripe has equal thickness of t units. If you drop a matchstick of
6. Suppose you have a blue and red parallel striped floor. Each stripe has equal thickness of t units. If you drop a matchstick of length l on the floor, the probability that it will cross the border between two stripes can be computed as P =. Note, if x is the center of the needle to the closest line and the acute angle between the needle and the lines, then it can be shown analytically that a needle will cross a line if x s (sine (a) (8 points) Create a function barPi (e,t,n) that uses the hit-or-miss method and the above for mulation to approximate the value of by simulating dropping many matchsticks onto the floor Assume that S t and that n > 0 is the number of sampleseedles to drop. Be sure that your code checks that the parameters are appropriate and gives useful error messages, as well as return a value of 0 if no needle crosses a line (your calculation returns Inf)! The complete function needs no more than 4 lines of R code. (b) (2 points) Create a function to return the mean and standard deviation of a vector of values. Only 1 line of R code (c) (6 points) Compare the mean/standard deviation (using your function from part (c)) for 1 = 0.5, 0.8, 1.0 (keeping t 1 constant). You will simulate dropping 1000 needles for each experi- ment. What do you notice? Explain. One line of R code per value, so 3 total lines of code needed. 6. Suppose you have a blue and red parallel striped floor. Each stripe has equal thickness of t units. If you drop a matchstick of length l on the floor, the probability that it will cross the border between two stripes can be computed as P =. Note, if x is the center of the needle to the closest line and the acute angle between the needle and the lines, then it can be shown analytically that a needle will cross a line if x s (sine (a) (8 points) Create a function barPi (e,t,n) that uses the hit-or-miss method and the above for mulation to approximate the value of by simulating dropping many matchsticks onto the floor Assume that S t and that n > 0 is the number of sampleseedles to drop. Be sure that your code checks that the parameters are appropriate and gives useful error messages, as well as return a value of 0 if no needle crosses a line (your calculation returns Inf)! The complete function needs no more than 4 lines of R code. (b) (2 points) Create a function to return the mean and standard deviation of a vector of values. Only 1 line of R code (c) (6 points) Compare the mean/standard deviation (using your function from part (c)) for 1 = 0.5, 0.8, 1.0 (keeping t 1 constant). You will simulate dropping 1000 needles for each experi- ment. What do you notice? Explain. One line of R code per value, so 3 total lines of code needed
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started