Generating Gaussian Random Numbers

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 should 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

 

posted on 2013-03-25 15:08 Len3d 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/len3d/archive/2013/03/25/2980813.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值