MATLAB Answers

How to generate Rayleigh distributed random variable with a specified mean and variance?

117 views (last 30 days)
Jonathan Mayers
Jonathan Mayers on 22 May 2016
Answered: possibility on 7 Feb 2018
For example:
x = mu + std*randn(row,col);
The above code generates a Gaussian random variable with mean mu and standard deviation std. Is there a way to do this for a Rayleigh distribution?

Answers (3)

possibility
possibility on 7 Feb 2018
Hey,
There is an easy method to generate values from a Rayleigh distribution.
Assume Z~Rayleigh(sigma). Since
Z=sqrt(X^2 + Y^2)
where X~N(0,sigma^2) and Y~N(0,sigma^2) independent random variables. So,
z= abs(sigma*randn(1)+1i*sigma*randn(1))
will generate a value from a Rayleigh distribution with parameter sigma.
I know it is quite late but may help someone else :)

Image Analyst
Image Analyst on 23 May 2016
You can use random() in the Statistics and Machine Learning Toolbox - it has lots of distributions in it. For Rayleigh it says:
The Rayleigh distribution is a special case of the Weibull distribution. If A and B are the parameters of the Weibull distribution, then the Rayleigh distribution with parameter b is equivalent to the Weibull distribution with parameters........
Since what John says is correct, maybe you can use a Weibull distribution???
If you don' thave that toolbox, see my attached Rayleigh demo.

John D'Errico
John D'Errico on 22 May 2016
Edited: John D'Errico on 22 May 2016
Um, you can't. A classic Rayleigh distribution has ONE parameter. Call it sigma.
https://en.wikipedia.org/wiki/Rayleigh_distribution
The mean is:
sqrt(pi/2)*sigma
The variance is:
(4-pi)/2*sigma^2
If you wish to match TWO parameters, the mean and variance, you won't in general be able to get both right, at least unless you are very lucky in your choice of the mean and variance.
If you choose some non-standard Rayleigh that has two parameters, depending on what they are, you may have a chance.

Community Treasure Hunt

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

Start Hunting!

Translated by