Generating Gaussian random numbers

Source: Internet
Author: User
Tags natural log

Rand (1) returns one pseudo random number between 0 and 1 correct? (I don't knoW MATLAB myself but I know what you can do with the random number)

Use the box-Muller transform.

This transform says is U1 and U2 are two independent Uniform Random Variables on 0, 1, I. e., UI ~ U (0, 1), then

Z1 = SQRT (-2 * log (U1) * sin (2 π U2)
Z2 = SQRT (-2 * log (U1) * Cos (2 π U2)

Where Z1 and Z2 are both standard normal random variables.
And log is the natural log.

Forgive my syntax here, but like I said, I don't know MATLAB. But these couple lines shoshould help you generate normal random variables X1 and X2 with mean μ andstandard deviation σ.

MU = 5; // enter the mean you want or need
Sigma = 3; // enter the standard deviation you want or need

U1 = rand (1 );
U2 = rand (2 );

Z1 = SQRT (-2 * log [U1]) * sin [2 * pI * U2];
Z2 = SQRT (-2 * log [U1]) * Cos [2 * pI * U2];

X1 = Mu + z1 * sigma;
X2 = Mu + Z2 * sigma;

 

Http://www.taygeta.com/random/gaussian.html

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.