I'm using the moody function by ILDEBERTO DE LOS SANTOS RUIZ and newton method for solving colebrook white equation.
My code is
a0 = input('Enter initial guess: ');
e = input('Tolerable error for: ');
n = input('Enter maximum number of steps: ');
a2=0;
format short
for Q=[0.0001,0.0002,0.0005,0.001,0.002,0.005,0.01,0.02]
for Re=[10000,20000,50000,100000,200000,500000,1000000]
syms f
eq1=(-0.869*log((Q/3.7) + (2.523/(Re*sqrt(f)))))*(sqrt(f))-1;
g = diff(eq1);
g2= diff(g);
fa = eval(subs(eq1,f,a0));
ga = eval(subs(g,f,a0));
ga2 = eval(subs(g2,f,a0));
gg=abs((fa*ga2)/ga^2);
an=a0-(fa/ga);
if gg<1
disp('Convergent')
end
if fa~=0 && ga~=0
for i=1:n
a1= an;
fprintf('x%d = %.8f\n',i,a1)
[numRows, numCols] = size(a2);
a2(1, numCols+1) = a1;
a1= an;
if abs(a1-a0)<e
break
end
a0=a1;
end
end
moody(Q,Re) %moody function the part Im having problem
end
end
Where Q is epsilon/D I want to plot all my Q and Re that are in the loop on the same figure where moody diagram is
I tried the hold on
after the moody function but it showed me the same plot in the figure
EDIT: I changed the code and now I get diffrent figures saved to pc each time and I made them into a gif but I need it to be on same plot