@@ -313,7 +313,7 @@ Private Sub Class_Initialize()
313313 AscDecSymbol = 46
314314 P_GALLOPING_MODE = True
315315 P_FORMATRESULT = False
316- BuildinFunctIDList = " abs;floor;achisq;asin;acos;aerf;afishf;agauss;asc;anorm;atn;astudt;array;avg" & _
316+ BuildinFunctIDList = " abs;floor;achisq;asin;acos;aerf;afishf;agauss;asc;anorm;atn;astudt;array;avg;beta.dist " & _
317317 " ;betainv;ceil;chisq;cholesky;cholinverse;cholsolve;chr;cos;choose;date;dateadd;datediff" & _
318318 " ;datepart;dateserial;datevalue;day;ddb;det;erf;exp;fishf;fit;format;fv;fzero" & _
319319 " ;gamma;gammaln;gauss;get;hour;ibeta;iff;inverse;ipmt;irr;lcase;left;len;log;lgn" & _
@@ -323,7 +323,7 @@ Private Sub Class_Initialize()
323323 " ;syd;tan;timeserial;timevalue;tinv;tinv_1t;tinv_2t;trim;ucase;weekday" & _
324324 " ;weekdayname;year"
325325 BuildinFunctNameList = " Absolute;aFloor;ACHISQ;ArcSin;ArcCos;AERF;AFISHF;AGAUSS;ASCII;ANORM;ArcTan" & _
326- " ;ASTUDT;strArray;Average;BETAINV;aCeiling;CHISQ;CholeskyDec;CholeskyInverseMatrix" & _
326+ " ;ASTUDT;strArray;Average;Beta_Distribution; BETAINV;aCeiling;CHISQ;CholeskyDec;CholeskyInverseMatrix" & _
327327 " ;CholeskySolve;ASCIIchr;Cosin;aChoose;aDate;aDateAdd;aDateDiff;aDatePart;aDateSerial" & _
328328 " ;aDateValue;aDay;aDDB;MatrixDeterminant;ERF;ExpEuler;FISHF;CurveFit" & _
329329 " ;aFormat;aFV;FunctionZero;Gamma;GammaLN;GAUSS;GET;aHour;iBETA;aIff;InverseMatrix" & _
@@ -1537,6 +1537,102 @@ Private Function BETAINV_(p As Double, A As Double, B As Double) As Double
15371537 BETAINV_ = x
15381538End Function
15391539
1540+ ''' < summary>
1541+ ''' Returns the beta distribution.
1542+ ''' < /summary>
1543+ ''' < param name=" x"> The value between A and B at which to evaluate the function.< /param>
1544+ ''' < param name=" alpha"> Shape parameter alpha.< /param>
1545+ ''' < param name=" beta"> Shape parameter beta.< /param>
1546+ ''' < param name=" Cumulative">
1547+ ''' A logical value that determines the form of the function. If cumulative is TRUE,
1548+ ''' BETADIST returns the cumulative distribution function; if FALSE, it returns
1549+ ''' the probability density function (PDF).
1550+ ''' < /param>
1551+ ''' < param name=" A"> Optional. A lower bound to the interval of x.< /param>
1552+ ''' < param name=" B"> Optional. An upper bound to the interval of x.< /param>
1553+ Private Function BETADIST(ByRef expression As String, ByRef fName As String) As String
1554+ Dim argsCount As Long
1555+ Dim tmpData() As String
1556+ Dim tmpEval As String
1557+ Dim LB As Long, UB As Long
1558+
1559+ On Error GoTo err_Handler
1560+ tmpData() = SplitArgs(expression)
1561+ LB = LBound(tmpData)
1562+ UB = UBound(tmpData)
1563+ argsCount = UB - LB + 1
1564+ Select Case argsCount
1565+ Case 4
1566+ tmpEval = BETAPDF_EXCEL( _
1567+ CDbl(tmpData(LB)), _
1568+ CDbl(tmpData(LB + 1)), _
1569+ CDbl(tmpData(LB + 2)), _
1570+ CBool(tmpData(LB + 3)), _
1571+ 0, 1)
1572+ Case 6
1573+ tmpEval = BETAPDF_EXCEL( _
1574+ CDbl(tmpData(LB)), _
1575+ CDbl(tmpData(LB + 1)), _
1576+ CDbl(tmpData(LB + 2)), _
1577+ CBool(tmpData(LB + 3)), _
1578+ CDbl(tmpData(LB + 4)), _
1579+ CDbl(tmpData(UB)))
1580+ Case Else
1581+ tmpEval = e_ValueError
1582+ BuildErrMessage errMissingArgsOrTooManyArgs, d_lCurly & fName & d_rCurly
1583+ End Select
1584+ BETADIST = tmpEval: Erase tmpData
1585+ Exit Function
1586+ err_Handler:
1587+ BETADIST = e_ValueError
1588+ BuildErrMessage errEvalError, d_lCurly & fName & d_rCurly & " | Error#: " & err.Number & d_Space & _
1589+ d_lParenthesis & err.Description & d_rParenthesis
1590+ End Function
1591+
1592+ Private Function BETALN_(x As Double, y As Double) As Double
1593+ BETALN_ = GAMMALN_(x) + GAMMALN_(y) - GAMMALN_(x + y)
1594+ End Function
1595+
1596+ Private Function BETAPDF_(x As Double, Alpha As Double, Beta As Double) As Double
1597+ BETAPDF_ = Exp((Alpha - 1) * Log(x) + (Beta - 1) * Log(1 - x) - BETALN_(Alpha, Beta))
1598+ End Function
1599+
1600+ Private Function BETAPDF_EXCEL(x As Double, Alpha As Double, _
1601+ Beta As Double, Cumulative As Boolean, _
1602+ Lower_Bound As Double, _
1603+ Upper_Bound As Double) As Variant
1604+ Dim z As Double
1605+ Dim range_ As Double
1606+
1607+ If Upper_Bound > Lower_Bound Then
1608+ If x > Lower_Bound And x < Upper_Bound Then
1609+ range_ = (Upper_Bound - Lower_Bound)
1610+ z = (x - Lower_Bound) / range_
1611+ If Cumulative Then
1612+ BETAPDF_EXCEL = iBETA_(z, Alpha, Beta)
1613+ Else
1614+ BETAPDF_EXCEL = BETAPDF_(z, Alpha, Beta) / range_
1615+ End If
1616+ Else
1617+ If x = Lower_Bound Or x = Upper_Bound Then
1618+ If Cumulative Then
1619+ If x = Upper_Bound Then
1620+ BETAPDF_EXCEL = 1
1621+ Else
1622+ BETAPDF_EXCEL = 0
1623+ End If
1624+ Else
1625+ BETAPDF_EXCEL = 0
1626+ End If
1627+ Else
1628+ BETAPDF_EXCEL = " #NUM!"
1629+ End If
1630+ End If
1631+ Else
1632+ BETAPDF_EXCEL = " #NUM!"
1633+ End If
1634+ End Function
1635+
15401636Private Sub BottomLevelEval(ByRef aToken As token)
15411637 On Error GoTo BLevelEval_errHanlder
15421638 If aToken.OperationToken < 100 Then ' Arithmetic operators
@@ -2728,6 +2824,8 @@ Private Function EvalFunction(ByRef Argument As String, ByRef FunctionName As St
27282824 EvalFunction = Asc_(Argument, FunctionName)
27292825 Case " Average"
27302826 EvalFunction = average(Argument, FunctionName)
2827+ Case " Beta_Distribution"
2828+ EvalFunction = BETADIST(Argument, FunctionName)
27312829 Case " BETAINV"
27322830 EvalFunction = BETAINV(Argument, FunctionName)
27332831 Case " Cosin"
0 commit comments