2016-07-31 3 views
0

私は数式を持っており、これを理解するのに苦労し、Javaコードに変換されました。1つの数式を理解するのが難しい

私はいくつかのコードを書かれているし、それは多くを助けていない

enter image description here

を[添付された画像は、私が解決しなければならない式です]。式Iは、CとPの値を持っているとN.以下

は私が対応するExcelの数式を持っているが、私はそれを変換する方法がわからない

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)))); 
    } 

を使用しているコードで検索する必要があります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 

私はこれを1週間ほど前に作業しており、解決できませんでした。体がこれを解決できれば、大きな助けになるはずです。前もって感謝します。

Vivek

+0

あなたが望むものは明確ではありません。あなたのJavaモジュールコードは 'c'、 ' n'と 'p'をとりますが、何も返しません。 Excel VBAコードでは、さまざまな変数がどのようになるかは完全にはわかりません。おそらく 'intJ'は' i'なので、 'intC'は' c'(10)となります。 'intI'は1から10000までループする' n'ですが、なぜですか? 'intLTPD'(' B1')は 'p'とすることができます。それで、式に基づいて意味のある方法で変数に名前を付けるのはなぜですか? 'intCL'(' B2')とは何ですか?与えられた式の結果である 'intCalcF'との関係はどうですか?そして、VBAコードは10行の結果を書きます。 Javaコードは正確に何をしますか? –

+0

質問を編集して回答を得たい場合は、さらに情報を提供してください。 Btw .:あなたの数式中の「n choose i」という用語は、[二項係数](https://en.wikipedia.org/wiki/Binomial_coefficient)です。それはExcelの[COMBIN](https://support.office.com/en-us/article/COMBIN-function-12a3f276-0a21-423a-8de6-06990aaf638a)が計算するものです。 –

+0

Btw:[BINOM.DIST](https://support.office.com/en-us/article/BINOM-DIST-function-c5ae37b6-f39c-4be2-94c2-509a1480770c) - [Java](http: /lacinato.com/cm/software/othersoft/binomdist) –

答えて

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)))); 
    } 
} 

私はまだコードをテストしていません。

関連する問題