Sec:5.2 The Bisection Method
Sec:5.2 The Bisection Method The root-finding problem is a process involves finding a root, or solution, of an equation of the form 𝑓 𝑥 = 0 for a given function 𝑓 . A root of this equation is also called a zero of the function 𝑓 . In graph, the root (or zero) of a function is the x-intercept Two numerical methods for root-finding Sec(5.2): The Bisection Method root Sec(6.2): The Newton-Raphson Method
Sec:5.2 The Bisection Method This technique is based on the Intermediate Value Theorem Example: Suppose 𝑓 is a continuous function defined on the interval [𝑎, 𝑏], with 𝑓 (𝑎) and 𝑓 (𝑏) of opposite sign. The Intermediate Value Theorem implies that a number 𝑝 exists in (𝑎, 𝑏) with 𝑓 ( 𝑝) = 0. Show that 𝑓 (𝑥) = 10 𝑥 6 −149 𝑥 5 +10𝑥−149 10( 𝑥 4 +1) has a root in [12, 16] Sol: 12 16 𝒇(𝟏𝟐)=−𝟑𝟒.𝟖 𝒇(𝟏𝟔)=𝟏𝟕.𝟔
Sec:5.2 The Bisection Method Example: Use Bisection method to find the root of the function 𝑓 (𝑥) = 10 𝑥 6 −149 𝑥 5 +10𝑥−149 10( 𝑥 4 +1) in [12, 16] 12 16 Change of sign -34.8 17.6 𝒙 𝟏 = True root: 𝑥 𝑟 ∗ =14.9 12 14 Change of sign 16 Iter1 𝒏 𝒙 𝒏 -34.8 -12.6 17.6 1 14.0000000000 2 15.0000000000 3 14.5000000000 4 14.7500000000 5 14.8750000000 6 14.9375000000 7 14.9062500000 8 14.8906250000 9 14.8984375000 10 14.9023437500 11 14.9003906250 12 14.8994140625 13 14.8999023438 14 14.9001464844 15 14.9000244141 16 14.8999633789 𝒙 𝟐 = 14 15 16 Iter2 Change of sign -12.6 1.5 17.6 𝒙 𝟑 = Change of sign 14.5 14 15 Iter3 -5.8 1.5 -12.6
Sec:5.2 The Bisection Method Textbook notations 𝒙 𝒍 𝟎 𝒙 𝒖 𝟎 12 16 Change of sign ∆ 𝒙 𝟎 = 𝒙 𝒖 𝟎 − 𝒙 𝒍 𝟎 At the n-th iteration: -34.8 17.6 endpoints of the inteval 𝒙 𝒍 𝟏 𝒙 𝒖 𝟏 12 14 Change of sign 16 [ 𝒙 𝒍 𝒏 , 𝒙 𝒖 𝒏 ] Iter1 ∆ 𝒙 𝟏 = 𝒙 𝒖 𝟏 − 𝒙 𝒍 𝟏 -34.8 -12.6 17.6 Length of the interval 𝒙 𝒍 𝟐 𝒙 𝒖 𝟐 14 15 16 ∆ 𝒙 𝒏 = 𝒙 𝒖 𝒏 − 𝒙 𝒍 𝒏 Iter2 Change of sign ∆ 𝒙 𝟐 = 𝒙 𝒖 𝟐 − 𝒙 𝒍 𝟐 -12.6 1.5 17.6 = ∆ 𝒙 𝟎 𝟐 𝒏 𝒙 𝒍 𝟑 𝒙 𝒖 𝟑 Change of sign 14.5 14 15 Iter3 ∆ 𝒙 𝟑 = 𝒙 𝒖 𝟑 − 𝒙 𝒍 𝟑 -5.8 1.5 -12.6
Sec:5.2 The Bisection Method Error Estimates for Bisection 12 16 Change of sign -34.8 17.6 𝒙 𝒓 ∗ At the iter1: 𝒙 𝟏 = True root live inside this interval 𝒙 𝟏 − 𝒙 𝒓 ∗ < length of the interval 12 14 Change of sign 16 𝒙 𝟏 − 𝒙 𝒓 ∗ <∆ 𝒙 𝟏 = ∆ 𝒙 𝟎 𝟐 Iter1 -34.8 -12.6 17.6 𝒙 𝟐 At the iter2: = 14 15 16 𝒙 𝟐 − 𝒙 𝒓 ∗ < length of the interval Iter2 Change of sign 𝒙 𝟐 − 𝒙 𝒓 ∗ <∆ 𝒙 𝟐 = ∆ 𝒙 𝟎 𝟐 𝟐 -12.6 1.5 17.6 At the nth iteration: 𝒙 𝒏 − 𝒙 𝒓 ∗ < 𝒃−𝒂 𝟐 𝒏 Error Estimates for Bisection 𝒙 𝒏 − 𝒙 𝒓 ∗ < length of the interval 𝑬 𝒂 𝒏 < 𝒃−𝒂 𝟐 𝒏 the absolute error in the n-th iteration < 𝒃−𝒂 𝟐 𝒏 𝒙 𝒏 − 𝒙 𝒓 ∗ <∆ 𝒙 𝒏 = ∆ 𝒙 𝟎 𝟐 𝒏 = 𝒃−𝒂 𝟐 𝒏
Sec:5.2 The Bisection Method Error Estimates for Bisection 𝑬 𝒂 𝒏 < 𝒃−𝒂 𝟐 𝒏 𝒏 𝒙 𝒏 𝑬 𝒂 𝒏 1 14.0000000000 -9.0000000000e-01 2 15.0000000000 1.0000000000e-01 3 14.5000000000 -4.0000000000e-01 4 14.7500000000 -1.5000000000e-01 5 14.8750000000 -2.5000000000e-02 6 14.9375000000 3.7500000000e-02 7 14.9062500000 6.2500000000e-03 8 14.8906250000 -9.3750000000e-03 9 14.8984375000 -1.5625000000e-03 10 14.9023437500 2.3437500000e-03 11 14.9003906250 3.9062500000e-04 12 14.8994140625 -5.8593750000e-04 13 14.8999023438 -9.7656250000e-05 14 14.9001464844 1.4648437500e-04 15 14.9000244141 2.4414062500e-05 16 14.8999633789 -3.6621093750e-05 If 𝐸𝑎,𝑑 =10 −4 is the desired error, this equation can be solved for 𝑛 𝑬 𝒂 𝒏 < 𝟏𝟔−𝟏𝟐 𝟐 𝒏 < 𝟏𝟎 −𝟒 𝟐 𝒏 > 𝟒 𝟏𝟎 −𝟒 𝟐 𝒏 >𝟒× 𝟏𝟎 𝟒 𝒏> 𝒍𝒐𝒈 𝟒× 𝟏𝟎 𝟒 𝒍𝒐𝒈 𝟐 =𝟏𝟓.𝟐
Stopping Criteria Sec:5.2 The Bisection Method function [xr,err,yc,iter,x]=bisect_ver1(f,a,b,es) %Input: f is the function, a, b are endpts % es is the tolerance, imax is max iter %Output: c is the zero, yc= f(c) ya=f(a); yb=f(b); iter =0; if ya*yb > 0,return,end for k=1:1000 iter = iter +1; xr=(a+b)/2; yc=f(xr); x(k)=xr; if yc==0 a=xr; b=xr; elseif yb*yc>0 b=xr; yb=yc; else a=xr; ya=yc; end if b-a < es, break,end xr=(a+b)/2; err=abs(b-a); yc=f(xr); function [xr,err,yc,iter,x]=bisect_ver2(f,a,b,es) %Input: f is the function, a, b are endpts % es is the tolerance, imax is max iter %Output: c is the zero, yc= f(c) ya=f(a); yb=f(b); iter =0; if ya*yb > 0,return,end max1=1+round((log(b-a)-log(es))/log(2)); for k=1:max1 iter = iter +1; xr=(a+b)/2; yc=f(xr); x(k)=xr; if yc==0 a=xr; b=xr; elseif yb*yc>0 b=xr; yb=yc; else a=xr; ya=yc; end % if b-a < es, iter=k; break,end xr=(a+b)/2; err=abs(b-a); yc=f(xr); a=12; b=16; es=1e-4; % [xr,err,yc,iter,x]=bisect_ver2(f,a,b,es); [xr,err,yc,iter,x]=bisect_ver1(f,a,b,es); iteration = [1:iter]'; res = [ iteration, x' , x'-14.9] fprintf(' %d %14.10f %14.10e \n', res');
Sec:5.2 The Bisection Method