clear , clc
fprintf(' \n <<< this program calculate Q in three branched pipes from three tanks >>> \n %12.5f ')
fprintf (' \n 1- Data for highest tank \n %12.5f')
E1=input ('\n Enter tank_ energy (m) : ');
f1=input (' Enter pipe_friction coefficient (m) : ');
d1=input (' Enter pipe_diameter (m) : ');
l1=input (' Enter pipe_length (m) : ');
fprintf (' \n 2- Data for intermediate tank \n %12.5f ')
E2=input ('\n Enter tank_ energy (m) : ');
f2=input (' Enter pipe_friction coefficient (m) : ');
d2=input (' Enter pipe_diameter (m) : ');
l2=input (' Enter pipe_length (m) : ');
fprintf (' \n 3- Data for lower tank \n %12.5f ')
E3=input ('\n Enter tank_ energy (m) : ');
f3=input (' Enter pipe_friction coefficient (m) : ');
d3=input (' Enter pipe_diameter (m) : ');
l3=input (' Enter pipe_length (m) : ');
R1=(.8*f1*l1)/(9.8*d1^5);
R2=(.8*f2*l2)/(9.8*d2^5);
R3=(.8*f3*l3)/(9.8*d3^5);
Ej=(E1+E3)/2;
Q1=((abs(E1-Ej))/(R1))^.5;
Q2=((abs(E2-Ej))/(R2))^.5;
Q3=((abs(E3-Ej))/(R3))^.5;
if E2<Ej
dQ=Q1-Q2-Q3;
elseif E2>Ej
dQ=Q1+Q2-Q3;
end
if dQ>0
iter=0;
while abs(dQ)>.0001
Ej=Ej+.001;
iter=iter+1;
q1=((abs(E1-Ej))/(R1))^.5;
q2=((abs(E2-Ej))/(R2))^.5;
q3=((abs(E3-Ej))/(R3))^.5;
if Ej>E2
dQ=q1-q2-q3;
else
dQ=q1+q2+q3;
end
end
fprintf('\n Q at 1st pipe(m^3/s)= %12.5f\n ',q1)
fprintf('\n Q at 2nd pipe(m^3/s)= %12.5f\n ',q2)
fprintf('\n Q at 3rd pipe(m^3/s)= %12.5f\n ',q3)
fprintf('\n Energy at junction(m)= %12.5f\n ',Ej)
fprintf('\n no.of iteration= %12.5f\n',iter)
elseif dQ<0;
iter=0;
while abs(dQ)>.0001
Ej=Ej-.001;
iter=iter+1;
q1=((abs(E1-Ej))/(R1))^.5;
q2=((abs(E2-Ej))/(R2))^.5;
q3=((abs(E3-Ej))/(R3))^.5;
if Ej>E2
dQ=q1-q2-q3;
else
dQ=q1+q2+q3;
end
end
fprintf('\n Q at 1st pipe(m^3/s)= %12.5f\n ',q1)
fprintf('\n Q at 2nd pipe(m^3/s)= %12.5f\n ',q2)
fprintf('\n Q at 3rd pipe(m^3/s)= %12.5f\n ',q3)
fprintf('\n Energy at junction(m^3/s)= %12.5f\n ',Ej)
fprintf('\n no.of iteration(m^3/s)= %12.5f\n',iter)
end