如果随机数超过0.96,则Gamma_inv返回错误



Gamma_inv如果传递给它的随机数大约高于0.96,则返回一个错误。这种情况在Excel和VBA中都会发生。我在蒙特卡洛跑步,在40000多次跑步中,这种情况只发生了10次左右。以下是我使用它的方式。alpha和beta总是>0。如果"gammatrunc"=1,我会得到错误。如果我把它设置为0.95,我不会得到错误:

alpha = B * B * bsy2 ^ -2
beta = bsy2 * bsy2 / B
rand = Rnd * gammatrunc
B = WorksheetFunction.GAMMA_Inv(rand, alpha, beta)

错误如下:

输出错误消息

我很想知道为什么会发生这种事。

感谢

You can use this function to study a variable whose distribution may be skewed.
If any argument is text, Gamma_Inv returns the #VALUE! error value.
If probability < 0 or probability > 1, Gamma_Inv returns the #NUM! error value.
If alpha ≤ 0 or if beta ≤ 0, Gamma_Inv returns the #NUM! error value.
Given a value for probability, Gamma_Inv seeks that value x such that GAMMA_DIST(x, alpha, beta, TRUE) = probability. Thus, precision of Gamma_Inv depends on precision of Gamma_Dist. Gamma_Inv uses an iterative search technique. If the search has not converged after 100 iterations, the function returns the #N/A error value.

https://learn.microsoft.com/en-us/office/vba/api/excel.worksheetfunction.gamma_inv

可以使用VBA在代码中添加一些控件,如MIN和MAX。

最新更新