Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
random numbers

Subject: random numbers

From: yugandhar ch

Date: 19 May, 2012 03:27:31

Message: 1 of 3

how to generate random numbers from double exponential distribution,pl give function

Subject: random numbers

From: Nasser M. Abbasi

Date: 19 May, 2012 03:48:03

Message: 2 of 3

On 5/18/2012 10:27 PM, yugandhar ch wrote:
> how to generate random numbers from double exponential distribution,pl give function

I assume you are asking becuase Matlab does not have this distribution.
I did not check.

There is a known general method which can be used to
generate random numbers from different distributions by
only using the uniform random number generator.

This is called the F^-1 method. This is the only I know
about now, since that is what we learned at school.

I'll show you how I did one for the exponential distribution with
parameter lamda. You can use for the double exponential distribution.

The CDF for the exponential distribution is given by

   F(x)=1-exp(-lambda*x) x>=0, and 0 otherwise

Hence the inverse CDF comes out to be (little algebra)

         F^-1(y)=-1/lambda * ln(1-y)

Now, generate a random number from U(0,1), this is just using
matlab's rand, see help. Let this number of z.

Then a random number from the exponential distribution will
be

        -1/lambda*ln(1-z)

i.e. the inverse CDF function is a function of the U(0,1) random
numbers.

So, generate a number from U(0,1), and call the above function, this
will give you the random number from the exponential distribution.

Just do the same for any other distributions. The trick is to be
able to determine the inverse cdf.

I just looked up the double expo. distribition. The CDF is
given by exp(x)/2 for x<0 and 1-exp(-x)/2 otherwise.

Hence it is easy to apply the F^-1 to it.

--Nasser

Subject: random numbers

From: Roger Stafford

Date: 19 May, 2012 04:37:26

Message: 3 of 3

"yugandhar ch" <yug_0203@rediffmail.com> wrote in message <jp73v3$82a$1@newscl01ah.mathworks.com>...
> how to generate random numbers from double exponential distribution,pl give function
- - - - - - - -
  Nasser has done all the hard work explaining the theory behind this method using the 'rand' function.

  I give here the formula obtained from the Wikipedia site

 http://en.wikipedia.org/wiki/Laplace_distribution

for the Laplace distribution, also known as the double exponential distribution, with 'mu' as "location parameter" and 'b' as "scale parameter":

 r = rand(n,m); % Get random values uniformly on (0,1)
 x = mu - b*sign(r-1/2).*log(1-2*abs(r-1/2));

  Note that there is also an entirely different distribution known as the "Gumbel distribution", also referred to as the double exponential distribution, which would require a quite different formula than that above.

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us