public class friction
{
public static double f(double Re,double eod)
{
// friction factor for turbulent flow 5000<Re<10^8
double f1=Math.log10(eod/3.7+5.74/ Math.pow(Re,0.9));
f1=1.325/(f1*f1);
return f1;
}

public static double fx(double X,double Re,double eod)
{
// colebrook equation to solve
// friction factor for turbulent flow 2000 < Re
double xx=2.0*Math.log10(eod/3.7+2.51/Re*X)+X;
return xx;
}

public  static double dfx(double X,double Re,double eod)
{
//derivative of colebrook equation
double xx;
xx = 1+2.0/(eod/3.7+2.51/Re*X)/Math.log(10.0)*2.51/Re;
return  xx;
}

public  static double fcol(double Re,double eod)
{
//solution of the colebrook equation
// by using newton method
double fi=f(Re,eod);
double x=1.0/ Math.pow(fi,0.5);
int nmax=50;
double tolerance=1.0e-10;
for(int i=0;i<nmax;i++)
{
double fx1=fx(x,Re,eod);
x-=fx1/dfx(x,Re,eod);
if(Math.abs(fx1)<tolerance) return 1.0/(x*x);
}
return 1.0/(x*x);
}

}