Upload
arafatasghar
View
288
Download
0
Embed Size (px)
Citation preview
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 1/24
Solution of Nonlinear Equations
Topic: Bisection method
Dr. Nasir M Mirza
Numerical Methods
Email: [email protected]
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 2/24
Bisection Method
• The method is known as the Bolzano methodand can be called interval halving technique.
• The method is simple and straight-forward.
• Given a bracketed root, the method repeatedlyhalves the interval while continuing to bracketthe root and it will converge on the solution.
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 3/24
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 4/24
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 5/24
Step 3
Now check the following
If f(x l ) f(x m ) < 0, then the root
lies between x l and x m ;
then x l = x l ; x u = x m .
If f(x l ) f(x m ) > 0, then the root
lies between x m and x u ;
then x l = x m ; x u = x u .
If f(x l ) f(x m ) = 0; then the root
is x m. Stop the algorithm
if this is true.
x
f(x)
xu x
xm
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 6/24
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 7/24
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 8/24
Example
• You are working for ‘DOWN THE TOILET COMPANY’ thatmakes floats for ABC commodes. The ball has a specific
gravity of 0.6 and has a radius of 5.5 cm. You are asked to
find the distance to which the ball will get submerged when
floating in water.
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 9/24
Solution
The equation that gives the depth ‘x’ to which the ball issubmerged under water is given by
42310x99331650
-.+ x.- x x f
Use the Bisection method of finding
roots of equations to find the depth ‘x’ to which the ball is submergedunder water. Conduct threeiterations to estimate the root of the above equation.
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 10/24
Graph of function f(x)
423 10x99331650 -.+ x.- x x f
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 11/24
Checking if the bracket is valid
Choose the bracket
4
4
10x662.211.0
10x993.30.0
11.0
00.0
f
f
x
x
u
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 12/24
Iteration #1
055.02
11.00
11.0,0
m
u
x
x x
5
4
4
10x655.6055.0
10x662.211.0
10x993.30
f
f
f
11.0
055.0
u x
x
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 13/24
Iteration #2
%33.33
0825.02
11.0055.0
11.0,055.0
a
m
u
x
x x
0825.0,055.0
10x62216.10825.0
10x662.211.0
10x655.6055.0
4
4
5
u x x
f
f
f
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 14/24
Iteration #3
06875.02
0825.0055.0
0825.0,055.0
m
u
x
x x
5
4
5
10x5632.506875.0
10x62216.10825.0
10x655.6055.0
%20
f
f
f
a
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 15/24
Convergence
Table 1: Root of f(x)=0 as function of number of iterations for bisection method.
Iteration x xu xm a% f(xm)
1
2
3
4
5
6
7
8
9
10
0.00000
0.055
0.055
0.055
0.06188
0.06188
0.06188
0.06188
0.0623
0.0623
0.11
0.11
0.0825
0.06875
0.06875
0.06531
0.06359
0.06273
0.06273
0.06252
0.055
0.0825
0.06875
0.06188
0.06531
0.06359
0.06273
0.0623
0.06252
0.06241
----------
33.33
20.00
11.11
5.263
2.702
1.369
0.6896
0.3436
0.1721
6.655x10-5
-1.6222x10-4
-5.5632x10-5
4.4843x10-6
-2.5939x10-5
-1.0804x10-5
-3.1768x10-6
6.4973x10-7
-1.2646x10-6
-3.0767x10-7
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 16/24
Bisection Method
DO while 0.5*|x1 - x2| >= tolerance_value
Set xmid =(x1+ x
2)/2
IF f(xmid) of opposite sign of f(x1);
Set x2 = xmid;
ELSE
Set x1 = xxmid;
ENDIF
END loop
A basic loop that is used to find root between two points for afunction f(x) is shown here.
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 17/24
Bisection Method
DemoBisect: the example program does a simple bisection for acubic polynomial equation.
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 18/24
Bisection Method
• Example Problem:y(x) = a5 x5 + a4 x4 + a3 x3 + a2 x2 + a1 x + a0
• Let us consider constants to be following:
a0 = -2, a1 = -3, a2 = 4, a3 = 1, a4 = 0, a5 = 1
Then the function:
y(x) = x5 + x3 + 4x2 - 3x - 2
First we plot this function in a range from -3 to 3 andsee visually where roots are located.
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 19/24
Bisectional Method
There are 3 roots
(a) -2 < x < -1
(b) -1 < x < 0
(c) 0.5 < x <1.5
-2 -1 0 1 2
-40
-20
0
20
40
60
y ( x )
x
The graph for thefunction is shown here.
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 20/24
Computer Program for Bisection method
% A program in matlab
% bisection method to find the roots of x^5+x^3+4*x^2-3*x-2=0
xleft = -2.0 ; xright = -1.0 ; n = 100
% Input: xleft,xright = left and right brackets of the root
% n = (optional) number of iterations; default: n =15
% Output: x = estimate of the root
if nargin<3, n=15; end % Default number of iterations
a = xleft; b =xright; % Copy orig bracket to local variablesfa = a^5 + a^3 +4*a^2 - 3*a - 2; % Initial values
fb = b^5 + b^3 +4*b^2 - 3*b - 2; % Initial values
fprintf(' k a xmid b f(xmid)\n');
for k=1:n
xm = a + 0.5*(b-a); % Minimize roundoff in the midpoint
fm = xm^5 + xm^3 +4*xm^2 - 3*xm - 2; % f(x) at midpoint
fprintf('%3d %12.8f %12.8f %12.8f %12.3e\n',k,a,xm,b,fm);
if sign(fm) == sign(fa)
a = xm; fa = fm;
else
b = xm; fb = fm;
end
end
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 21/24
Bisection Method
k a xmid b f(xmid)
1 -2.00000000 -1.50000000 -1.00000000 5.313e-0012 -2.00000000 -1.75000000 -1.50000000 -6.272e+0003 -1.75000000 -1.62500000 -1.50000000 -2.184e+0004 -1.62500000 -1.56250000 -1.50000000 -6.748e-0015 -1.56250000 -1.53125000 -1.50000000 -3.612e-0026 -1.53125000 -1.51562500 -1.50000000 2.562e-0017 -1.53125000 -1.52343750 -1.51562500 1.122e-001
8 -1.53125000 -1.52734375 -1.52343750 3.860e-0029 -1.53125000 -1.52929688 -1.52734375 1.379e-00310 -1.53125000 -1.53027344 -1.52929688 -1.734e-00211 -1.53027344 -1.52978516 -1.52929688 -7.971e-00312 -1.52978516 -1.52954102 -1.52929688 -3.294e-00313 -1.52954102 -1.52941895 -1.52929688 -9.572e-00414 -1.52941895 -1.52935791 -1.52929688 2.108e-00415 -1.52941895 -1.52938843 -1.52935791 -3.732e-004
16 -1.52938843 -1.52937317 -1.52935791 -8.117e-00517 -1.52937317 -1.52936554 -1.52935791 6.482e-00518 -1.52937317 -1.52936935 -1.52936554 -8.174e-00619 -1.52936935 -1.52936745 -1.52936554 2.832e-00520 -1.52936935 -1.52936840 -1.52936745 1.008e-005
For range of x = [-2, -1]; we see x = -1.5293684 as root here.
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 22/24
Advantages & Disadvantages
Advatages: • Always convergent
• The root bracket gets halved with each iteration -guaranteed.
Disadvatanges:
• Slow convergence
• If one of the initial guesses is close to the root, theconvergence is slower
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 23/24
Drawbacks (continued)
• If a function f(x) is such that it just touches the x-axis it will beunable to find the lower and upper guesses.
2 x x f
-10 -5 0 5 10
0
20
40
60
80
100
y ( x )
x
y = x2
7/27/2019 Lec 6 Bisection Method
http://slidepdf.com/reader/full/lec-6-bisection-method 24/24
Drawbacks (continued)
Function changes sign but root does not exist
x
x f 1
-0.9 -0.6 -0.3 0.0 0.3 0.6 0.9
-100
-80
-60
-40
-20
0
20
40
60
80
100
y ( x )
x
y = 1/x