0% found this document useful (0 votes)
2 views79 pages

Numeric Analysis Notes

Chapter 1 discusses the solution system of linear equations, introducing concepts such as linear equations, systems of linear equations, and methods for solving them including Gaussian elimination and Jacobi method. It provides examples of representing linear equations in matrix form and solving them using direct and iterative methods. The chapter emphasizes the importance of diagonal dominance for the convergence of iterative methods.

Uploaded by

vedatalageri
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
2 views79 pages

Numeric Analysis Notes

Chapter 1 discusses the solution system of linear equations, introducing concepts such as linear equations, systems of linear equations, and methods for solving them including Gaussian elimination and Jacobi method. It provides examples of representing linear equations in matrix form and solving them using direct and iterative methods. The chapter emphasizes the importance of diagonal dominance for the convergence of iterative methods.

Uploaded by

vedatalageri
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
Chapter 1: Solution System of Linear Equations 1.1 Linear Equation = mx is an equation, in which variable y is expressed in terms of x and the constant m, is called Linear Equation. In Linear Equation exponents of the variable is always ‘one’, 1.2 Linear Equation in n variables: AX, FX, FON, Ht x, =) Where xx .tje0%, are Variables and 4),43,4)3.44, and bare constants. 1.3 System of Linear Equations: A Linear System of m linear equations and n unknowns i AN Hay Hayy Hota, ty =P) yX + ayyty +ay3%y asx, ba ayy + Ay Xj Fy Ny * Aggy Ho A, Where x,.4,..,.0%, are variables or unknowns and a’s and b’s are constants, 1.4 Augmented Matrix System of linear equations: ay Hgts + gy) =) Ay X\ + dyXy Hay Ny = by aX, $y: + aay =D Can be written in the form of matrices product ay ay x] fb ay ayy dy | |=), ay dy asda) |b Or we may write it in the form AX=b. fay ay ay x, b Where A=|a,, a3, ay) |X =)x5 b= by ay dy ay [x hy Augmented matrix is [4:b]=)a,, a ay, merical Analysis / M. Se. Chap. 1 Written by Assoe. Prof. Dr. Zaidoon M. Shakoor Scanned with CamScanner Example 1.1: Write the matrix and augmented form of the system of linear equations 3x-y+6z=6 xty+z=2 2x +yt4z=3 Solution: Matrix form of the system is [3-1 6yx) [6 11 dfy|=|2 21 4 | [3 3-1 6 6 Augmented formis — [4:hJ=|1 1 1 2 2143 1.5 Direct Methods for Solving System of 1.5.1 Gaussian Elimination. Gaussian elimination is a general method of finding possible solutions to a linear ear Equation pation Method By using elementary row opera fa a as A] fl dy dy Bi] ay dy ay | >]0 1 Ay BI a ay dy hb) 0 0 1 BY 2: Solve the system of linear equations by Gaussion- Elimination method [atetass 2x, -x 4x Solution: Step 1. ‘Augmented mati 11 13] 2 -1 -26 4 2 3\7 Numerical Analysis / M. Se. Written by Assoc. Prof. Chap. 1 Dr. Zaidoon M. Shakoor Scanned with CamScanner 0 0) 5)-15 R= Equivalent sy em of equations form is: Step 2. Back Substitution yy tay tay a3 Bret Solutions are x, Example 1.3: For the below figure calculate the values of the unknown flow rates F, F2 and F by using Gaussion- Elimination method F, F 99% Benzene 5% Benzene {ve Toluene t 92% Toluene 3%: lene F=1000 kg/hr 4 ‘Tower 1 ‘Tower 2 40% Benzene 40% Toluene 2% Xylene 90% Xylene Component material balance gives these three equations of three variables Ft 000 0.99F, +0.05, 400 O.01F, +0.92F, +0.1F, = 400 Numerical Analysis / M. Se. -7- Written by Assoc. Prof. Chap. 1 Dr. Zaidoon M. Shakoor Scanned with CamScanner Augmented matrix is 1 11 1000 0.99 0.05 0 400 2 (0.99/1)xr, [0.01 0.92 0.1 400 = (O.01/1 ry 1 1 1 1000 0-094 -0.99 =590 Ry 15-(0.91/(-0.94))r2 0 0.91 0.09 390 | frou 1 1000 0 -0.94 — -0.99 -590 | Ri=12/(-0.94) [0 0 -0.8684 -181.17] R3=r3/( -0.8684) flu 1 1000 10 L 1.0532 627.6596 [0 0 1 208.6253 Equivalent system of equations form is: F, + F,+F;= 1000 F, +1.0532F; = 627.6596 Fy = 208.6253 Step 2. Back Substitution F: = 208.6253 627.6596-1.0: 1 =1000- F.-F, 27 .6596- 1.0532 «208.6253 =407. 000 -208.6253 - 407.9354= 383.4393 1.5.2 Gauss - Jorden Elimination Method Gauss - Jorden Method By using elementary row operations fay a ay Ab] fl 0 0 B) az dy h|>)0 1 0 By a, ay bf [O01 BI Example 1.4: em of linear equations by Gauss-Jorden elimination method Scanned with CamScanner Solution: Augmented matrix is xy=2 is the solution of the system. Example 1 Total and component material balance on a system of distillation columns gives the flowing equations:- Fit Fat y+ F,= 1699 OAF) + O.1SF > + 0.25F s+ 0 412.5 O.25F + O.8F y+ 0.3F 3+ [Link] = 701 O.08F , + U.0SF; + [Link] s+ 0.3F ,= 487.3 Use Gauss - Jorden method to compute the four un-known's in above equations:~ Numerical Analysis / M. Se. 9. Written by Assoc. Prof. Chap. 1 Dr. Zaidoon M. Shakoor Scanned with CamScanner Solution: Augmented matrix is 11 1 1 1690 04 0.15 0.25 0.2 412.5 025 08 03 045 701 0.08 0.05 045 0.3 487.3 tot 1 1 1690 0 -0.25 -0.15 -0,2 -263.5 0 055 0.05 02 2785 0 -0.03 0.37 0.22 352.1 11 1 1 1690 0 -0.25 -0.15 -0.2 ~263.5 0 0-028 -0.24 301.2 10 00.388 0.244 383.72 1 1 1 1 1690 (0 -0.25 -015 -02 = 263.5 fo 0-028-024-3012 lo 0-0 0.08857 ~33.657 r1ot 1 1690 0 1 06° 08 1054 0 0 1 0.85714 1075.74 00 0 1 380 11 1 0 1310 0 1 06 0 750 00 1 0 750 00 0 1 380 1 1 0 0 560 0 1 0 0 300 0 0 1 0 750 0 0 0 1 380 10 0 0 260 0 1 0 0 300 0 0 1 0 750 0 0 0 1 380 (0.4/1 )ry =13-(0.25/1)r, 4-(0.08/1)ry R31y-(0.55/(-0.25))r2 Ryg=ry-((-0.03)/(-0,025))r> R.=1y-((0.0388)/(-0.028) yrs r/(-0.25) s/(-0.028) Ry =ry/(-0.0887) tyty (O.8/1)ry s(0.85714/1)ts Raters Romrs-((-0.6)/1)ts Equivalent system of equations form: F,= 260, F)= 300, F;=750 and F,=380 is the solution of the system. Numerical Analysis / M. Chap. 1 = 10- Written by Assoc. Prof, Dr. Zaidoon M. Shakoor Scanned with CamScanner 1.6 In-direct (iterative) Methods for Solving System of Linear Equations The sufficient condition for solving ems of linear equations using iterative methods is: \al=[h) +a iy les] =leal +104 The absolute value of the diagonal element in each row of the coefficient matrix must be greater than the sum of the absolute values of the off-diagonal elements in the same row. 1.6.1 Jacobi Method Let the given equation be ayxt by + cy ayx+ byt cy ax t byt cy If the given system of equation is diagonally dominant then wb x Example 1.6: Use the Jacobi iteration method to obtain the solution of the following equations: Solution Step 1: Re-write the equati coefficient on the left hand side: such that each equation has the unknown with largest Scanned with CamScanner Step 2: Assume the initial guesses xy = easy) +H 20)-O) +11 6 6 2x7) -20$) 20 7 1 Of) +209) +1 20) (0)+2(0) +1 ‘ Ll and x! x =0 then calculate x.) and x}: Step 3: Use the values obtained in the first iteration, to calculate the values for the 2" iteration: Ses 2x 7 20) fot Ot) +204) 41 ayl= 5 The results for 9 iterations are: Chap. 1 Unknowns: Iter. Xo XS I 0.714 | 0.200 2 L.1st | 0.852 3 1.053 1.080 4 1.001 | 1.038 9 2.000. 1,000 1.000 7M. Se. -12- Written by Assoc. Prof. Dr. Zaidoon M. Shakoor Scanned with CamScanner Example 1.7: Solve the equations by Jacobi method 20x, +X; —2x;=17 3x1 + 20x2 —x3 =—18 2x, — 3x2 + 20x; = 25 Solution. Rewrite the given equation in the form: ), we obtain 20 (25-2) +3x))=1.1515 20 These and further iterates are listed in the table below: xf % x} 0 0 0 0.85 | —0.90 1.25 1.02 | -0.965 | 1 ISIS 0032 1.0009 | —1.0018 | 0. 1.9993, i 0 I 2 3 1.0134 | —0,9954} | 4 S| 1.0000 | -1.0002 | 0. 9996 6 | 1.0000 -1.0000 | 1 0000, The values in 5" and 6"" iterations being practically the same, we can stop. Hence the solutions are: xX) = 1.x) =-l andx;=1 Numerical Analysis / M. Se. 13 - Written by Assoc. Prof. Scanned with CamScanner 1.6.2 Gauss-Seidel Method Ifthe given system of equation is diagonally dominant then tg Ay! ee") Use the Gauss-Seidel method to obtain the solution of the following equations: 6x) 2x) +x) =11 a) x) 22%) Q) -2X) +72 e) Solution Step 1: Re-write the equations such that each equation has the unknown with largest ‘coefficient on the left hand side: 2x) - 4, +11 7 RTT from eq. (1) from eq. (3) ace from eq. (2) Step 2: Assume the initial guesses x=! =0 , then calculate x: 20)-()+U 1.833 Use the updated value xf =1.833 and x} =0 to calculate af) 20x) +5 _ 211.833) —210) +5 7 7 Similarly, use x} =1.833 and. x, 1.238 38 to calculate x} 2D (x) 41 (1.833) 4-20 5 3 Step 3: Repeat the same procedure for the 2" iteration Dah y-(ahy 1 201.238) = (1.062) +11 6 6 2(2.069) ~ 21.062) +5 069 a2) 20k) 45 2 _ af) +5 22) =1.002 7 Numerical Analysis / M. Se. -14- Written by Assoc. Prof. Chap. 1 Dr. Zaidoon M. Shakoor Scanned with CamScanner +203 )41 2.069) +20..002) +1 os and so on for the next iterations so that the next values are calculated using the current values: 2ayy-O4) +H 6 2iyy+5 7 wet OL 220441 a 3 and continue the above iterative procedure until [(X4)" |= (X4)'J/ (x4)! <€ for i=1,2 and 3. The procedure yields the exact solution after 5 iterations only: Unknown Iter: x X> Xs 1 1,833 1,238 1.062 2 2.069 | 1.002 | LOIS 3 1.998 | 0.995 | 0.998 4 1.999 | 1.000 | 1.000 5 2.000 | 1.000 | 1.000 Example 1.9: For the below figure calculate the values of the unknown flow rates F), F; and Fy by using Gauss-Seidel Method F 99% Benzene 5% Benzene 1% Toluene 92% Toluene 3% Xylene F=1000 kg/hr] 5 5 ——| z z 40% Benzene| © 5 40% ‘Toluene 20% Xylene Fy? 410% Toluene 90% Xylene Component material balance gives these three equations of three variables 0.99F, +0.05F, + 0F, = 400 O.01F, +0.92F, +0.1. OF, + 0.03F, +0.9F, = 200 Numerical Analysis / M. Se. ~15- Written by Assoc. Prof. Chap. Dr. Zaidoon M. Shakoor Scanned with CamScanner Re-arranging the above equations F, =(400—0.05F,)/0.99 F, = (400-0.01F, ~0.1F,)/0.92 (200 -0.03F,)/0.9 Starting with F1= 00/3 Iteration | FI F2 F3 333.3333 | 333.3333 | 333.3333 1,0000 | 387.2054 | 394.3420 | 209.0775 2.0000 | 384.1241 | 407.8815 | 208.6262 3.0000 _| 383.4403 | 407.9380 | 208.6243 4.0000 _| 383.4375 | 407.9383 | 208.6243 5.0000 _ | 383.4375 | 407.9383 | 208.6243 A Matlab program for solving the above equations using Gauss-Seidel method is listed in Table 1.1 Table (1.1) Matlab code and results for solution example (1.9) F1=333.33; F2=333.33; F3=333.33 4 100-0.05*F2)/0.99; (00-0.01*F1-0.1*F3)/0.92; 100-0.03*F2)/0.9; disp({ I, F1, F2, F3)) end Matlab Code 1.0000 387.2056 394.3423 209.0775 2.0000 384.1241 407.8815 208.6262 Results | 39000 383.4403 407.9380 208.6243 4.0000 383.4375 407.9383 208.6243 1.7 Solving Linear Simultaneous Equations Using Gaussian Elimination Matlab Command There are a number of common situations in chemical engineering where sys of linear equations appear. There are at least three ways in MATLAB to solve these systems of equations. One of these methods is using matrix al called matrix inverse or Gaussian Elimination method). Consider a set of n equations in which the unknowns are x, The system of equations given above can be expressed in the matrix form as, Ja, a, ay a, [x b, hay a Or AX=b fan ay an: ands, | [b, Numerical Analysis / M. Se. = 16- Written by Assoc. Prof. Chap. 1 Scanned with CamScanner ayy Ay b Fay ay b x b=) b. x ay Ay Ay ta | To determine the variables contained in the column vector 'x', complete the following steps. (a) Create the coefficient matrix ‘A’. Remember to include zeroes where an equation does not contain a variable. (b) Create the right-hand-side column vector 'b’ containing the constant terms from the equation, This must be a column vector, not a row. * vector by left dividing 'b' by " by typing x = A\b. (c) Calculate the values in the ' Note: this is different from x = b/A. Example 1.10 'ylene, styrene, toluene and benzene are to be separated with the array of distillation columns that is shown below. Write a program to calculate the amount of the streams D, B. DI, BI, D2 and B2 also to calculate the composition of streams D and B. D { Ty Silene 54% Tol Bente 2 D “ " ie 59 Xylene Mate F=70 modimin B Note: Solve the system of equations by using the matrix inverse method. Solution By making material balances on individual components on the overall Numerical Analysis / M. Se. -17- Written by Assoc. Prof. Dr. Zaidoon M. Shakoor Scanned with CamScanner separation train yield the equation set Xylene: 0.07D1+ 0.18B1+ 0.15D2+ 0.24B2= 0. 70 Styrene: 0.04D1+ 0.24B1+ 0.10D2+ 0,65B2= 0.25% 70 Toluene: 0.54D 1+ 0.42B1+ 0,54D2+ 0.10B2= 0.40% 70 Benzene: 0.35D1+ 0.16B1+ 0.21D2+ 0.01B2=0.20* 70. Overall material balances and individual component balances on column 2 can be used to determine the molar flow rate and mole fractions from the equation of stream D. Molar Flow Rates: D= DI + BI Xylene: XDxD = 0.07D1 + 0.18B1 Styrene: XDsD = 0.04D1 + 0.24B1 Toluene: XDtD = 0.54D1 + 0.42B1 Benzene: XDbD = 0.35D1 + 0.16B1 Where: XD: mole fraction of Xylene. = mole fraction of Styrene. mole fraction of Toluene. XDb =mole fraction of Benzene Similarly, overall balances and individual component balances on column 3 can be used to determine the molar flow rate and mole fractions of stream B from the equation set Molar Flow Rates: B = D2 + B2 Xylene: XBxB = 0.15D2 + 0.24B2 Styrene: XBsB = 0.10D2 + 0.65B2 Toluene: XBIB = 0.54D2 + 0.10B2 Benzene: XBbB = 0.21D2 + 0.01B2 Where: F, D, B, D1, BI, D2 and B2 are the molar flow rates in mol/min. A Matlab program for solving the above equations using Gau method is listed in Table 1.2 Table (1.2) Matlab code and results for solution example (1.10) .07, 0.18, 0.15, 0.24; 0.04, 0.24, 0.10, 0.65; 0.54, 0.42, 0.54, 0.1;0.35, 0.16, 0.21, 0.01); .15*70; 0.25°70; 0.4*70; 0.2°70}; ijan-Elimination =A\B; Matlab | 2* (A) B4=X{2),D2=X(9),B2=Xt4) Code | g-p24B2 (0.07*D1+0.18*B1)/D XDs=(0.04*D1+0.24°B1)/D XDt=(0.54°D1+0.42*B1)/D XDb=(0.35°D1+0.16"B1)/D ‘Numerical Analysis / M. Se. -18- Written by Assoc. Prof. Chap. 1 Dr. Zaidoon M. Shakoor Scanned with CamScanner ] XBx=(0.15*D2+0.24*B2)/B XBs=(0.1*D2+0.65°B2)/B XBt=(0.54*D2+0.1°B2)/B XBb=(0.21"D2+0.01°B2)/B Results Di= 26.2500 B1= 17.5000 D2 8.7500 B2= 17.5000 D= 43.7500 B 26.2500 XDx = 0.1140 XDs = 0.1200 XDt= 0.4920 XDb = 0.2740 XBx = 0.2100 XBs = 0.4667 XBt= 0.2467 XBb = 0.0767 Example 1.11 side: ‘Numerical Analysis / M. Se. Chap. 1 Balance the following chemical equation: x; Paly +29 Py+xy H2O > xy PHI +25 HyPO, Solution: Ubalance: 4x)=x3-+.r5 H balance: ANB O balance: x;=4y5 Re-write these as homogeneous equations, each having zero on its right hand -19- Written by Assoc, Prof. Dr. Zaidoon M. Shakoor Scanned with CamScanner 2x) + 4xy Ax) x4 - Dey dey 3x0 xy- dxs= 0 At this point, there are four equations in five unknowns. To complete the system, we define an auxiliary equation by arbitrarily choosing a value for one of the coefficients: “=I We can easily solve the above equations to balance this reaction using MATLAB such in table 1.3 Table (1.3) Matlab code and results for solution example (1.11) A=[240-4-1 400-10 002-43 0010-4 10000); B= [0,0 X= A\B Matlab Code 1.3000 12.8000 4.0000 3.2000 This does not yield integral coefficients, but multiplying by 10 will do the trie The balanced equation will be: 10 Poly + 13 Ps + 128 HO — 40 PHI +32 [Link] Results Example 1:12 Steady state mass balances on a flash tank. Consider an isothermal flash tank: Isothermal flash tank This unit takes a pressurized liquid, three-component feed stream and exp\ a low-pressure vessel maintained under isothermal conditions. The net result is that Numerical Analysis / M. Se. -20- Written by Assoc. Prof. Dr. Zaidoon M. Shakoor Scanned with CamScanner some of the fluid is vaporized, while some fluid remains liquid. The compositions of the liquid and vapor phase are determined by the combined analysis of mass balances and Raoult’s Law for vapor-liquid equilibrium. The temperature in the flash tank is T 298 K and the pressure in the tank is P= 101 kPa, Raoult’s Law states that the product of the liquid mole fraction of component i and the vapor pressure of component i is equal to the partial press xP =P re of component i in the vapor phase: Use the following data for the temperature given above P’=0.6 bar at 298 K Pee=1.0 bar at 298 K Pp 9 bar at 298 K F=100 mol/hr ZA-04 ZB: ZC Yom? Xe Using MATLAB solve for steady state values of the unknowns L=F-V mol/hr Soluti Then you have six unknowns, the compositions of the liquid stream and the composition of the vapor stream and you have eight available equations, which are. A mole balance: B mole balan C mole balance: Liquid mole fraction cor Vapor mole fraction constraint A equilibrium constraint (not used dependent) (not used dependent) B equilibrium constraint Xp P)"-YgP=0 C equilibrium constraint XP)" -yoP=0 Put equations in matrix form Matrix of coefficients A (6 *6) eqn Xa Xp X¢ Ya Ya Ye 1 L 0 0 Vv 0 0 2 I 1 1 0 0 0 3 0 0 0 1 1 1 4 pe" 0 0 P 0 0 5 0 Py 0 0 -P 0 6 0 0 Pye 0 0 P Numerical Analysis / M. Se. 21. Written by Assoc. Prof, Chap. 1 n Dr. Zaidoon M. Shakoor Scanned with CamScanner Vector of right hand side b(6*1) Eqn b A Matlab program for solving the above equations using Gaussian-Elimination method is listed in Table 1.4 Table (1.4) ) Jab code and results for solution example (1.12) = V; 2A = 0.4; 2B = 0.3; 2C = 0.3; PvapA = 0.6; 1.01325: 0,0,0,1,1,1;PvapA,0,0,-P,0,0;0,PvapB, 0,0,-P,0; Matlab 0,0,PvapC,0,0, Code war 7 34 0; 0) 5 x(2),xC = x(3), yA = x(4),yB = x(5),y =x(6) Results 0.2897 0.2978 0.4125 Example 1.13 Steady state mass balances on a single-stage liquid-liquid extractor Extract one Solvent E, (Xray Nees Nev) Heese S. (Xe Extractor Feed Raffinate F (Xn. Xre. Xr R (Xn Xres Xe —" —> Numerical Analysis / M. Se. Chap. 1 Scanned with CamScanner This unit removes uses a recycled furfural stream as the solvent to extract benzene from a cyclohexane product stream. The d you are given is: F=100 mol/hr S=150 mol/hr R=95 mol/hr Xgp=0.0010. Xprp~? X5.=0.0001 The equilibrium constants are: K,=~£=200 and K- 0.05 steady state values of the unknowns. Using MATLAB solve for Solution: You have six unknowns, the compositions of the raffinate and the compositions of the extract stream. In addition, you have seven independent equations, which are Benzene mole balance RX gu+EXpy=FXry+SXsp Cyclohexane mole balance RX got EXr=F Xr SXse furfural mole balance RXgtEXpyAFXe+SXgp (not used dependent) tion constraint XavtXgetX el jon constraint XeptXeetXeel Xpoky=0 eK =0 raffinate mole Extract mole fi Benzene equilibrium constraint ——-X; Cyelohexane equilibrium constraint X,.-) you have to choice any Note: you have six variables and seven equations therefore: We neglect mole balance equation. six equations from thes Pur the equations in matri equations. In this form. Matrix of coefficients A (6 *6) Eqn | Xr Xre Xen Xr Xtc Xr 1 R 0 0 E 0 0 2 0 R 0 0 E 0 3 1 1 1 0 0 0 4 0 0 0 1 1 1 5 -Kb 0 0 1 0 0 6 0 -Ke 0 0 1 0 Vector of right hand side b (6* 1) Numerical Analysis / M. Se. -23- Written by Assoc. Prof. Chap. 1 Dr. Zaidoon M. Shakoor Scanned with CamScanner Eqn. 1 2 3 1 4 1 3 0 6 0 A Matlab program for solving the above equations using Gaussian-Elimination method is listed in Table 1.5 Table (1.5) Matlab code and results for solution example (1.13) Matlab: Code -R=95: R,0,0,E,0;1,1,1,0,0, *XFb+S*XSb;F*XFc+S*XSe;1;1 \B; XRb=X(1), XRC=X(2), XRFEX(3), XED=X(4), XEC=X(5), XEF=X(6) ;0,0,0,1,1,1;-Kb,0,0,1,0,0;0,-Ke,0,0, 1,0]; ; Results XRb = 0.0032 XRe = 0.8761 XRF= 0.1208 XEb = 0.0635 XEc = 0.0438 XEf = 0.8927 Scanned with CamScanner Chapter 2: Solution of Non-Linear Equations 2.1.1 Graphical Methods A simple method for obtaining a root of the equation flx) = is to plot the function 's the x axis. There is much available software that will and observe where it ero facilitate making a plot of a function. We will use Matlab exclusively for the course notes; however you can use other software such as Excel or Matcad for your work Example 2.1 900 x Solve a (1-e"') =50 using the graphical method. Solution 600 W150 -e The function Ax) = (1 ) ~ 50 can be plotted in Figure 2.1 using the F Matlab statements listed in table (2.1). Table (2.1) Matlab code for solving example (2.1) using graphical method x=4:0.1:20; x=600*(1-exp(-0.15"x))./x-50; Matlab | plot(x,fx,[0 20},{0 0}) Code xlabel('x’); ylabell'f(x)’) grid on; zoom on Figure 2.1 The graphical method for roots finding. ‘al Analysis / M.S. -25- Written by Assoc. Prof. Dr. Zaidoon M. Shakoor Scanned with CamScanner The Matlab Zoom on statement allows the function to be zoomed in at the cursor with left mouse click (right mouse click will zoom out). Each time you click the axes limits will be changed by a factor of 2 (in or out). You can zoom in as many times as necessary for the desired accuracy. Figure 2.2 shows the approximate root x to be 8.79 Figure 2.2 The graphical method for roots finding with Matlab Zoom on The plot of a function between x; and x2 is important for understanding its behavior within this interval. More than one root can occur within the interval when flx)) and s can also occur within the interval Ax2) are on opposite sides of the x axis. The root when /(x;) and /(v2) are on the same sides of the x axis. Since the functions that are 0 at this point, the tangent point is tangent to the x axis satisfy the requirement /lx called a multiple root. 2.1.2 The Bisection Method The bisection method or interval halving can be used to determine the solution to f(x) = 0 onan interval [x, =a, x2 = b] if f(x) is real and continuous on the interval and f(x,) and f(x2) have opposite signs. We assume for simplicity that the root in this interval is unique. The location of the root is then calculated as lying at the midpoint of the subinterval within which the functions have opposite signs. The process is repeated to any specified accuracy. The procedure can be summarized in the following steps iten by Assoc. Prof. Dr. Zaidoon M. Shakoor Numerical Analysis / M.S. -26- Chap. 2 Scanned with CamScanner Let f(xy) Ax) <0 on an interval [x)= a,x2=5] Step1 —— Letay= 40) +0): fi =fos fe = fore) Step 2 Evaluate f, = fly) If fi > Othen Mahi ah else Rah end Step3 If abs(v2—x1) > an error tolerance, go back to Step 1 Figure 2.3 shows first three iterations x3, x4, and x5 of the bisection method. 5 10) \ : e ie , : 5 of Figure 2.3 The first three iterations x3, x4, and xs of the bisection method. x1=6 => flr) =9.3430 and x14 => fly) =-12.3910 Il x: 2 FOr) txy)= L(+ 14)= 10 = fxs) =-3.3878 Ae) flss) ivy) =2.4104 2 fxs) fla) <0 x5= Lory xy) = 4(10+8)=9 = ivy) =-0.6100 Numerical Analysis / M. &. -27- Written by Assoc. Prof. Chap. 2 Dr. Zaidoon M. Shakoor Scanned with CamScanner Since v1) and v2) bracket the root and.x3= 4 (x; +x2)= 4(a + 6), the error after the first iteration is less than or equal to 4(h ~a). A Matlab program for solving example 2.1 using biscetion method is listed in Table 2.2 where the function /(x) is an input to the program. Table (2.2) Matlab code and results for solving example (2.1) using bisection method line(’600*(1-exp(-0.15*x)) /x-50') x1=6; f= fun (x1); x2=14; 2= fun (x2); tol=1e-5; 7100 X3=(x14K2)/2; 13= fun(x3); if f1"13<0 x2=x3; 12213; else x1=x3; 11213; end if abs(x2-x1) 9) + (x+0.5h) =(0.9574)(-0.9549) + 0.05= -0.8642 1+0.5hk>,1) =(0.05)(-0.9549) + 0.9574 = 0.9096 x+h) =(0.9136)(-0.9091) + 0.1 = -0.7305 ks.) =(0.1)(-0.9091) + 0.9136= 0.8227 = (yi thks, )(yothks kaa = (xth)(yothky2) Hy at x=0.1 y (0.1) = y,(0) + (1v6)(k, + 2k, ) + 2ky) + ky) +(0.1/6) [(-1) + 2(-0.8525) + 2(-0.864) + (-0.730)]= 0.9139 y,(0.1 y2(0.1) = y,(0) +(/6) (k, + 2k, , + 2k, + ky) y2(0.1) =-1 + [(1) + 2(0.9025) + 2(0.909) + (0.823)]= -0.9092 Example 3.8 Use ode45 Matlab Command to solve the following first order system for y, and y at O

You might also like