zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    消息队列设计
    抓包工具Fiddler
    分布式系统和CAP
    Topshelf组件
    Parallel.For
    MVC插件
    Azure Messaging-ServiceBus Messaging
    MVC
    requireJS
    第一次react-native项目实践要点总结 good
  • 原文地址:https://www.cnblogs.com/len3d/p/2980813.html
Copyright © 2011-2022 走看看