The random variable that needs to be generated has the following density function:
$f(x)=1/4 + 2x^3 + (5/4)x^4, 0 < x < 1$
My attempted solution is as follows:
Step 1: Generate a random number with the Uniform distribution between (0,1) ie: Unif(0,1) Step 2: Evaluate f(x) using the number generated in step 1 Repeat as necessary
I'm lost as to what the second method is that I can use to generate the RV.
Thanks in advance,
Algorithm 1
The corresponding cdf is $$\frac14x+\frac12x^4+\frac14x^5$$ if $0\leq x \leq1$ and is $0$ and $1$ for $x<0$ and $x>1$, respectively. This is a monotonically increasing (distribution) function and as a result its inverse exists. Even if we cannot compute the exact inverse, we can solve numerically the following problem. Consider the figure below depicting our distribution function. Let the location of a red dot uniform over the vertical axis between $0$ and $1$. Get the corresponding red dot on the horizontal axis as shown:
The location of the second red dot will be of the required distribution.
This is because if the inverse of a distribution function $F$ is known and a random variable, $X$ uniformly distributed over $[0,1]$ is given then
$$P(F^{-1}(X)<x)=P(X<F(x))=F(x).$$
Algorithm 2
The following figure depicts the pdf in question (Green area is below the graph of the pdf and the red area is above the pdf):
The black dots are samples from the uniform distribution over the rectangle $[0,1]\times[0,3.5]$.
According to the "rejection sampling" method take notes of the horizontal component when you get a sample falling in the green area. Let $N_x$ denote the number of sample points that fell in the green region over the interval $[x,x+\Delta x]$. If $N$ denotes the total number of samples then $$\frac{N_x}{N}\approx f(x)\Delta x.$$
That is, the pdf of the accepted samples ( $x$ components) will be of the given $f$.