How to generate data based on uninvertible probability distribution function?
Show older comments
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 y
f(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
Accepted Answer
More Answers (0)
Categories
Find more on Uniform Distribution (Continuous) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!