Question: Using the Rejection Method Algorithm below, write a python program to generate random variables X with distribution determined by the density function f(x) = 1/3
Using the Rejection Method Algorithm below, write a python program to generate random variables X with distribution determined by the density function f(x) = 1/3 (x-1)^2 on the interval [0,3]. Algorithm: 1.Find such numbers a , b , and c that 0 ? f (x ) ? c for a ? x ? b . The bounding box stretches along the x -axis from a to b and along the y -axis from 0 to c . 2. Obtain Standard Uniform random variables U and V from a random number generator or a table of random numbers. 3. Define X = a + (b ? a )U and Y = cV . Then X has Uniform(a, b ) distribution, Y is Uniform(0, c ), and the point (X, Y ) is Uniformly distributed in the bounding box. 4. If Y > f (X ), reject the point and return to step 2. If Y ? f (X ), then X is the desired random variable having the density f (x ). Write a subroutine that implements steps 1,2,3,4 of Algorithm 5.4, then call it at least 10,000 times. Make a table of values 0, 0.1, 0.2, ... 2.8, 2.9 and keep a running tally of the number of variables that fall within each interval. At the end of the program, print out a histogram showing how the values accumulated. It should look like the graph presented in class.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
