user2981046
user2981046

Reputation: 25

updating values of outer loop, For loop in another For loop

My Question: I want to use the last calculated values of the inner loop (i) for outer loop (j). But it starts taking wrong values when (j=2 and i=1 ). where i might have a mistake? I am not showing any inputs , just need help in understanding the outer loop.

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

Upvotes: 0

Views: 46

Answers (1)

barrowc
barrowc

Reputation: 10689

Should you be setting wfg_new = 0 in the outer j loop? Otherwise, j=2, i=1 is using the wfg_new value from j=1, i=3 when you call the pffunction

Upvotes: 1

Related Questions