Generation of samples from a given distribution

57 Views Asked by At

How to generate samples from a given density function in matlab. The PDF of the random variable is given by $f_Z(z) = \left\{ \begin{array}{ c l } \frac{3}{a^3} \left(a + 2z\right)^2 & \quad \textrm{if } -\frac{a}{2}\leq z < 0 \\ \frac{3}{a^3} \left(a - 2z\right)^2 & \quad 0 < z \leq \frac{a}{2} \end{array} \right.$

First I have evaluated its CDF which is given as

$F_Z(z) = \left\{ \begin{array}{ c l } \frac{1}{2a^3} \left(a + 2z\right)^3 & \quad \textrm{if } -\frac{a}{2}\leq z < 0 \\ \frac{1}{2} + \frac{1}{2}\left[1 - \left(\frac{1 - 2z}{a}\right)^3\right] & \quad 0 < z \leq \frac{a}{2} \end{array} \right.$

Note from $z \geq \frac{a}{2} \quad F_Z(z) = 1$ Here I want to generate the random samples using the command "rand" in matlab. So I have tried through inverse method by equating this F_Z(z) to Uniform distribution. However my question is when I want to equate with uniform distribution which equation should I equate and is the first equation for z < 0 I will equate or the second equation should I equate to U. So that I can evaluate the inverse function and getting z in terms of U. Please suggest me.

When I am trying to generate samples from

1

There are 1 best solutions below

0
On BEST ANSWER

As always you have to invert the distribution function $F_Z\,.$ Because $F_Z(0)=1/2$ and because $F_Z$ is increasing you get $$ F_Z^{-1}(y)=\left\{\begin{array}\displaystyle \frac{a\sqrt[3]{2y}-a}{2}&\text{ if }\quad y\in [0,1/2)\\ \frac{a-a\sqrt[3]{2-2y}}{2}&\text{ if }\quad y\in[1/2,1]\,.\end{array}\right. $$