CE 311 K - Introduction to Computer Methods

Lab 9: Bisection Method


Introduction

In this laboratory, we will explore a method that we have considered for solving nonlinear equations, the bisection method. Given a nonlinear function f(x), we seek a value of x for which

f(x) = 0

Such a solution value for x is called a root of the equation, and a zero of the function f(x).

The essence of the bisection method lies in the fact that the sign of a function f(x) changes on opposite sides of a root. Suppose the function f(x) has one root in the interval between x = a and x = c, or [a,c], as shown in the Figure below.

   

The bisection method is based on the fact that when an interval [a,c] contains a root, the sign of the function at the two ends (f(a) and f(c)) are opposite each other, namely

f(a)*f(c) < 0

The first step in the bisection method is to bisect the interval [a,c] into two halves, namely [a,b] and [b,c], where

b=(a + b)/2

By checking the sign of 

f(a)*f(b)

the half-interval containing the root can be identified. If 

f(a)*f(b) < 0

then, the interval [a,b] has the root, otherwise the other interval [b,c] has the root. Then the new interval containing the root is bisected again. As the procedure is repeated the interval becomes smaller and smaller. At each step, the midpoint of the interval containing the root is taken as the best approximation of the root. The iterative procedure is stopped when the half-interval size is less than a prespecified size.


Assignment

Colebrook's Formula

The friction factor f for turbulent flow in a pipe of diameter D and interior roughness characterized by a roughness coefficient e is given by Colebrook's formula (White, 1993[1])

 

   (1)

or

   (2)

where

Re is the Reynolds number indicating laminar or turbulent flow,
e is the roughness of the pipe surface, and
D is the pipe diameter.

Your bisection program should find the root of Eq. 2, that is, the value of the friction factor f which solves the nonlinear equation, g(f)=0.

Spreadsheet

Set up an Excel spreadsheet and make a graph of the function g(f) given in Eq. 2.  You will have to set up at least two columns in the spreadsheet: one which contains a range of values of f, and one or more others which calculate g(f).  Your spreadsheet should allow you to compute g(f) for any f and any (reasonable) values of parameters Re, e, and D.  For each set of parameter values (see below) select an appropriate range of values of f so that g(f) passes through zero. This will allow you select a good initial interval for the bisection method in Part 2.

Program

Write a VB program to solve Eq. 2 for f using the bisection method. Your program must:

Use your program to evaluate f for the following cases:

  1. D = 0.1 m, e = 0.0025, Re = 3 x 10^4
  2. D = 0.1 m, e = 0.0001, Re = 5 x 10^6

Use the spreadsheet results to select a good initial interval for the bisection method.  Check your program results using a hand calculator. You should also make sure that you are reading the input values correctly. Your program may get stuck in an infinite loop. How will you prevent or test for this? You should investigate the effect of setting different values for the 'tolerance' variable in your program.


Turn in

Create a word processor file and include the following in it:

  1. Your spreadsheet plot of g(f) vs. f for the two sets of parameter values,
  2. A description of how you have dealt with the infinite loop problem in your program,
  3. A copy of your output file. 
  4. A copy of your VB source code file,  and
  5. A copy of your output file. Be sure that this includes the solution for both sets of parameter values.

Print this file and turn it in to the instructor.


McKinney | CE311K Civil Engineering | UT Austin