CASE STUDY CHEMICAL REACTIONS

12.3 CASE STUDY continued

12.3 CASE STUDY 299 where the subscript 0 designates the initial concentration of each constituent. These values can be substituted into Eqs. 12.20 and 12.21 to give K 1 = c c, + x 1 + x 2 c a, − 2x 1 − x 2 2 c b, − x 1 K 2 = c c, + x 1 + x 2 c a, − 2x 1 − x 2 c d, − x 2 Given the parameter values, these are two nonlinear equations with two unknowns. Thus, the solution to this problem involves determining the roots of f 1 x 1 , x 2 = 5 + x 1 + x 2 50 − 2x 1 − x 2 2 20 − x 1 − 4 × 10 − 4 12.26 f 2 x 1 , x 2 = 5 + x 1 + x 2 50 − 2x 1 − x 2 10 − x 2 − 3.7 × 10 − 2 12.27 In order to use Newton-Raphson, we must determine the Jacobian by taking the partial derivatives of Eqs. 12.26 and 12.27. Although this is certainly possible, evaluating the derivatives is time consuming. An alternative is to represent them by finite differences in a fashion similar to the approach used for the modified secant method in Sec. 6.3. For exam- ple, the partial derivatives comprising the Jacobian can be evaluated as ∂ f 1 ∂ x 1 = f 1 x 1 + δx 1 , x 2 − f 1 x 1 , x 2 δ x 1 ∂ f 1 ∂ x 2 = f 1 x 1 , x 2 + δx 2 − f 1 x 1 , x 2 δ x 2 ∂ f 2 ∂ x 1 = f 2 x 1 + δx 1 , x 2 − f 2 x 1 , x 2 δ x 1 ∂ f 2 ∂ x 2 = f 2 x 1 , x 2 + δx 2 − f 2 x 1 , x 2 δ x 2 These relationships can then be expressed as an M-file to compute both the function values and the Jacobian as function [J,f]=jfreactx,varargin del=0.000001; df1dx1=ux1+delx1,x2-ux1,x2delx1; df1dx2=ux1,x2+delx2-ux1,x2delx2; df2dx1=vx1+delx1,x2-vx1,x2delx1; df2dx2=vx1,x2+delx2-vx1,x2delx2; J=[df1dx1 df1dx2;df2dx1 df2dx2]; f1=ux1,x2; f2=vx1,x2; f=[f1;f2]; function f=ux,y f = 5 + x + y 50 - 2 x - y 2 20 - x - 0.0004; function f=vx,y f = 5 + x + y 50 - 2 x - y 10 - y - 0.037; The function newtmult Fig. 12.4 can then be employed to determine the roots given ini- tial guesses of x 1 = x 2 = 3: format short e [x,f,ea,iter]=newtmultjfreact,x0 x = 3.3366e+000 2.6772e+000 f = -7.1286e-017 8.5973e-014 ea = 5.2237e-010 iter = 4 After four iterations, a solution of x 1 = 3.3366 and x 2 = 2.6772 is obtained. These values can then be substituted into Eq. 12.22 through 12.25 to compute the equilibrium con- centrations of the four constituents: c a = 50 − 23.3366 − 2.6772 = 40.6496 c b = 20 − 3.3366 = 16.6634 c c = 5 + 3.3366 + 2.6772 = 11.0138 c d = 10 − 2.6772 = 7.3228 PROBLEMS

12.3 Use the Gauss-Seidel method to solve the following

system until the percent relative error falls below ε s = 5: 10x 1 + 2x 2 − x 3 = 27 − 3x 1 − 6x 2 + 2x 3 = − 61.5 x 1 + x 2 + 5x 3 = − 21.5

12.4 Repeat Prob. 12.3 but use Jacobi iteration.

12.5 The following system of equations is designed to de-

termine concentrations the c’s in gm 3 in a series of coupled reactors as a function of the amount of mass input to each reactor the right-hand sides in gday: 15c 1 − 3c 2 − c 3 = 3800 − 3c 1 + 18c 2 − 6c 3 = 1200 − 4c 1 − c 2 + 12c 3 = 2350

12.1 Solve the following system using three iterations with

Gauss-Seidel using overrelaxation λ = 1.25. If necessary, rearrange the equations and show all the steps in your solu- tion including your error estimates. At the end of the compu- tation, compute the true error of your final results. 3x 1 + 8x 2 = 11 6x 1 − x 2 = 5

12.2 a

Use the Gauss-Seidel method to solve the following system until the percent relative error falls below ε s = 5: ⎡ ⎣ 0.8 − 0.4 − 0.4 0.8 − 0.4 − 0.4 0.8 ⎤ ⎦ ⎧ ⎨ ⎩ x 1 x 2 x 3 ⎫ ⎬ ⎭ = ⎧ ⎨ ⎩ 41 25 105 ⎫ ⎬ ⎭ b Repeat a but use overrelaxation with λ = 1.2.

12.3 CASE STUDY continued