[ hninel @ 11.08.2005. 17:39 ] @
Imam slijedeci kod u VB 6.0: Code: Option Explicit Dim CikTable() As Double Private Sub generateCikTable(ByVal k As Long, ByVal s As Long, ByVal beta As Double, theta As Double, ByVal AcWT As Double) 'this function generates a Cik table so these are calculated only once in the program Dim currentK As Long Dim i As Long Dim x As Long Dim Uk As Double 'faster than calculating twice Dim CikSum As Double Dim thisCik As Double ' Dim a() As Double ' ReDim a(1 To 4, 1 To 2) If k < 0 Then MsgBox "Error in generateCikTable, k must be equal to or greater than 0." End End If ReDim CikTable(0 To k, 0 To k) 'matrix, but half of it will be empty For i = 0 To k For currentK = i To k If i = currentK Then If currentK = 0 Then thisCik = 1 Else CikSum = 0 For x = 0 To i - 1 CikSum = CikSum + CikTable(x, currentK) Next x thisCik = 1 - CikSum End If Else Uk = calculateUi(s + currentK, s, beta, theta) * AcWT thisCik = (Uk * CikTable(i, currentK - 1)) / (Uk - calculateUi(s + i, s, beta, theta) * AcWT) End If CikTable(i, currentK) = thisCik Next currentK Next i End Sub Poziv ove procedure: Code: Call generateCikTable(B - s - 1, s, beta, theta, AcWT) Ja sam napisao ovu proceduru u C#-u ovako: Code: private void generateCikTable(long k, long s, double beta, double theta, double AcWT) { long currentK, i, x; double Uk = 0, CikSum, thisCik=0; this._cikTable = new double[k, k]; if (k<0) return; for (i=0; i<k; i++) { for (currentK = i; currentK < k; currentK++) { if (i == currentK) { if (currentK==0) {thisCik = 1;} else { CikSum = 0; for (x=0; x<i; x++) { CikSum = CikSum + _cikTable[x, currentK]; } thisCik = 1-CikSum; } } else { Uk = calculateUi(s + currentK, s, beta, theta) * AcWT; thisCik = (Uk * _cikTable[i, currentK - 1]) / (Uk - calculateUi(s + i, s, beta, theta) * AcWT); } _cikTable[i, currentK] = thisCik; } } } Podaci koje kreira u C# nisu identicni sa podacima procedure napisane u VB 6. Obje ove procedure kreiraju matricu, recimo cikTable[80][80]. Kada uporedim podatke, u obje funkcije, podaci postaju razliciti nakon otprilike 13-tog reda -> cikTable[13][0]. Do tada su tu negdje, ali zanemarljive greske. Interesuje me da nije nesto oko zaokruzivanja brojeva ili nisu isti double u VB 6.0 i u C#-u (ili nisam dobro ovo preveo)... Drugo pitanje: Kako da procesiram '<undefined value>', tj da provjerim da li postoji vrijednost. Kada provjeravam: if (obj!=null) ... kaze da nisam instancirao objekat. Objekat je tipa Hashtable. Hvala! |