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

55 次查看(过去 30 天)
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?

回答(3 个)

possibility
possibility 2018-2-7
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 2016-5-23
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 2016-5-22
编辑:John D'Errico 2016-5-22
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