2009-12-15 41 views

回答

4

以下是使用approximation from wikipedia的代码,如Peter Mortensen的回复中所述 原始积分为Abramowitz and Stegun

 function erf(x) { 
      var z; 
      const ERF_A = 0.147; 
      var the_sign_of_x; 
      if(0==x) { 
       the_sign_of_x = 0; 
       return 0; 
      } else if(x>0){ 
       the_sign_of_x = 1; 
      } else { 
       the_sign_of_x = -1; 
      } 

      var one_plus_axsqrd = 1 + ERF_A * x * x; 
      var four_ovr_pi_etc = 4/Math.PI + ERF_A * x * x; 
      var ratio = four_ovr_pi_etc/one_plus_axsqrd; 
      ratio *= x * -x; 
      var expofun = Math.exp(ratio); 
      var radical = Math.sqrt(1-expofun); 
      z = radical * the_sign_of_x; 
      return z; 
     } 
12

我对高斯近似做了一些研究。 (Math.random())+ Math.random()+ Math.random()+ Math.random()+ Math.random()+数学。数学公式随机() - 3);

这个技巧可能看起来很丑,但它会给你一个平均值和sigma²= 1/2的预期。

我希望这会有所帮助。

+1

这是有效的,因为中心极限定理 – sauerburger 2015-10-15 11:11:17