Lecture 11 - Non-Linear Equations (Part 1 - Bracketing Methods)
Lecture 11 - Non-Linear Equations (Part 1 - Bracketing Methods)
Bracketing Methods
Chapter 5
• Easy
b b 2
4ac
ax bx c 0 x
2
2a
All Iterative
3
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Graphical Approach
• Make a plot of the Using MATLAB, plot f(x)=sin(10x)+cos(3x)
function f(x) and
observe where it
crosses the x-axis,
i.e. f(x) = 0
Figure 5.4a
f(x)=sin 10x+cos 3x
Figure 5.4c
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Bracketing:
exceptions
6
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Bisection Method
xrnew xrold
Relative error estimate : e new
100%
x r
for i=1:1:imax
11
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example 1
13
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example 2
A ball has a specific gravity of 0.6 and has a
radius of 5.5 cm. What is the distance to which
the ball will get submerged when floating in
water.
16
Example 1 Cont.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
17
Example 1 Cont.
Solution
Let us assume
x 0.00
xu 0.11
Check if the function changes sign between x and xu .
f xl f 0 0 0.1650 3.993 104 3.993 104
3 2
Hence
f xl f xu f 0 f 0.11 3.993 104 2.662 104 0
So there is at least on root between x and xu, that is between 0 and 0.11
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
19
Example 1 Cont.
Iteration 1 x xu 0 0.11
The estimate of the root is xr 0.055
2 2
f xl f xr f 0 f 0.055 3.993 10 4 6.655 105 0
Hence the root is bracketed between xr and xu , that is, between 0.055
and 0.11. So, the lower and upper limits of the new bracket are
xl 0.055, xu 0.11
At this point, the absolute relative approximate error a cannot be
calculated as we do not have a previous approximation.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
21
Example 1 Cont.
f xl f xr f 0.055 f (0.0825) 1.622 104 6.655 105 0
Hence the root is bracketed between x and xr , that is, between 0.055
and 0.0825. So, the lower and upper limits of the new bracket are
xl 0.055, xu 0.0825
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
23
Example 1 Cont.
None of the significant digits are at least correct in the estimate root of
xr = 0.0825 because the absolute relative approximate error is greater
than 5%.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
25
Example 1 Cont.
f xl f xr f 0.055 f 0.06875 6.655 105 5.563 105 0
Hence the root is bracketed between x and xr , that is, between 0.055
and 0.06875. So, the lower and upper limits of the new bracket are
xl 0.055, xu 0.06875
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
26
Example 1 Cont.
Still none of the significant digits are at least correct in the estimated
root of the equation as the absolute relative approximate error is
greater than 5%.
Seven more iterations were conducted and these iterations are shown in
Table 1.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
28
Table 1 Cont.
Table 1 Root of f(x)=0 as function of number of iterations for
bisection method.
Iteration x xu Xr a % f(xr)
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
29
Table 1 Cont.
Pros Cons
• Easy • Slow
• Always finds a root • Need to find initial
• Number of iterations guesses for xl and xu
required to attain an • No account is taken
absolute error can be of the fact that if f(xl)
computed a priori. is closer to zero, it is
likely that root is
closer to xl .
31
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Drawbacks (continued)
f x x 2
34
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Drawbacks (continued)
f x
f(x)
1
x
x
35
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
The False-Position Method (Regula-Falsi)
xl f u xu f l
xr
fu fl
36
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Procedure
1. Find a pair of values of x, xl and xu such that
fl=f(xl) <0 and fu=f(xu) >0.
2. Estimate the value of the root from the
following formula
xl f u xu f l
xr
fu fl
and evaluate f(xr).
37
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
3. Use the new point to replace one of the
original points, keeping the two points on
opposite sides of the x axis.
38
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
4. See if the new xl and xu are close enough for
convergence to be declared. If they are not go back
to step 2.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
The False-Position Method
Works well, but not always!
Here is a pitfall
Modified False-Position
One way to mitigate the “one-sided”
nature of the false position (i.e. the
pitfall case) is to have the algorithm
detect when one of the bounds is
stuck.
40
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
False-position
(Regula-Falsi)
Linear
Linear interpolation
Interpolation
Method
41
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
False-Position (Linear Interpolation) Method
Manning Equation
>> false_position('manning')
enter lower bound xl = 0
enter upper bound xu = 10
allowable tolerance es = 0.00001
maximum number of iterations maxit = 50
False position method has converged
step xl xu xr f(xr)
1.0000 0 10.0000 4.9661 271.4771
2.0000 4.9661 10.0000 6.0295 27.5652
3.0000 6.0295 10.0000 6.1346 2.4677
4.0000 6.1346 10.0000 6.1440 0.2184
5.0000 6.1440 10.0000 6.1449 0.0193
6.0000 6.1449 10.0000 6.1449 0.0017
7.0000 6.1449 10.0000 6.1449 0.0002
43
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
f ( x) x 4 3 x 4 0
xl , xu 0, 3
Convergence
slower than
bisection method
1 23 2 1
root midpoint
44
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Bisection Method False-Position Method
» xl = 0; xu = 3; es = 0.00001; maxit = 100; » xl = 0; xu = 3; es = 0.00001; maxit = 100;
» [xr,fr]=bisect2(inline(‘x^4+3*x-4’)) » [xr,fr]=false_position(inline(‘x^4+3*x-4’))
Bisection method has converged False position method has converged
step xl xu xr f(x) step xl xu xr f(xr)
1.0000 0 3.0000 1.5000 5.5625 1.0000 0 3.0000 0.1333 -3.5997
2.0000 0 1.5000 0.7500 -1.4336 2.0000 0.1333 3.0000 0.2485 -3.2507
3.0000 0.7500 1.5000 1.1250 0.9768 3.0000 0.2485 3.0000 0.3487 -2.9391
4.0000 0.7500 1.1250 0.9375 -0.4150 4.0000 0.3487 3.0000 0.4363 -2.6548
5.0000 0.9375 1.1250 1.0312 0.2247 5.0000 0.4363 3.0000 0.5131 -2.3914
6.0000 0.9375 1.0312 0.9844 -0.1079 6.0000 0.5131 3.0000 0.5804 -2.1454
7.0000 0.9844 1.0312 1.0078 0.0551 7.0000 0.5804 3.0000 0.6393 -1.9152
8.0000 0.9844 1.0078 0.9961 -0.0273 8.0000 0.6393 3.0000 0.6907 -1.7003
9.0000 0.9961 1.0078 1.0020 0.0137 9.0000 0.6907 3.0000 0.7355 -1.5010
10.0000 0.9961 1.0020 0.9990 -0.0068 10.0000 0.7355 3.0000 0.7743 -1.3176
11.0000 0.9990 1.0020 1.0005 0.0034 11.0000 0.7743 3.0000 0.8079 -1.1503
12.0000 0.9990 1.0005 0.9998 -0.0017 12.0000 0.8079 3.0000 0.8368 -0.9991
13.0000 0.9998 1.0005 1.0001 0.0009 13.0000 0.8368 3.0000 0.8617 -0.8637
14.0000 0.9998 1.0001 0.9999 -0.0004 14.0000 0.8617 3.0000 0.8829 -0.7434
15.0000 0.9999 1.0001 1.0000 0.0002 15.0000 0.8829 3.0000 0.9011 -0.6375
16.0000 0.9999 1.0000 1.0000 -0.0001 16.0000 0.9011 3.0000 0.9165 -0.5448
17.0000 1.0000 1.0000 1.0000 0.0001 17.0000 0.9165 3.0000 0.9296 -0.4642
18.0000 1.0000 1.0000 1.0000 0.0000 18.0000 0.9296 3.0000 0.9408 -0.3945
19.0000 1.0000 1.0000 1.0000 0.0000 19.0000 0.9408 3.0000 0.9502 -0.3345
20.0000 0.9502 3.0000 0.9581 -0.2831
….
40.0000 0.9985 3.0000 0.9988 -0.0086
f ( x ) x 3x 4 0
4
….
58.0000 0.9999 3.0000 0.9999 -0.0004
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example: Rate of Convergence
» x = -2:0.1:2; y = x.^3-3*x+1; z = x*0;
» H = plot(x,y,'r',x,z,'b'); grid on; set(H,'LineWidth',3.0);
» xlabel('x'); ylabel('y'); title('f(x) = x^3 - 3x + 1 = 0');
46
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
>> bisect2(inline('x^3-3*x+1')) Comparison of rate of
enter lower bound xl = 0 convergence for
enter upper bound xu = 1
allowable tolerance es = 1.e-20 bisection and false-
maximum number of iterations maxit = 100 position method
exact zero found
step xl xu xr f(xr)
1.0000 0 1.0000 0.5000 -0.3750
2.0000 0 0.5000 0.2500 0.2656
3.0000 0.2500 0.5000 0.3750 -0.0723
4.0000 0.2500 0.3750 0.3125 0.0930
5.0000 0.3125 0.3750 0.3438 0.0094
6.0000 0.3438 0.3750 0.3594 -0.0317
7.0000 0.3438 0.3594 0.3516 -0.0112
8.0000 0.3438 0.3516 0.3477 -0.0009
9.0000 0.3438 0.3477 0.3457 0.0042
10.0000 0.3457 0.3477 0.3467 0.0016
11.0000 0.3467 0.3477 0.3472 0.0003
12.0000 0.3472 0.3477 0.3474 -0.0003
13.0000 0.3472 0.3474 0.3473 0.0000
14.0000 0.3473 0.3474 0.3474 -0.0001
.. .
.. .
50.0000 0.3473 0.3473 0.3473 -0.0000
51.0000 0.3473 0.3473 0.3473 0.0000
52.0000 0.3473 0.3473 0.3473 -0.0000
53.0000 0.3473 0.3473 0.3473 -0.0000
54.0000 0.3473 0.3473 0.3473 0
Bisection
Method
False
position
49
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
How to find good initial guesses?
• Start at one end of the region of interest (xa) and evaluate
f(xa), f(xa+Dx), f(xa+2Dx), f(xa+3Dx), ........
Problem:
if Dx is too small search is very time consuming
if Dx is too large could jump over two closely spaced roots
Suggestions:
• Generate random x values and evaluate f(x) each time until you find two values that
satisfy f(x1)*f(x2) < 0
• Know the application and plot the function to see the location of the roots, and pick xl
and xu accordingly to start the iterations.
50
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.