Skip to content

Instantly share code, notes, and snippets.

@kcajf
Created February 21, 2014 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kcajf/283a2ef905ae231419f2 to your computer and use it in GitHub Desktop.
Save kcajf/283a2ef905ae231419f2 to your computer and use it in GitHub Desktop.
MATLAB friction factor iterator
Re_guess = 2e4;
r = 0.002; % roughness
R = 0.075; % pipe radius
D = 2*R;
p = 1000; % density
visc = 1.141e-3; % viscosity
latest_q = q_from_f(f_guess, R)
penultimate_q = 1;
Re = Re_guess;
f = Moody(Re_guess, r);
tolerance = 0.001;
while (penultimate_q - latest_q)/penultimate_q > tolerance
Re = (4*latest_q*p) / (pi*visc*D);
f = Moody(Re, r);
penultimate_q = latest_q;
latest_q = q_from_f(f, R)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment