 The literal friction loss equations use a term called "Q"2, but we want to preserve any changes in direction.Create a separate equation for each loop where the head losses are added up, but instead of squaring "Q", use |"Q"|·"Q" instead (with |"Q"| the absolute value of "Q") for the formulation so that any sign changes reflect appropriately in the resulting head-loss calculation.In many situations, especially for real water distribution networks in cities (which can extend between thousands to millions of nodes), the number of known variables (flow rates and/or head losses) required to obtain a deterministic solution will be very large.