Solving Complex Equations: Brute Force Method

 

by The Flow Guy (www.FlowGuy.com)

 

Solving a complex equation that is not easily simplified can be a daunting task. A common example is the Colebrook-White friction factor equation. One form of the equation, utilized in pipe flow calculations, is shown below:

 

           (1)

 

In this equation, the friction factor, f, is on both sides of the equality sign and so how do you solve for the friction factor, when knowing the friction factor is required to solve the equation? The solution to these types of equations is solved by what is known as an iterative process. In other words, the equation must be solved multiple times and substituting new friction factors into the equation until the values on both sides of the equality (equals sign) are very close to each other.

 

There are a number of methods used to solve these types of equations but most involve a significant amount of time to program a solution. Plus the equations used in many types of engineering calculations make the problem very complex. One of the most elegant solutions is through the Newton-Rhapson method but it involves taking the derivates of the original equation. Newton-Rhapson will quickly converge on a solution but the problem most people have is developing the algorithm to solve it.

 

This article is going to present an alternative method, which works in a great deal of the applications for commonly encountered hydraulic equations and is very simple. I learned the method many years ago and have lost the original article I read. So unfortunately I am unable to credit the original article writer for this method.

 

I call this method the Brute Force method of equation solution as the power of the personal computer is used to solve the problem without relying on more elegant methods such as Newton-Rhapson, bi-section, etc.

 

Ill use the Colebrook-White equation (1) shown above and Im not going to cover the use of the equation as it is simply for an example. If you try and algebraically manipulate the equation to solve for the friction factor, f, you will note that it is impossible to derive an equation of the form f = some algorithm.

 

The brute force method simply involves solving for one of the variables you are looking for. In this case, we want to determine the value of f when given the other variables. By rearranging the equation (1) and solving for the f on the left side, we can derive the following form of the equation:

 

        (2)

 

Hopefully this equation manipulation is easily understood. In simple terms, all I did was:

  1. Multiply both sides by the square root of f over the square root of f.

  2. Then multiply both sides by the equation on the right side over the equation on the right side.

  3. Or stated another way, just invert both sides of the equation to get the square root of f on top of the line and then square both sides to get rid of the radical around the f variable.

  4. If you have problems with this, email me at Lyle@FlowGuy.com for help.

 

And before you say it, I realize that when I square the equation on the right side, it could potentially lead to a problem, if the value on the right side is a negative value. If you square a negative value, the result is a positive value.

 

I dont want to go into the math implications and overly complicate the solution. Just realize that you need to carefully test the results over the range of possible input values to check for problems. Often we have a chart or some other reference that can be used to pick values to test. Keep in mind that this is a brute force method and is not without potential errors.

 

If the equation is continuous and does not have multiple maximums and minimums, this method will typically work for most common engineering equations. Always test the resultant equation over its intended range to verify the result.

 

Now that the original equation (1) has been algebraically manipulated to solve for one of the f variables desired, all you have to do use a programming language or spreadsheet program to solve it.

 

Pick a typical value for the variable, in our case, 0.03 for the friction factor. You may have to play around with your particular equation but normally utilizing a mid range value will work.

 

Once a starting value for the desired variable is selected, utilize that value in the equation and solve for f or your desired variable. Once you have a new value, compare the difference between the new and previous value to see what the difference is. If the difference is greater than what ever accuracy desired, substitute the new value back in the equation and then calculate another result. Continue doing this until the difference between the current value and the previous value are negligible. In the friction factor equation used in this example, a tolerance of 0.0001 is more than enough.

 

When your values are at the outer limits of the equation, it can take a number of loops to resolve. Setting a maximum number of loops to 30 or so will prevent the program ending up in an endless loop.

 

Example

 

f_initial  0.03                 Friction factor initial

Re                    10,000             Reynolds number

ε/D                   0.0001             Relative roughness

 

Trial

f used

f calculated

Difference

1

0.0300

0.0312

0.00120

2

0.0312

0.0310

-0.00019

3

0.0310

0.0310

0.00004

 

In example, using an initial value of 0.03 for the friction factor, f, the equation was resolved in 3 iterations, with a difference of 0.00004 between the current friction factor and the previous one.

 

To try this for yourself, use a spreadsheet or programming language to program equation (2) above. Use the values above including the initial value of f to calculate a new value of f. Then take the newly calculated value of f and plug it into the equation and compute a new value of f. Continue to substitute the new value of f into the equation and calculate another value of f. Each time the calculation is performed, check the difference between the newest value of f and the previous value. When the difference is below a predetermined threshold, the latest value is the answer.

 

Often if the equation will not resolve, the resultant values will be greatly different. If the process performs normally, the calculated variable will become closer and closer to the previous value.

 

Substituting the last friction factor, 0.0310, into the original equations (1), the difference across the equals sign is 0.000588. In a practical application, the routine should be iterated at least one more time to further reduce the difference.