|
|
How to generate random number given density function?
Hi All,
I need generate a random number x belongs to [0, 2*pi], given density function
f(x) = 1/ (2*pi) * { (a^2 - 1) / ( a^2 + 2*a*cos(x) + 1) } where a >=1.
Could you help me to solve the problem? Thank you very much.
Nguyen Van Tien
|
|
0
|
|
|
|
Reply
|
Tiên
|
11/27/2010 11:37:04 AM |
|
In short, you need to compute the cumulative distribution function and
then invert it and stick in the uniform distribution. See #6 in this
thread where I do the process for a Ralyeigh distribution.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/289740#772962
|
|
0
|
|
|
|
Reply
|
ImageAnalyst
|
11/27/2010 2:39:33 PM
|
|
"Tiên " <nguyenvantien812@gmail.com> wrote in message <icqqh0$19p$1@fred.mathworks.com>...
> Hi All,
> I need generate a random number x belongs to [0, 2*pi], given density function
> f(x) = 1/ (2*pi) * { (a^2 - 1) / ( a^2 + 2*a*cos(x) + 1) } where a >=1.
> Could you help me to solve the problem? Thank you very much.
> Nguyen Van Tien
- - - - - - - - -
You'll be glad to learn that the cumulative distribution function for your f(x) not only has a fairly simple expression, its inverse is also readily computable. You can look up the integral for the cumulative distribution in any good table of integrals. If you have trouble, I'll give integral formula to you.
Roger Stafford
|
|
0
|
|
|
|
Reply
|
Roger
|
11/27/2010 7:16:03 PM
|
|
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <icrldj$qo9$1@fred.mathworks.com>...
> "Tiên " <nguyenvantien812@gmail.com> wrote in message <icqqh0$19p$1@fred.mathworks.com>...
> > Hi All,
> > I need generate a random number x belongs to [0, 2*pi], given density function
> > f(x) = 1/ (2*pi) * { (a^2 - 1) / ( a^2 + 2*a*cos(x) + 1) } where a >=1.
> > Could you help me to solve the problem? Thank you very much.
> > Nguyen Van Tien
> - - - - - - - - -
> You'll be glad to learn that the cumulative distribution function for your f(x) not only has a fairly simple expression, its inverse is also readily computable. You can look up the integral for the cumulative distribution in any good table of integrals. If you have trouble, I'll give integral formula to you.
>
> Roger Stafford
- - - - - - - -
You haven't asked but I've decided to give you the cumulative distribution of that function you defined in case the integral table formulas proved to be too confusing. It is:
F(x) = 1/pi*atan((a+1)/(a-1)*tan((x-pi)/2))+1/2
for the range of numbers 0 <= x <= 2*pi. It is the definite integral of your f(x) from 0 to x. It assumes that a > 1. You will note that when x = 0, it is zero and when x = 2*pi, it is one, as a valid cumulative distribution should be. Its derivative is just f(x), though that takes some manipulation to demonstrate.
As you can see, the inverse of this function can readily be found and this will enable you to generate random variables with your given density function using the 'rand' function in accordance with a standard method which you can read about at:
http://en.wikipedia.org/wiki/Inverse_transform_sampling
or on ImageAnalyst's referenced thread.
Roger Stafford
|
|
0
|
|
|
|
Reply
|
Roger
|
11/28/2010 3:43:03 AM
|
|
|
3 Replies
497 Views
(page loaded in 0.052 seconds)
Similiar Articles: How to generate random number given density function? - comp.soft ...Hi All, I need generate a random number x belongs to [0, 2*pi], given density function f(x) = 1/ (2*pi) * { (a^2 - 1) / ( a^2 + 2*a*cos(x) + 1)... Generate noise model[Please help] - comp.soft-sys.matlab ...How to generate random number given density function? - comp.soft ... Generate noise model[Please help] - comp.soft-sys.matlab ..... function to get a function that can ... Creating random decimal numbers in C - comp.soft-sys.matlab ...Dear Ansgar, there is an implementation of Marsaglia's KISS random number generator in the C-Mex function SHUFFLE published in the FEX. Good luck, Jan Generating a `random' number between 0 and 1 with a higher ...How to generate random number given density function? - comp.soft ... Generating a `random' number between 0 and 1 with a higher ... How to generate random number ... are ... How to generate random noise with known P.S.D - comp.soft-sys ...... you how to generate such a distribution using the well known ... to get a function that can generate random ... ... power Spectral density ... how to generate random numbers ... Generating a uniform random rotation matrix - comp.soft-sys.matlab ...How to generate random number given density function? - comp.soft ... Hi All, I need generate a random number x belongs to [0 ... and then invert it and stick in the ... How to generate random number without replacement? - comp.lang ...I feel neither sorry nor that Perl should provide such a function. You are confusing generating random numbers with sampling a given data set. uniform random variable - comp.soft-sys.matlabHow to generate random number given density function? - comp.soft ... uniform random variable - comp.soft-sys.matlab How to generate random number given density function ... How to generate vector of random numbers in any interval (e.g. [-1 ...How to generate random number given density function? - comp.soft ... How to generate vector of random numbers in any interval (e.g. [-1 ... How to generate random number ... Generate Gaussian Process with a Specified Autocorrelation ...How to generate colored Noise - comp.soft-sys.matlab... profile spectral density as a function of frequency ... ... gaussian ... to get a function that can generate random ... How to generate random number given density function? - comp.soft ...Hi All, I need generate a random number x belongs to [0, 2*pi], given density function f(x) = 1/ (2*pi) * { (a^2 - 1) / ( a^2 + 2*a*cos(x) + 1)... Generate random numbers from specified distribution, parameters ...Event-Based Random Number -Generate random numbers from specified distribution ... also uses the Minimum and Maximum parameters to define its density function. Number of ... 7/24/2012 5:12:16 AM
|
|
|
|
|
|
|
|
|