I want to generate data based on given probability distribution.
f(y) = alpha*exp(-y/beta1)+(1-alpha)*exp(-y/beta2)
I tried to use the way as follows. I used inverse function and reversed a probability distribution function to get the inverse result.
syms yf(y) = alpha*exp(-y/beta1)+(1-alpha)*exp(-y/beta2);g = finverse(f);
This method doesn't work since "Functional inverse cannot be found. " However, I find another code written by a programmer. This code can generate the data series perfectly. But I cannot understand its thought. Could you help me explain it?
m = [beta1;beta2]; % the two means
t = 1 + (randn(n,1)<alpha); % randomly select 1st or 2nd mean
X = m(t) .* -log(rand(n,1)); % generate exponentials with selected mean
Best Answer