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