colebrook iterative equation in a for loop

조회 수: 4 (최근 30일)
Omar Almahallawy
Omar Almahallawy 2019년 6월 1일
답변: KALYAN ACHARJYA 2019년 6월 1일
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
KALYAN ACHARJYA 2019년 6월 1일
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);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by