难以理解一个数学公式

时间:2016-07-31 17:20:54

标签: java excel discrete-mathematics

我有一个数学公式,很难理解这一点并转换为Java代码。

[附图是我必须解决的公式]

enter image description here

我已经编写了一些代码,并没有多大帮助。在公式中,我有C和P的值,需要找到N.

以下是我使用过的代码

public static Double sigmaSum(int c, int n, Double p){
    Double sum = 0.00;
    for(int i=0; i<c; i++){
    for(int j=i; j<n;j++){
    sum += ((Math.pow(p, j)) * (Math.pow((1-p), (n-j))));
   }

我有一个相应的excel公式,但我不知道如何将其转换为java。

Option Explicit
Dim intLTPD, intCL, intC, intCalcF, intK, intComboNum, intComboDen1, intI, intJ, intComboDen2, intCombo, intL As Integer
Dim lngSampleSize As Long

Sub macBinSampPlan()
'
intLTPD = (Range("B1") / 100)
intCL = Range("B2") / 100
'intC = Int(Range("B3"))
Cells.Range("A6").Select

intCombo = 0
intCalcF = 0
intI = 0
intJ = 0

For intC = 0 To 10
    For intI = 1 To 10000
        For intJ = 0 To intC
            If intI >= intJ Then
                intCombo = Application.WorksheetFunction.Combin(intI, intJ)
                intCalcF = intCalcF + (intCombo * (Application.WorksheetFunction.Power(intLTPD, intJ)) * (Application.WorksheetFunction.Power((1 - intLTPD), (intI - intJ))))
            Else
                Exit For
            End If
        Next intJ
        If (intCalcF - (1 - intCL)) / intCalcF <= intLTPD Then
            lngSampleSize = intI
            Exit For
        Else
            intCombo = 0
            intCalcF = 0
        End If
    Next intI
    ActiveCell = intC
    ActiveCell.Offset(0, 1).Range("A1").Select
    ActiveCell = lngSampleSize + 1
    ActiveCell.Offset(1, -1).Range("A1").Select
Next intC

End Sub

我正在研究这个问题大约一个星期而且无法解决。如果某个机构可以解决这个问题,那将是一个很大的帮助。提前谢谢。

的Vivek

1 个答案:

答案 0 :(得分:0)

你的二项式实现方式似乎是错误的。根据您的公式,代码应该是:

public static Double sigmaSum(int c, int n, Double p){
    Double sum = 0.00;
    for(int i=0; i<c; i++){
    sum += ((CombinatoricsUtils.binomialCoefficientDouble(n,i)) * (Math.pow(p, i)) * (Math.pow((1-p), (n-i))));
   }
}

我还没有测试过代码。