title: solveing Colebrook equation using Newton in Matlab
body: <p>I make this script:</p>
  
  <p>This part is for creating de variables Re and Ru so, I can replace use another. Next, create the expression so MATLAB can derivate it.</p>
  
  <pre><code>Re = 152788; % Reynolds
  Ru = 4e-05; % roughnesss
  syms x a b
  dy = subs(1/sqrt(x)+2*log10((a/3.7)+2.51/(b*sqrt(x))), [a, b], [Ru,Re]);
  df1 = diff(dy);
  </code></pre>
  
  <p>This is the script for Newton-Rapson, it works for other expressions.</p>
  
  <pre><code>f=inline(dy);
  df=inline(df1);
  x0=input('Enter the initial value of x; x0:  ');
  precis=input('Enter the calculation precision; precis:  ');
  it=0;
  x=x0;
  d=f(x)/df(x);
  fprintf('\n %6s %7s  \n ','Iter.','x');
  while abs(d)&gt;precis
  fprintf('\n %8.4f %8.4f  \n',it,x);
  x1=x-d;
  it=it+1;
  x=x1;
  d=f(x)/df(x);
  end;
  fprintf('\n %8.4f %8.4f  \n',it,x);
  </code></pre>
  
  <p>When I run the script the iteration never ends, go on to infinity. The friction factor obtains for the data is 0.016</p>