Chpter 3 Solving Nonliner Equtions 3.1 Introduction The nonliner function of unknown vrible x is in the form of where n could be non-integer. Root is the numericl vlue of x tht stisfies f ( x) 0. Grphiclly, the root is the point where the function f(x) crosses or touches the x-xis. 2 A simple nonliner eqution is qudrtic eqution f ( x) x bx c 0, the roots of it cn be found nlyticlly by qudrtic formul s b b 2 4c x 2 In mny situtions, however, it is very difficult or impossible to find the nlyticl roots of the non-liner eqution. In this cse, numericl methods nd desired ccurcy of solution re often required. These numericl methods cn be divided two types: 1). Brcketing Method: serch for root inside n intervl (x l, x r ). Grphicl method Flse position (lso clled regul flsi or liner interpoltion) method Bisection method 2). Open Method: serch for root strting from n initil given guess point x 0. Newton s method Secnt method Fixed -point itertion 3.2 Brcketing Method Intermedite vlue theorem: Brcketing method: An initil intervl tht includes the solution is identified. Then, by using numericl scheme, the size of the intervl is successively reduced until the distnce between the endpoints is less thn the desired ccurcy of the solution. It includes two steps: 1). Subdividing lrge intervl (, b) into n smller subintervls s (, 1 ), ( 1, 2 ),, ( n-1, b) 24
2). Exmine signs t both ends of ech subintervl. There re two possibilities of the two signs: ) f(x l ) nd f(x u ) sme signs, i.e. f(x l )f(x u ) >0 then No roots or Even number of roots b) f(x l ) nd f(x u ) different signs, i.e. f(x l )f(x u ) <0, ccording to intermedite vlue theorem then One roots or Odd number of roots Exceptions: f(x) id discontinuous function. The lgorithm (not MATLAB code) of brcketing method is: Given: f(x), xmin, xmx, n dx = (xmx-xmin)/n % Size of brcket intervl xl = xmin % Initilize left side of test brcket i = 0 % Initilize counter while i < n i = i + 1 xr = xl + dx if f (x) nd f (xb)<0 %f(xl) nd f(xr) hve different sign sve [ x, xb ] for further root finding else xl = xr % serch next intervl end 3.2.1 Grphicl Method Grphicl method: Sketch the grph of f (x), then serch for the points tht intersects x- xis, these points re the roots of f ( x) 0. 667.38 0.147x Exmple 3.1 Estimte the root of f ( x) (1 e ) 40 0 by grphicl x method. 25
From the plot, we observe tht it crosses x xis between (12, 16), nd estimte the root roughly s x 15. However, f (15) = -0.4133, thus, grphicl method is not precise. 3.2.2 Bisection Method Bisection method: is brcketing method for finding numericl solution of eqution f(x)=0 when it is known tht within given intervl [, b], f(x) is continuous nd the eqution hs solution. The lgorithm is implemented in the following steps: 1). Choose serch intervl [, b] which hs sign-chnge for f(x) (i.e. f()f(b)<0); 2). Clculte the midpoint of the intervl x m = (+ b ) / 2, use it s n estimte of the numericl solution; 3). Select subintervl from [, x m ] or [x m, b], use the one tht hs sign-chnge for f(x) (i.e. contins solution) s new serch intervl [, b], then repet steps 2)-3) until the error stisfies your expecttion. The lgorithm of bisection method is: initilize: =..., b =... for k = 1, 2,... xm = + (b-)/2 if sign(f (xm)) = sign(f ()) = xm else b = xm end 26
if converged, stop end 667.38 0.147 x Exmple 3.2 Estimte the root of f ( x) (1 e ) 40 0 by bisection x method between the intervl (12, 16) until estimted reltive error less thn 0.5%. Itertion b xm 1 12 16 14 5.279 2 14 16 15 6.667 1.487 3 14 15 14.5 3.448 1.896 4 14.5 15 14.75 1.695 0.204 5 14.75 15 14.875 0.840 0.641 6 14.75 14.875 14.8125 0.422 0.219 Note: The method converges slowly to find n idel solution. It my fil when the function f(x) is tngent to nd does not cross x-xis. t 3.2.3 Flse Position (Regul Flsi or Liner Interpoltion) Method Flse position method: is nother brcketing method for finding numericl solution of eqution f(x)=0 when it is known tht within given intervl [, b], f(x) is continuous nd the eqution hs solution. The endpoints t the intervl (, b) re connected by stright line, the point where the line crosses the x-xis is thought s the estimte of the numericl solution. 27
Line cn be expressed s: y= sx +t Then Δy=sΔx i.e. let y=0 so x=x c = (3.1) The lgorithm is implemented in the following steps: 1). Choose serch intervl [, b] which hs sign-chnge for f(x) (i.e. f()f(b)<0); 2). Find the cross point xc by eqution 3.1, use it s n estimte of the numericl solution; 3). Select subintervl from [, x c ] or [x c, b], use the one tht hs sign-chnge for f(x) (i.e. contins solution) s new serch intervl [, b], then repet 2)-3) until the error stisfies your expecttion. Note: 3.3 Open Method 3.3.1 Newton s Method Newton s method: lso clled Newton-Rphson method, is open method for finding numericl solution of eqution f(x)=0 when it is known tht f(x) is continuous nd differentible nd the eqution hs solution ner given point. Figure below shows procedure: 28
Newton s method cn be derived by using Tylor series round x i : f(x)= Assume x i+1 is the root, then f(x i+1 )=f(x i )+f (x i )( x i+1 - x i )=0 thus x i+1 = (3.2) The lgorithm is implemented in the following steps: 1). Choose point x i s n initil guess of the numericl solution; 2). Find the next guess x i+1 by eqution (3.2), use it s n estimte of the numericl solution; 3). Clculte the estimted reltive error, check whether the error stisfies your expecttion or not. If not, use x i+1 s new initil guess x i, then repet 2); otherwise, x i+1 is the solution. Stop itertion by checking 1) or 2) tolernce f ( xi ). Note: Newton s method converges fst when there is solution. The expression of derivtive (slope) of function f(x) should be found nd used to clculte the next guess of solution, sometimes it is difficult to determine the expression, then slope should be found numericlly. Newton s method my fil under the following conditions: Cse 1: Inflection point in vicinity of root Cse 2: Oscillte round locl mximum or minimum Cse 3: Jump wy for severl roots 29
Cse 4: Disster from zero slope Exmple 3.4 Write MATLAB function file tht pplies Newton s Method to find the root for x - x 1/3-2 = 0 with true reltive error less thn 0.005%. 3.3.2 Secnt Method Secnt method: It is good for function whose derivtive expression is difficult to evlute. It is open method for finding numericl solution of eqution f(x)=0, it uses two points in the neighborhood of the solution to determine new estimte for the solution. 30
In Newton s method, we know x i+1 =, when it is hrd to find the expression of f (x), Newton s method doesn t work. However, we cn rewrite x i+1 = Thus, secnt method needs two initil dt points, nd is n pproximted form of Newton s method. Exmple 3.5 Use secnt method to estimte root of e -x - x = 0. Initil estimte x -1 = 0 nd x 0 = 1.0. 1st itertion: x -1 = 0, f (x -1 ) = x 0 = 1, f (x 0 ) = x 1 = 2nd itertion: 3rd itertion: 3.3.3 Fixed-point Itertion Method Fixed-point itertion method: It is nother open method for finding numericl solution of eqution f(x)=0, the steps includes: 31
1). Rewrite originl eqution f(x) = 0 into nother form x = g(x); 2). Select initil vlue x 0, nd let x i = x 0; 3). Updte new x i+1 s function of old x i using itertion function x=g(x), i.e. x i+1 = g (x i ) 4). Check whether it reches convergence, i.e. xi 1 xi 100% expected error x i 1 If yes, x i+1 is the root; otherwise, let x i = x i+1, nd repet steps 3)-4). Note: 1). Sometimes, it is hrd to derive x=g(x) from f(x)=0. Under this sitution, you cn rewrite f(x)=0 s f(x)+x x=0, then x=f(x)+x is your g(x). 2).For some problem, it my not converge. When the derivtive of g(x) in the neighborhood of the fixed point hs n bsolute vlue tht is smller thn 1, i.e. g(x) <1, the fixed-point itertion method converges. Exmple 3.3 cont. Find root of f (x) = x - e -x = 0 by fixed-point itertion method strting from x 0 =0 until 1%. 32
i x i (%) 0 0 1 1 100 2 0.3679 171.8 3 0.6922 46.9 4 0.5005 38.3 5 0.6062 17.4 6 0.5454 11.2 7 0.5796 5.90 8 0.5601 3.48 9 0.5711 1.93 10 0.5649 1.11 Approximted solutions 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 Approximted solution True solution 0 0 2 4 6 8 10 12 Number of itertions 3.4 Roots of Polynomil A polynomil of order n is where s = constnt coefficients, f(x)=0 is specil kind of nonliner eqution. Roots of polynomils: (1) nth-order eqution hs n rel or complex roots (2) If n is odd, t lest one root is rel. (3) Complex roots exist with conjugte pirs (r + mi nd r - mi) 3.5 MATLAB built-in Function for Solving Nonliner Equtions There re two built-in functions: 1). fzero(`function, x 0 ) It solves n eqution (in the form of f(x)=0) with one vrible. `function is the expression of the function f(x), x 0 is vlue of x ner to where the function crosses the xis. Thus, the user needs to know pproximtely where the solution is. 2). roots(p) It only finds the roots of n-order polynomil 33
2 n f ( x) 0 1x 2 x n x 0 Where the row vector P consists of the coefficients of the polynomil nd P=[ n n-1 0 ]. Exmple 3.6 Find the roots of function. f ( x) 10 8x 5x 3 9x 4 0 using MATLAB roots Exmple 3.7 Find the root of Exmple 3.5 using MATLAB fzero function, use x 0 =0.5. 34