逆日志正态分布

时间:2018-02-06 18:16:37

标签: vba excel-vba excel

如何在VBA中获取由日志正态分布生成的随机数? 我用了

    Dim upper As Double, lower As Double

    ' Declare 2 arrays 
    Dim irr(26) As Double
    Dim lirr(26) As Double

    ' set the upper and lower band
    upper = 0.125
    lower = 0.02

...
     lirr(i ) = WorksheetFunction.LogInv(Rand, (upper - lower), lower) + lower

但是我收到错误。

1 个答案:

答案 0 :(得分:1)

Option Base 1
Public Function LOGINV_SAMPLE(Optional n As Integer = 1, Optional md As Variant = 1, Optional stdv As Variant = 0) As Variant
'#Execute this as array formula i.e Cnt+Shft+Enter
 Dim x(), i, p As Variant
  ReDim Preserve x(n)
  For i = 1 To n Step 1
   Randomize
    p = Rnd()
   x(i) = Application.LogNorm_Inv(p, stdv, md)
 Next i

 LOGINV_SAMPLE = Application.Transpose(x)

End Function

这很有效。