0
我的問題:我想使用內部循環(i)的最後計算值作爲外部循環(j)。但是當(j = 2和i = 1)時,它開始採取錯誤的值。我可能會犯錯誤? 我沒有顯示任何輸入,只需要幫助理解外部循環。更新外部循環的值,For循環在另一個For循環
For j = 1 To 4
wf = (2 * j - 1) * wff
For i = 1 To 3
PZ = (1 - GP/GT) * pzi
p = fPpz(PZ, ppc, Tpr)
z = p/PZ
pavg = (p + pwf)/2
Bg_p = Bg(z, T, p, psc, Tsc)
mug_p = (mugas(SGg, p, T))/1000
mug_pavg = (mugas(SGg, pavg, T))/1000
Z_pavg = fZ(pavg/ppc, Tpr)
Bg_pavg = Bg(Z_pavg, T, pavg, psc, Tsc)
Time2 = 1 + Time1
delTime = Time2 - Time1
PIndex = PIndn(kres, hres, mug_pavg, Bg_pavg, JDf)
dpdlf = pf(p, pwf, xf, PIndex, tauyhb, nhb, khb, wfg_new, Hf, wf, Bg_pavg, dpdlold,mug_pavg, Bg_p, mug_p)
dpdlnew = dpdlf
If dpdlf < 0 Then
dpdlnew = dpdlold
End If
qg = FrGasF(tauyhb, nhb, khb, wfg_new, Hf, wf, dpdlnew, mug_p)
GP = 2 * qg * delTime * 60/Bg_p + GP
qhb = FrHBF(tauyhb, nhb, khb, wfg_new, Hf, wf, dpdlnew)
wfg_old = qhb/xf/Hf * delTime * 60/2
'=======For next iteration (i+1)======='
wfg_new = wfg_new + wfg_old
Time1 = Time2
dpdlold = dpdlnew
Next i
Next j
它在顯示錯誤的值時,j = 2,i = 1是使用來自j = 1的
wfg_new
值?外循環只是向wff提供奇數乘法器(1,3,5,7)。 – hstay,它也比i循環運行這些值...當j = 4時出現錯誤的值... – user2981046
我仍然不明白什麼是錯誤的或者你想達到什麼目的。 – hstay