Combine rand function with exponential cdf

1 回表示 (過去 30 日間)
evan lan
evan lan 2012 年 10 月 10 日
I would like to produce random random results from cdf (cumulative distribution function) of exponential distribution. I know that exponential cdf is:
F=1-exp(-x/mu)
how could I combine it with rand to produce random results? Thanks in advance!

回答 (2 件)

Wayne King
Wayne King 2012 年 10 月 10 日
Perhaps you're thinking of generating exponentially distributed random numbers based on a uniform (0,1) RV?
x = rand(1000,1);
mu = 2;
y = -mu*log(x);
hist(y)

owr
owr 2012 年 10 月 10 日
Search in the Statistics Toolbox Documentation for "Inversion Methods"(You can look online if you dont have access to the Toolbox). There is a common trick where you generate uniformly distributed random numbers using "rand", then pass them all through the inverse cdf function for the distribution you are interested in. The documentation even shows an example for the exponential distribution. This requires that you have a function that calculate the inverse cdf value for a given input. If you have Stats, many of these are built in. If you dont, you'll need to write that part yourself.
Here's a link to the 2012a doc:

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by