Hi all
I’m trying to solve an equation via an iterative method. The VB code below shows a simple loop I’ve created to solve for Nc. Stricly speaking, Nc is found when when “Term” is equal to 0.
I’m fairly new to VBA and would really like a few pointer on how to make this sort of routine more efficient.
Thanks
CODE:
******************************************************************
Function Type1_and_2_Area(inlet_P, back_P, Omega)
Dim Pc As Single
Dim Po As Single
Dim Pa As Single
Dim Nc As Single
Dim Term As Double
'===Conversions======
Po = inlet_P * 14.50377 '====Convert from bara to psia
'===Determine Critical/Non Critical Flow======
'First find Nc:
Nc = 0
Do
Nc = Nc + 0.00001
Term = (Nc ^ 2) + ((Omega ^ 2 - (2 * Omega)) * ((1 - Nc) ^ 2)) + (2 * (Omega ^ 2) * Log(Nc)) + ((2 * Omega ^ 2) * (1 - Nc))
Loop Until Term < 0.00001 ' Loop until terms become small
****Some code missing***
End Function
I’m trying to solve an equation via an iterative method. The VB code below shows a simple loop I’ve created to solve for Nc. Stricly speaking, Nc is found when when “Term” is equal to 0.
I’m fairly new to VBA and would really like a few pointer on how to make this sort of routine more efficient.
Thanks
CODE:
******************************************************************
Function Type1_and_2_Area(inlet_P, back_P, Omega)
Dim Pc As Single
Dim Po As Single
Dim Pa As Single
Dim Nc As Single
Dim Term As Double
'===Conversions======
Po = inlet_P * 14.50377 '====Convert from bara to psia
'===Determine Critical/Non Critical Flow======
'First find Nc:
Nc = 0
Do
Nc = Nc + 0.00001
Term = (Nc ^ 2) + ((Omega ^ 2 - (2 * Omega)) * ((1 - Nc) ^ 2)) + (2 * (Omega ^ 2) * Log(Nc)) + ((2 * Omega ^ 2) * (1 - Nc))
Loop Until Term < 0.00001 ' Loop until terms become small
****Some code missing***
End Function