Function ZFactor(Tr, Pr) a = 0.064225133 b = 0.53530771 * Tr - 0.61232032 c = 0.31506237 * Tr - 1.0467099 - 0.57832729 / Tr ^ 2 d = Tr e = 0.68157001 / Tr ^ 2 f = 0.68446549 g = 0.27 * Pr Newton-Raphson iteration (commented due to unstability and convergence problems rho = 0.27 * Pr / Tr 'Initial guess rhoold = rho For i = 1 To 100 frho = a * rho ^ 6 + b * rho ^ 3 + c * rho ^ 2 + d * rho + e * rho ^ 3 * (1 + f * rho ^ 2) * Exp(-f * rho ^ 2) - g dfrho = 6 * a * rho ^ 5 + 3 * b * rho ^ 2 + 2 * c * rho + d + e * rho ^ 2 * (3 + f * rho ^ 2 * (3 - 2 * f * rho ^ 2)) * Exp(-f * rho ^ 2) rho = rho - frho / dfrho test = Abs((rho - rhoold) / rho) If test < 0.00001 Then Exit For rhoold = rho Next i ZFactor = 0.27 * Pr / rho / Tr
MATLAB: I need to convert this code(excell) to matlab language help
for loopwhile
Best Answer