How to generate mixed exponential distribution random number using the command in MATLAB?
Show older comments
How to generate mixed exponential distribution random number using the command in MATLAB? because mixexprnd function does not exist in R2013. Thank you for your help
2 Comments
David Goodmanson
on 19 Apr 2017
Hello Noor, could you supply an expression for the distribution you would like to generate?
Noor
on 19 Apr 2017
Accepted Answer
More Answers (1)
David Goodmanson
on 19 Apr 2017
Hello Noor, The function below agrees with the function cited above for several choices of parameters that I have tried. For 10000 points, cited function takes 40 sec. and this function takes .009 sec.
function R = randmixexp(a,b1,b2,n)
%
% random numbers taken from mixed exponential distribution
% pdf = a*(1/b1)*exp(-x/b1) + (1-a)*(1/b2)*exp(-x/b2)
% cdf = a*(1-exp(-x/b1)) + (1-a)*(1-exp(-x/b2))
%
% R = randmixexp(a,b1,b2,n)
if nargin < 4; n=1; end
r = rand(1,n);
ind = r<a;
nind = ~ind;
r = rand(1,n);
R(ind) = -log(r(ind))*b1;
R(nind) = -log(r(nind))*b2
% David Goodmanson
3 Comments
Noor
on 20 Apr 2017
Noor
on 20 Apr 2017
David Goodmanson
on 20 Apr 2017
I guess it is telling you that you are not supplying enough input arguments to the function. I just tried randmixexp(.2,1,2,100) and it worked fine.
Categories
Find more on Creating and Concatenating Matrices 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!