i need to write a function that starts with two values for friction. one is initialized to .02. then it solves for the new friction value. after that it compares the friction values. if
|fnew-fstart|<=.001 it stops and returns the fnew value. if not it plugs fnew into the equation and solves for fnew again... does this make sense. i can't figure it out.
take a look...
CODE
double Friction_Factor(double surf_roughness, double pipe_diameter, double reynolds_number)
{
double friction_factor_old(0.2);
double friction_factor_new;
do
{
friction_factor_new=pow(-1/(((2*log10 (((surf_roughness/pipe_diameter)/3.7)+(2/(reynolds_number*sqrt (friction_factor_old)))))),2));
friction_factor_old=friction_factor_new;
}
while (abs(friction_factor_new-friction_factor_old>.001));
return friction_factor_new;
}