11. Numerical Methods Root Bisection Method

11. Numerical Methods — Root Bisection Method Like Newton’s method, the root bisection method seeks a zero of a function f (x). However, unlike Newton...
Author: Doris Wheeler
2 downloads 1 Views 275KB Size
11. Numerical Methods — Root Bisection Method Like Newton’s method, the root bisection method seeks a zero of a function f (x). However, unlike Newton’s method, it does not seek the zero by a series of linearizations around an operating point. Rather, the root bisection method repeated halving the length of an interval that contains a zero of the function.

11.1 Introduction to the Root Bisection Method

One begins with an interval (x1 , x2 ) known to contain a zero of the function. Each iteration halves the length of the interval. Iterations continue until the size of that interval conforms to the accuracy needed for the particular problem being considered. The initial interval (x1 , x2 ) must contain a zero of a continuous function if f(x1 ) and f (x2 ) have opposite signs. For example, if f (x1 ) > 0 and f (x2 ) < 0, then the function is positive at x1 and negative at x2 . Since it is continuous, it must be zero somewhere in between. Similarly, if f(x1 ) < 0 and f (x2 ) > 0, then the function is negative at x1 and positive at x2 . Since it is continuous, it must be zero somewhere in between. Note that, in either case, the product f (x1 )f (x2 ) will be less than zero when the interval (x1 , x2 ) brackets a zero of the function. As a simple example, consider again the problem of finding a zero of the function f (x) = x2 − 4. As before, a problem having an analytical solution permits illustration of the principles involved without getting bogged down in excessive detail. Hopefully, the root bisection method will converge to the root x0 = 2. A plot of the function appears in the figure on the right.

The root bisection method calls for a series of iterations, where each iteration requires • finding the midpoint xm of the interval from the equation xm = 0.5(x1 + x2 ); • finding f (xm ); and • defining a new interval from – (xm , x2 ), if f (xm )f (x2 ) < 0; – (x1 , xm ), if f (x1 )f (xm ) < 0. Thus each iteration halves the interval bracketing the zero of the function.

1

Suppose the initial interval is (x1 , x2 ) = (1, 4) for the function f (x) = x2 − 4. Since f (1) = −3 and f (4) = 12, the interval brackets a zero of the function. See the figure on the right.

The midpoint becomes xm = 0.5(x1 + x2 ) = 0.5(1 + 4) = 2.5. Since f (xm ) = 2.25at the midpoint, the iterations must continue. The next interval that brackets the zero will be either (1.0,2.5) or (2.5,4.0). Inspection of Figure 9-6 makes it clear that the former interval should be selected. However, this can be determined without using the graph by computing the product f (1.0)f (2.5) = (−3)(2.25). Since a negative product results, the new interval should be (1.0,2.5). At the next iteration, the midpoint becomes xm = 0.5(x1 + x2 ) = 0.5(1 + 2.5) = 1.75. Since f (xm ) = −0.9375 at the midpoint, the iterations must continue. The next interval that brackets the zero will be either (1.0, 1.75) or (1.75, 2.5). This can be determined without using a graph by computing the product f (1.0)f (1.75) = (−3)(−0.9375). Since a positive product results, the new interval cannot be (1.0, 1.75). Consequently, by the process of elimination, the new interval must be (1.75, 2.5). The following table summarizes results from applying the root bisection method to this problem for ten iterations. x1 1.0000 1.0000 1.7500 1.7500 1.9375 1.9375 1.9844 1.9844 1.9961 1.9961

f (x1 ) -3.0000 -3.0000 -0.9375 -0.9375 -0.2461 -0.2461 -0.0623 -0.0623 -0.0156 -0.0156

x2 4.0000 2.5000 2.5000 2.1250 2.1250 2.0313 2.0313 2.0078 2.0078 2.0020

f (x2 ) 12.0000 2.2500 2.2500 0.5156 0.5156 0.1260 0.1260 0.0313 0.0313 0.0078

2

xm 2.5000 1.7500 2.1250 1.9375 2.0313 1.9844 2.0078 1.9961 2.0020 1.9990

(xm ) 2.2500 -0.9375 0.5156 -0.2461 0.1260 -0.0623 0.0313 -0.0156 0.0078 -0.0039

The length of the initial interval is (4-1)=3 units. After making the eleven changes in the interval shown in the above table, the length of the interval is (2.0005 − 1.9990) = 0.0015 units. This corresponds to (3)(2−11 ) = 0.0014650.0015.

11.2 Root Bisection Method In Visual Basic Sub Dim Dim Dim

RBMInVB() I As Integer, X1 As Single, Y2 As Single pRow As Integer, pCol As Integer XM As Single, YM As Single, X2 As Single, Y2 As Single X1 = 0: Y2 = X1 ^ 2 - 4 ’ Interval end points 0 and 3 X2 = 3: Y2 = X2 ^ 2 - 4 pRow = 10: pCol = 12 ’ Place results off to the right For I = 1 To 10 ’ Perform 10 iterations. XM = 0.5 * (X1 + X2) ’ Compute new midpoint YM = XM ^ 2 - 4 ’ Evaluate function there Cells(pRow, pCol) = X1 ’ Display results into pRow Cells(pRow, pCol + 1) = Y2 ’ Columns used are L,M,N,O,P,Q Cells(pRow, pCol + 2) = X2 Cells(pRow, pCol + 3) = Y2 Cells(pRow, pCol + 4) = XM Cells(pRow, pCol + 5) = YM If Y2 * YM > 0 Then ’ Replace X1 or X2 X1 = XM: Y2 = YM ’ If Y2 and YM have the Else ’ same sign, move X1 X2 = XM: Y2 = YM ’ Otherwise move X2 End If pRow = pRow + 1 Next I End Sub

11.3 Exercises — Root Bisection Method In Visual Basic . Exercise 11.3.1 (a) Use the root bisection method starting from x = 3 in seeking a zero of the function f (x) = x2 − 4. Perform 5 iterations without computer use. (b) use the root bisection method starting from x = 1 in seeking a zero of f (x) = x2 − 9. Perform 5 iterations without computer use. (c) use the root bisection method starting from x = 1 in seeking a zero of f (x) = e−2x − sin x. The argument of the sin function is given in radians. Perform 5 iterations without computer use.

3

. Exercise 11.3.2 (a) use the root bisection method starting from x = 3 in seeking a zero of the function f (x) = x2 − 4. Use Excel. (b) use the root bisection method starting from x = 1 in seeking a zero of f (x) = x2 − 9. Use Excel. (c) use the root bisection method starting from x = 1 in seeking a zero of f (x) = e−2x − sin x. The argument of the sin function is given in radians. Use Excel. (d) use the root bisection method starting from x = 1 in seeking a zero of f (x) = e−2x − sin x. The argument of the sin function is given in radians. Use Visual Basic. . Exercise 11.3.3 (a) use the root bisection method starting from x = 3 in seeking a zero of the function f (x) = x2 − 4. Perform 5 iterations without computer use. (b) use the root bisection method starting from x = 1 in seeking a zero of f (x) = x2 − 9. Perform 5 iterations without computer use. (c) use the root bisection method starting from x = 1 in seeking a zero of f (x) = e−2x − sin x. The argument of the sin function is given in radians. Perform 5 iterations without computer use. . Exercise 11.3.4 (a) use the root bisection method starting from i = 0.01 in seeking a value i0 of i that satisfies the equation (1 + i)n − 1 = 12 i when n = 10. Perform 4 iterations by hand. (b) use the root bisection method starting from i = 0.01 in seeking a value i0 of i that satisfies the equation (1 + i)n − 1 = 12 i when n = 10. Use Excel to perform 10 iterations. (c) use the root bisection method starting from i = 0.01 in seeking a value i0 of i that satisfies the equation (1 + i)n − 1 = 12 i when n = 10. Use Visual Basicto perform 10 iterations. 4

. Exercise 11.3.5 a use the root bisection method starting from x = 3 in seeking a zero of the function f (x) = x2 − 4. Use Excel. b Attempt to use the root bisection method starting from x = 0 in seeking a zero of the function f (x) = x2 − 4. Use Excel. Note its response. c use the root bisection method starting from x = 1 in seeking a zero of f (x) = x2 − 9. Use Excel. d use the root bisection method starting from x = 1 in seeking a zero of f (x) = e−2x − sin x. The argument of the sin function is given in radians. Use Excel. e use the root bisection method starting from x = 1 in seeking a zero of f (x) = e−2x − sin x. The argument of the sin function is given in radians. Use Visual Basic. . Exercise 11.3.6 a use the root bisection method starting from x = 3 in seeking a zero of the function f (x) = x2 − 4. Use Visual Basic. b Attempt to use the root bisection method starting from x = 0 in seeking a zero of the function f (x) = x2 − 4. Use Visual Basic. Note its response. c use the root bisection method starting from x = 1 in seeking a zero of f (x) = x2 − 9. Use Visual Basic. d use the root bisection method starting from x = 1 in seeking a zero of f (x) = e−2x − sin x. The argument of the sin function is given in radians. Use Visual Basic. . Exercise 11.3.7 a Use the the root bisection method starting from i = 0.01 in seeking a v alue i0 of i that satisfies the equation (1 + i)n − 1 = 12 i when n = 10. Perform 4 iterations by hand. b Use the the root bisection method starting from i = 0.01 in seeking a value i0 of i that satisfies the equation (1 + i)n − 1 = 12 i when n = 10. Use Excel to perform 10 iterations.

5

c Use the the root bisection method starting from i = 0.01 in seeking a value i0 of i that satisfies the equation (1 + i)n − 1 = 12 i when n = 10. Use Visual Basic to perform 10 iterations. . Exercise 11.3.8

Two ladders crisscross in an alley as shown on the right. L1 = 20 f t. = length of ladder 1;L2 = 30 f t. = length of ladder 2. Given that H = 8 f t. =, find the width W of the alley. Use the root bisection method.

Hint: It can be shown that H =

H1 ∗H2 . H1 +H2

File 716session11rbm.TEX

February 19, 2008@ 7:15

6