Consider the continuous random variable with pdf given by:

$$f(x) = 2(x − 1)^2;\quad 1 < x ≤ 2$$ $$f(x) = 0;\quad \text{otherwise}$$

Plot the cdf for this random variable. Show how to simulate a rv with this cdf using the inversion method.

I tried this as

$$F(x) =\int_{1}^{x} 2(t − 1)^2 dt=\frac{2}{3}(x − 1)^3;\quad 1 < x ≤ 2$$

I plot the cdf using R.


to simulate a rv with this cdf using the inversion method


$$S=\frac{2}{3}(x − 1)^3$$

$$\frac{3S}{2}=(x − 1)^3$$


Using R

  X.sim <- function(S)1+(3*S/2)^(1/3)
  S <- runif(100)   

  x = X.sim(S)

But i got the value of $x$ more than $2$ . But $1 < x ≤ 2$ .

How can i solve the problem ?

I noticed if i integrate the pdf under the range $1 < x ≤ 2$ it is not equal to $1$.

  • $\begingroup$ Maybe you should revisit the source of this problem? As you point out, that is not a probability density function since it doesn't integrate to 1. $\endgroup$ – hejseb Sep 24 '13 at 6:36
  • $\begingroup$ @hejseb This is an exercise of Introduction of scientific programing and simulation using R exercise 18.6,number 13 $\endgroup$ – ABC Sep 24 '13 at 6:42

The issue is that the normalizing constant has been incorrectly specified in the exercise. It says 2 when it should in fact be 3. See below.

$$ \int_1^2c(x-1)^2dx=c\left[\frac{(x-1)^3}{3}\right]_1^2=\frac{c}{3}=1\Leftrightarrow c=3 $$

If you change this and run the following code:

X.sim <- function(S)1+(S)^(1/3)
S <- runif(100000)   
x <- X.sim(S)

you will see that you get very close to 2, but you won't exceed it. Hope this helps!

  • $\begingroup$ Thank you very much. Would you please check the command of my plotting cdf? is it correct? $\endgroup$ – ABC Sep 24 '13 at 8:43
  • 1
    $\begingroup$ @harry: You probably want to plot it as a continuous function and not just ten values from the cdf. Like this for example: CDF <- function(x) {(x-1)^3}; curve(CDF, from = 1, to = 2) $\endgroup$ – hejseb Sep 24 '13 at 9:03
  • $\begingroup$ Thank you very,very,very much. $\endgroup$ – ABC Sep 24 '13 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.