## colebrook iterative equation in a for loop

### Omar Almahallawy (view profile)

on 1 Jun 2019
Latest activity Answered by KALYAN ACHARJYA

on 1 Jun 2019

### KALYAN ACHARJYA (view profile)

DoM = [0.7620 0.8128 0.8636 0.9144 0.9652 1.0160 1.0668 1.1176 1.1684 1.2192]
Re= [319130 299180 281590 265940 251940 239350 227950 217590 208130 199460]
Ks=0.000045
Er=10.^-8
Fo=0.01;
for I=0:1:10^8;
Fn=(1./(-4.*log10(Ks./(3.71.*DoM))+(1.26./(Re.*sqrt(Fo))))).^2
E=abs((Fn-Fo)/Fn)
if E<=Er
Fn=Fn ;break;
elseif E>Er
Fn=Fo;
end
end
i have an iterative equation where i have to set an initial value for Fo=0.01 to ahieve the Left hand side (Fn)
then calculate the absolute error (E)
after that compare the absolute error (E) with the specified Erorr (Er)
if the absolute error (E) is greater than the specified Error (Er)
replace Fo with the new Fn achived earlier
and calculate for a new Fn
until the absolute error is less than the specified error (Er)
then show the final value of Fn

### KALYAN ACHARJYA (view profile)

on 1 Jun 2019

This way you can more easily implement the same code, please check the login of the code.
DoM=[0.7620 0.8128 0.8636 0.9144 0.9652 1.0160 1.0668 1.1176 1.1684 1.2192];
Re=[319130 299180 281590 265940 251940 239350 227950 217590 208130 199460];
Ks=0.000045;
Er=10.^-8;
Fo=0.01;
E=10.^-20; %initialize any value less than Er
while E<Er
% Check the internal while loop carefully
Fn=(1./(-4.*log10(Ks./(3.71.*DoM))+(1.26./(Re.*sqrt(Fo))))).^2;
E=abs((Fn-Fo)/Fn); % may be change required, it run for once only then E>Er, while loop break
Fo=Fn;
end
disp(Fn);