function demoHeadLoss
% demoHeadLoss  Head loss problem in Example 8.8 in Munson, Young and Okiishi

L = [15  10  10  10  10]*0.3048;  %  pipe lengths (m)
D = 0.0625*0.3048*ones(size(L));  %  true pipe diameters, all equal
                                  %     at 0.0625*0.3048 (m)
A = 0.25*pi*D.^2;                 %  cross sectional area
e = 0.0015e-3*ones(size(L));      %  roughness for drawn tubing
KL = [1.5  1.5  1.5  1.5  10  2]; %  minor loss coefficients
Am = A(1)*ones(size(KL));         %  areas of pipe associated with minor loss
                                  %     coefficients are same as pipe area
rho = 998.2;           %  density of water (kg/m^3) at 20 degrees C
mu = 1.002e-3;         %  dynamic viscosity (kg./m/s) at 20 degrees C
nu = mu/rho;           %  kinematic viscosity (m^2/s)
dz = -20*0.3048;       %  inlet is 20ft below outlet
Q = 12*6.309e-5;       %  12 gpm flow rate

[hv,hm,f] = pipeLoss(Q,L,A,D,e,KL,Am,nu);
hLtot = sum(hv) + sum(hv);
Wp = rho*9.81*Q*hLtot;       %  pump power (eta = 1)  (W)

fprintf('\nViscous losses in straight pipe sections\n');
fprintf(' section        Re           f         hL\n');
for k=1:length(L)
  Re = (Q/A(k))*D(k)/nu;
  fprintf('  %3d    %12.2e    %8.4f   %6.1f\n',k,Re,f(k),hv(k));
end

fprintf('\nMinor losses in straight pipe sections\n');
fprintf(' fitting     KL        hm\n');
for k=1:length(KL)
  fprintf('  %3d   %8.2f    %6.1f\n',k,KL(k),hm(k));
end

% --- convert to ancient system of units and print
fprintf('\nFlow rate  = %6.1f  gpm\n',Q/6.309e-5);
fprintf('Pump power = %6.1f  hp\n',Wp*1.341e-3);
gam = rho*9.81;      %  specific weight of fluid
dp = gam*(hLtot-dz) 
dpsi = dp*14.696/101325

end