How to generate samples from a given density function in matlab. The PDF of the random variable is given by
First I have evaluated its CDF which is given as
Note from
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. So I inverted my distribution function and also equate with rand command which is formed as uniform distribution. When rand produces a value less than 0.5 I have taken the value of the inverse distribution function where z less than zero. and when rand produces I have taken the inverse distribution of the when z is greater than 0. I have attached my code and results too. computational CDF is coming correct but simulation results are not correct. Please suggest me where I am wrongl
When I am trying to generate samples from .
z = linspace(-a/2,a/2,100000);
F_z(i) = (1/2*(a^3))*(a+2*z(i))^3;
F_z(i) = (0.5/a^3)*(a+2*z(i))^3;
F_z(i) = -(0.5/a^3)*((a-2*z(i))^3-a^3) + 0.5;
z_1(i) = (a/2)*((2*x(i))^(1/3)-1);
z_2(i)= (a/2)*(1 - (2 -2*x(i))^(1/3));