我的问题:当我在SUb中调用它时它工作正常。但它给出了“pf”值的一个高跳跃我想给出一个条件,即pf总是小于dpdlold ......我尝试了不同的方法,但没有任何效果......
代码从这里开始:
Public Function pf(p, pwf, xf, PI, tau, n, k, wg, Hf, wf, Bg, dpdlold, mug, Bg_p, mug_p)
Dim i, j As Integer
Dim error As Double
Dim pj As Double
Dim pj1 As Double
Dim pj0 As Double
Dim e As Double
j = 100
i = 0
error = 1000
pj0 = dpdlold
pj = pj0
e = 0.001
While (error > e) And (i < j)
qgr = FrGas(tau, n, k, wg, Hf, wf, pj, mug_p)
pj1 = (p - pwf - 2 * qgr / PI) / xf
error = Abs(pj1 - pj)
pj = pj1
i = i + 1
Wend
pf = pj
End Function
答案 0 :(得分:0)
如何将循环更改为以下内容:
While (error > e) And (i < j)
qgr = FrGas(tau, n, k, wg, Hf, wf, pj, mug_p)
pj1 = (p - pwf - 2 * qgr / PI) / xf
error = Abs(pj1 - pj)
if pj1 > dpdlold Then pj1 = dpdlold
pj = pj1
i = i + 1
Wend
现在,如果pj1
太大,它将被“剪裁”为dpdlold
的值。如果它达到限制两次,则连续估计中的“误差”将为零并且它将停止。
由于您提供的信息有限,我能做的最好......