13 Problem Solving with MATLAB.pdf

download 13 Problem Solving with MATLAB.pdf

of 64

Transcript of 13 Problem Solving with MATLAB.pdf

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    1/64

    Cutlip and Shacham: Problem Solving in Chemical and Biochemical Engineering

    Chapter 5

    Problem Solving with MATLAB

    Cheng-Liang Chen

    PSELABORATORYDepartment of Chemical Engineering

    National TAIWAN University

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    2/64

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    3/64

    Chen CL 2

    where P = pressure in atm

    V = molar volume in liters/g-mol

    T = temperature in K

    R = gas constant (R= 0.08206 (atm-liter/g-mol-K))T e = critical temperature in K

    P e = critical pressure in atm

    The compressibility factor is given by

    z = P VRT

    Equation (1) can be written, after considerable algebra, in terms of thecompressibility factor as a cubic equation (see Seader and Henley)

    f(z) =z

    3

    z2

    qz r= 0 (5)where r = A2B, q = B2 + B A2

    A2 = 0.42747

    Pr

    T5/2r

    B = 0.0866

    PrTr

    in whichPr is the reduced pressure (P/Pc) andTr is the reduced temperature

    (T /Tc). Equation (5) can be solved analytically for three roots. Some of these

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    4/64

    Chen CL 3

    roots are complex. Considering only the real roots, the sequence of calculationsinvolves the steps

    C =f

    33

    +g

    22

    f = 3q 1

    3 g =

    27r 9q 227

    IfC >0, there is one real solution for z given by

    z = D+ E+ 1/3

    D = (g/2 +

    C)1/3 E = (g/2

    C)1/3

    IfC

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    5/64

    Chen CL 4

    the maximal zk is selected as the true compressibility factor. (Note: let z = 0 forC

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    6/64

    Chen CL 5

    %filename P5_01A_CCL

    R = 0.08206;%Gas constant (L-atm/g-mol-K)

    Tc = 647.4; %Critical temperature (K)

    Pc = 218.3; %Critical pressure (atm)

    a = 0.42747 * R ^ 2 * Tc ^ (5 / 2) / Pc;%Eq. (4-2), RK equation constb = 0.08664 * R * Tc / Pc; %Eq. (4-3),RK equation consta

    Pr = 10 %1.2;%0.1; %Reduced pressure (dimensionless)

    Tr = 3 %1; %Reduced temperature (dimensionless)

    Asqr = 0.42747 * Pr / (Tr ^ 2.5);%Eq. (4-8)

    B = 0.08664 * Pr / Tr; %Eq. (4-9)

    r = Asqr * B; %Eq. (4-6)q = B ^ 2 + B - Asqr; %Eq. (4-7)

    g = (-27 * r - (9 * q) - 2) / 27;%Eq. (4-12)

    f = (-3 * q - 1) / 3; %Eq. (4-11)

    C = (f / 3) ^ 3 + (g / 2) ^ 2; %Eq. (4-10)

    if (C > 0)E1 = 0 - (g / 2) - sqrt(C); %Eq. (4-15)

    D = (0 - (g / 2) + sqrt(C)) ^ (1 / 3);%Eq. (4-14)

    E = sign(E1) * abs(E1) ^ (1 / 3);%Eq. (4-15)

    z = D + E + 1 / 3;%Eq. (4-13), Compressibility factor (dimensionl

    else

    z = 0 ;

    Ch CL 6

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    7/64

    Chen CL 6

    end

    P = Pr * Pc; %Pressure (atm)

    T = Tr * Tc; %Temperature (K)

    V = z * R * T / P %Molar volume (L/g-mol)

    Pr =

    10

    Tr =

    3

    V =

    0.0837

    Ch CL 7

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    8/64

    Chen CL 7

    %filename P5_01B_CCL

    clear, clc, format compact, format short g

    Tc = 647.4; %Critical temperature (K)

    Pc = 218.3; %Critical pressure (atm)

    Tr_set=[1 1.2 1.5 2 3];Pr_set(1) = 0.1;

    Pr_set(2) = 0.2;

    i = 2 ;

    while Pr_set(i)

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    9/64

    Chen CL 8

    end

    end

    end

    disp( Compressibility Factor Versus Tr and Pr);

    disp( Tabular Results);disp( );

    disp(Pr\Tr 1.0 1.2 1.5 2 3 );

    Res=[Pr_set z];

    disp(Res);

    subplot(1,2,1)

    plot(Pr_set,z(:,1),-,Pr_set,z(:,2),+,Pr_set,z(:,3),*,...Pr_set,z(:,4),x,Pr_set,z(:,5),o,LineWidth,2);

    set(gca,FontSize,14,Linewidth,2)

    legend(Tr=1,Tr=1.2,Tr=1.5,Tr=2,Tr=3);

    title(\bf Compressibility Factor Versus Tr and Pr,FontSize,12)

    xlabel(\bf Reduced Pressure (Pr),FontSize,14);

    ylabel(\bf Compressibility Factor (z),FontSize,14);

    disp( Pause; Please press any key to continue ... )

    pause

    P_set=Pr_set.*Pc;

    disp( Molar Volume Versus Tr and P);

    disp( Tabular Results);

    Ch CL 9

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    10/64

    Chen CL 9

    disp( );

    disp(Pr\Tr 1.0 1.2 1.5 2 3 );

    Res=[P_set V];

    disp(Res);

    subplot(1,2,2)loglog(P_set,V(:,1),-,P_set,V(:,2),+,P_set,V(:,3),*,...

    P_set,V(:,4),x,P_set,V(:,5),o,LineWidth,2);

    legend(Tr=1,Tr=1.2,Tr=1.5,Tr=2,Tr=3);

    set(gca,FontSize,14,Linewidth,2)

    title(\bf Molar Volume Versus Tr and P,FontSize,12)

    xlabel(\bf Pressure (atm),FontSize,14);ylabel(\bf Molar Volume (L/g-mol),FontSize,14);

    Chen CL 10

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    11/64

    Chen CL 10

    function [z, V] = RKfun(Tr,Pr,Tc,Pc)

    R = 0.08206; %Gas constant (L-atm/g-m

    a = 0.42747 * R ^ 2 * Tc ^ (5 / 2) / Pc;%Eq. (4-2), RK equation const

    b = 0.08664 * R * Tc / Pc; %Eq. (4-3),RK equation constant

    Asqr = 0.42747 * Pr / (Tr ^ 2.5); %Eq. (4-8)B = 0.08664 * Pr / Tr; %Eq. (4-9)

    r = Asqr * B; %Eq. (4-6)

    q = B ^ 2 + B - Asqr; %Eq. (4-7)

    g = (-27 * r - (9 * q) - 2) / 27; %Eq. (4-12)

    f = (-3 * q - 1) / 3; %Eq. (4-11)

    C = (f / 3) ^ 3 + (g / 2) ^ 2; %Eq. (4-10)if (C > 0)

    E1 = 0 - (g / 2) - sqrt(C); %Eq. (4-15)

    D = (0 - (g / 2) + sqrt(C)) ^ (1 / 3); %Eq. (4-14)

    E = sign(E1) * abs(E1) ^ (1 / 3); %Eq. (4-15)

    z = D + E + 1 / 3; %Eq. (4-13), Compressibility factor (dimenselse

    z = 0 ;

    end

    P = Pr * Pc; %Pressure (atm)

    T = Tr * Tc; %Temperature (K)

    V = z * R * T / P; %Molar volume (L/g-mol)

    Chen CL 11

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    12/64

    Chen CL 11

    Calculation of Flow Rate In A Pipeline

    Concepts Utilized: Application of the general mechanical energy balance for

    incompressible fluids, and calculation of flow rate in a pipeline for various pipediameters and lengths.

    Numerical Methods: Solution of a single nonlinear algebraic equation andalternative solution using the successive substitution method.

    Problem Statement:The following figure shows a pipeline that delivers water at a constanttemperature T = 60oF from point 1 where the pressure is P1= 150 psig and theelevation is z1= 0 ft to point 2 where the pressure is atmospheric and theelevation is z2= 300 ft.

    The density and viscosity of the water can be calculated from the following

    Chen CL 12

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    13/64

    Chen CL 12

    equations.

    = 62.122 + 0.0122T 1.54 104T2 + 2.65 107T3 2.24 1010T4

    ln = 11.0318 + 1057.51

    T+ 214.624

    where T is in oF, is in lbm/ft3 , and is in lbm/fts.

    (a) Calculate the flow rate q (in gal/min) for a pipeline with effective length of

    L= 1000 ft and made of nominal 8-inch diameter schedule 40commercial steelpipe. (Solution: v= 11.61 ft/s, gpm =1811 gal/min)

    (b) Calculate the flow velocities in ft/s and flow rates in gal/min for pipelines at60oF with effective lengths ofL= 500, 1000, . . . 10, 000 ft and made of nominal

    4-, 5-, 6- and 8-inch schedule 40 commercial steel pipe. Use the successivesubstitution method for solving the equations for the various cases and presentthe results in tabular form. Prepare plots of flow velocity v versusD andL, andflow rate qversus D andL.

    (c) Repeat part (a) at temperatures T = 40, 60, and 100oF and display the results

    in a table showing temperature, density, viscosity, and flow rate.

    Chen CL 13

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    14/64

    Chen CL 13

    Solution:

    The general mechanical energy balance on an incompressible liquid applied to thiscase yields

    1

    2v2 + gz+

    gcP

    + 2

    fFLv2

    D = 0 (4

    20)

    where v is the flow velocity in ft/s, g is the acceleration of gravity given byg= 32.174 ft/s2, z =z2 z1 is the difference in elevation (ft), gc is aconversion factor (in English units gc= 32.174ft-lbm/lbfs2), P =P2P1 is thedifference in pressure lbm/ft

    2), fF is the Fanning friction factor, L is the length of

    the pipe (ft) andD is the inside diameter of the pipe (ft). The use of thesuccessive substitution method requires Equation (4-20) to be solved for v as

    v=

    gz+

    gcP

    12 2fFLv

    2

    D

    The equation for calculation of the Fanning friction factor depends on theReynolds number, Re= vD/, where is the viscosity in lbm/ft-s. For laminarflow (Re

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    15/64

    Chen CL 15

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    16/64

    Chen CL 15

    function P5_2C_CCL

    clear, clc, format short g, format compact

    D_list=[4.026/12 5.047/12 6.065/12 7.981/12]; % Inside diameter of pi

    T = 60; %Temperature (deg. F)

    for i = 1:4D = D_list(i);

    j=0;

    for L=500:500:10000

    j = j+1;

    L_list(j)=L; % Effective length of pipe (ft)

    [v(j,i),fval]=fzero(@NLEfun,[1 20],[],D,L,T);if abs(fval)>1e-10

    disp([No Conv. for L = num2str(L) and D = num2str(D)]);

    end

    q(j,i) = v(j,i) * pi * D ^ 2 / 4* 7.481 * 60; %Flow rate (gpm)

    end

    end

    disp( Flow Velocity (ft/s) versus Pipe Length and Diameter);

    disp( Tabular Results);

    disp();

    disp( L\D D=4" D=5" D=6" D=8");

    Res=[L_list v];

    Chen CL 16

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    17/64

    Chen CL 16

    disp(Res);

    subplot(1,2,1)

    plot(L_list,v(:,1),-,L_list,v(:,2),+,L_list,v(:,3),*,...

    L_list,v(:,4),x,LineWidth,2);

    set(gca,FontSize,14,Linewidth,2)legend( D=4", D=5", D=6", D=8");

    title(\bf Flow Velocity,FontSize,12)

    xlabel(\bf Pipe Length (ft),FontSize,14);

    ylabel(\bf Velocity (ft/s),FontSize,14);

    disp( Pause; Please press any key to continue ... )

    pausedisp( Flow Rate (gpm) versus Pipe Length and Diameter);

    disp( Tabular Results); disp();

    disp( L\D D=4" D=5" D=6" D=8");

    Res=[L_list q(:,1) q(:,2) q(:,3) q(:,4)];

    disp(Res);

    subplot(1,2,2)

    plot(L_list,q(:,1),-,L_list,q(:,2),+,L_list,q(:,3),*,...

    L_list,q(:,4),x,Linewidth,2);

    set(gca,FontSize,14,Linewidth,2)

    legend( D=4", D=5", D=6", D=8");

    title(\bf Flow rate,FontSize,14)

    Chen CL 17

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    18/64

    Chen CL 17

    xlabel(\bf Pipe Length (ft),FontSize,14);

    ylabel(\bf Flow rate (gpm),FontSize,14);

    function fv = NLEfun(v,D,L,T)epsilon = 0.00015;%Surface rougness of the pipe (ft)

    rho = 62.122+T*(0.0122+T*(-0.000154+T*(0.000000265-...

    (T*0.000000000224)))); %Fluid density (lb/cu. ft

    deltaz = 300; %Elevation difference (ft)

    deltaP = -150; %Pressure difference (psi)

    vis = exp(-11.0318 + 1057.51 / (T + 214.624)); %Fluid viscosity (lbm/pi = 3.1416; %The constant pi

    eoD = epsilon / D; %Pipe roughness to diameter ratio (dimensionless)

    Re = D * v * rho / vis; %Reynolds number (dimesionless)

    if (Re < 2100) %Fanning friction factor (dimensionless)

    fF = 16 / Re;

    else

    fF=1/(16*log10(eoD/3.7-(5.02*log10(eoD/3.7+14.5/Re)/Re))^2);

    end

    fv=v-sqrt((32.174*deltaz+deltaP*144*32.174/rho)...

    /(0.5-(2*fF*L/D))); %velocity (ft/s)

    Chen CL 18

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    19/64

    Chen CL 18

    Flow Velocity (ft/s) versus Pipe Length and Diameter

    Tabular Results

    L\D D=4" D=5" D=6" D=8"

    500 10.773 12.516 14.15 17.035

    1000 7.4207 8.6048 9.7032 11.6131500 5.9721 6.9243 7.8051 9.3295

    2000 5.1188 5.9361 6.6912 7.9953

    2500 4.5409 5.2674 5.9382 7.0953

    3000 4.1168 4.7769 5.3861 6.4362

    3500 3.7888 4.3975 4.9592 5.927

    4000 3.5255 4.093 4.6166 5.51854500 3.3082 3.8416 4.3338 5.1815

    5000 3.1249 3.6297 4.0953 4.8973

    5500 2.9677 3.4478 3.8907 4.6535

    6000 2.8309 3.2896 3.7128 4.4415

    6500 2.7106 3.1504 3.5561 4.2548

    7000 2.6036 3.0266 3.4169 4.0889

    7500 2.5077 2.9156 3.292 3.9402

    8000 2.4211 2.8154 3.1793 3.8059

    8500 2.3424 2.7244 3.0769 3.6838

    9000 2.2706 2.6412 2.9832 3.5723

    9500 2.2046 2.5648 2.8972 3.4698

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    20/64

    Chen CL 20

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    21/64

    9000 90.099 164.71 268.65 557.05

    9500 87.48 159.94 260.91 541.07

    10000 85.064 155.54 253.76 526.33

    Chen CL 21

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    22/64

    Adiabatic Operation of A Tabular Reactor for

    Cracking of Acetone

    Concepts Utilized: Calculation of the conversion and temperature profile in anadiabatic tubular reactor. Demonstration of the effect of pressure and heatcapacity change on the conversion in the reactor.

    Numerical Methods:

    Solution of simultaneous ordinary differential equations.

    Problem Statement:

    The irreversible, vapor-phase cracking of acetone (A) to ketene (B) and methane(C) that is given by the reaction

    CH3COCH3 CH2CO+ CH4is carried out adiabatically in a tubular reactor. The reaction is first order withrespect to acetone and the specific reaction rate can be expressed by

    ln(k) = 34.3434222

    T (4-26)

    Chen CL 22

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    23/64

    wherek is in s1 andT is in K. The acetone feed flow rate to the reactor is 8000kg/hr, the inlet temperature is T= 1150 K and the reactor operates at theconstant pressure ofP= 162 kPa (1.6 atm). The volume of the reactor is 4 m3.

    The material balance equations for the plug-flow reactor are given by

    dFAdV

    = rA (4-27)

    dFBdV

    = rA (4-28)dFC

    dV =

    rA

    (4-29)

    where FA, FB, andFCare flow rates of acetone, ketene, and methane in g-mol/s,respectively and rA is the reaction rate ofA in g-mol/m

    3s. The reaction is firstorder with respect to acetone, thus

    rA= kCAwhere CA is the concentration of acetone in g-mol/m

    3. For a gas phase reactor,using the appropriate units of the gas constant, the concentration of the acetonein g-mol/m3 is obtained by

    CA=

    1000yAP

    8.31T

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    24/64

    Chen CL 24

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    25/64

    reaction and the molar heat capacities.

    H = 80770 + 6.8(T 298) 0.00575(T2 2982) 1.27 106(T3 2983)CpA = 26.60 + 0.183T

    45.86

    106T2

    CpB = 20.04 + .0945T 30.95 106T2CpC = 13.39 + 0.077T 18.71 106T2

    Galculate the final conversion and the final temperature ofP = 1.6, 1.8, . . . , 5.0atm, for acetone feed rates ofFA0= 10, 20, 30, 35, and38.3 mol/s where nitrogenis fed to maintain the total feed rate38.3 mol/s in all cases. Present the results intabular form and prepare plots of final conversion versus P andFA0 and finaltemperature versus P andFA0.

    function P5_03C_CCL

    clear, clc, format short g, format compactFA0set = [10 20 30 35 38.3]; %Feed rate of acetone in kg-mol/s

    P_set(1)=1.6;

    i=1;

    while P_set(i)

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    26/64

    end

    n_P = size(P_set);

    for i=1:5

    FA0=FA0set(i);

    for j=1:n_PP=P_set(j)*101.325; % Pressure in kPa

    y0=[FA0; 0; 0; 1035; 0];

    [V,y] = ode45(@ODEfun,[0 4],y0,[],FA0,P);

    Xfin(j,i)=y(end,5);

    Tfin(j,i)=y(end,4);

    endend

    % -------------------------------------------------------------------

    disp( Final Conversion versus FA0 and Pressure);

    disp( Tabular Results);

    disp();

    disp( Pressure FA0=10 FA0=20 FA0=30 FA0=35 FA0=38.3 );

    Res=[P_set Xfin(:,1) Xfin(:,2) Xfin(:,3) Xfin(:,4) Xfin(:,5)];

    disp(Res);

    subplot(1,2,1)

    plot(P_set,Xfin(:,1),-,P_set,Xfin(:,2),+,P_set,Xfin(:,3),*,...

    P_set,Xfin(:,4),x,P_set,Xfin(:,5),o,LineWidth,2);

    Chen CL 26

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    27/64

    set(gca,FontSize,14,Linewidth,2)

    legend(FA0=10,FA0=20,FA0=30,FA0=35,FA0=38.3);

    title(\bf Final Conversion versus FA0 and Pressure,FontSize,12)

    xlabel(\bf Pressure (atm),FontSize,14);

    ylabel(\bf Final Conversion,FontSize,14);disp( Pause; Please press any key to continue ... )

    pause

    disp( Final Temperature versus FA0 and Pressure);

    disp( Tabular Results);

    disp();

    disp( Pressure FA0=10 FA0=20 FA0=30 FA0=35 FA0=38.3 );Res=[P_set Tfin(:,1) Tfin(:,2) Tfin(:,3) Tfin(:,4) Tfin(:,5)];

    disp(Res);

    subplot(1,2,2)

    plot(P_set,Tfin(:,1),-,P_set,Tfin(:,2),+,P_set,Tfin(:,3),*,...

    P_set,Tfin(:,4),x,P_set,Tfin(:,5),o,Linewidth,2);

    set(gca,FontSize,14,Linewidth,2)

    legend(FA0=10,FA0=20,FA0=30,FA0=35,FA0=38.3);

    title(\bf Final Temperature versus FA0 and Pressure,FontSize,12)

    xlabel(\bf Pressure (atm),FontSize,14);

    ylabel(\bf Temperature (K),FontSize,14);

    % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    Chen CL 27

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    28/64

    function dYfuncvecdV = ODEfun(V,Yfuncvec,FA0,P);

    FA = Yfuncvec(1);

    FB = Yfuncvec(2);

    FC = Yfuncvec(3);

    T = Yfuncvec(4);XA = Yfuncvec(5);

    k = 8.2E14 * exp(-34222 / T); %Reaction rate constant in s-1

    FN = 38.3 - FA0; %Feed rate of nitrogene in kg-mol/s

    yA = FA / (FA + FB + FC + FN); %Mole fraction of acetone

    CA = yA * P * 1000 / (8.31 * T); %Concentration of acetone in k-mol/m

    yB = FB / (FA + FB + FC + FN); %Mole fraction of keteneyC = FC / (FA + FB + FC + FN); %Mole fraction of methane

    rA = -k * CA; %Reaction rate in kg-mole/m3-s

    deltaH = 80770 + 6.8 * (T - 298) - .00575 * (T ^ 2 - 298 ^ 2)...

    - 1.27e-6 * (T ^ 3 - 298 ^ 3);

    CpA = 26.6 + .183 * T - 45.86e-6 * T ^ 2; %Heat capacity of acetone

    CpB = 20.04 + 0.0945 * T - 30.95e-6 * T ^ 2; %Heat capacity of ketene

    CpC = 13.39 + 0.077 * T - 18.71e-6 * T ^ 2; %Heat capacity of methane

    CpN = 6.25 + 8.78e-3 * T - 2.1e-8 * T ^ 2; %Heat capacity of nitrogen

    dFAdV = rA; %Differential mass balance on acetone

    dFBdV = -rA; %Differential mass balance on ketene

    dFCdV = -rA; %Differential mass balance on methane

    Chen CL 28

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    29/64

    dTdV = (-deltaH)*(-rA)/(FA*CpA+FB*CpB+FC*CpC+FN*CpN);

    %Differential enthalpy balance

    dXAdV = -rA / FA0; %Conversion of acetone

    dYfuncvecdV = [dFAdV; dFBdV; dFCdV; dTdV; dXAdV];

    Final Conversion versus FA0 and Pressure

    Tabular Results

    Pressure FA0=10 FA0=20 FA0=30 FA0=35

    1.6 0.31358 0.27759 0.26394 0.25964

    1.8 0.32043 0.28346 0.26946 0.26505

    2 0.32651 0.28867 0.27436 0.269862.2 0.33197 0.29335 0.27877 0.27419

    2.4 0.33693 0.2976 0.28277 0.27811

    2.6 0.34147 0.30149 0.28643 0.2817

    2.8 0.34565 0.30508 0.2898 0.28501

    3 0.34952 0.3084 0.29293 0.288083.2 0.35313 0.31149 0.29584 0.29094

    3.4 0.3565 0.31438 0.29856 0.29361

    3.6 0.35967 0.3171 0.30112 0.29612

    3.8 0.36266 0.31966 0.30353 0.29849

    4 0.36548 0.32208 0.30581 0.30073

    4.2 0.36815 0.32438 0.30797 0.30285

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    30/64

    Chen CL 30

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    31/64

    0.30752

    Pause; Please press any key to continue ...

    Final Temperature versus FA0 and Pressure

    Tabular Results

    Pressure FA0=10 FA0=20 FA0=30 FA0=35Columns 1 through 5

    1.6 911.84 908.14 907.47 907.47

    1.8 909.02 905.32 904.66 904.67

    2 906.5 902.81 902.16 902.18

    2.2 904.24 900.55 899.91 899.93

    2.4 902.18 898.49 897.87 897.892.6 900.3 896.61 895.99 896.02

    2.8 898.56 894.87 894.26 894.29

    3 896.94 893.26 892.66 892.69

    3.2 895.44 891.76 891.16 891.2

    3.4 894.03 890.35 889.76 889.8

    3.6 892.7 889.03 888.44 888.48

    3.8 891.45 887.78 887.19 887.24

    4 890.27 886.59 886.02 886.07

    4.2 889.15 885.47 884.9 884.95

    4.4 888.08 884.4 883.84 883.89

    4.6 887.07 883.39 882.82 882.88

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    32/64

    Chen CL 32

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    33/64

    Column 6

    907.53

    904.74

    902.25900.01

    897.97

    896.1

    894.38

    892.78

    891.29889.89

    888.58

    887.34

    886.17

    885.05883.99

    882.98

    882.02

    881.1

    Chen CL 33

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    34/64

    Correlation of The Physical Properties of Ethane

    Concepts Utilized:

    Correlations for heat capacity, vapor pressure, and liquid viscosity for an ideal gas.

    Numerical Methods:

    Polynomial, multiple linear, and nonlinear regression of data with linearization andtransformation functions.

    Problem Statement:

    Tables F-l through F-4 of Appendix F present values for different propertiesof ethane (ideal gas heat capacity, vapor pressure, and liquid viscosity) as functionof temperature. Various regression models will be fitted to the properties ofAppendix using MATLAB.

    (a) Construct a MATLAB function which solves the linear regression problemXb = y, where X is the matrix of the independent variable values, y is thevector of dependent variable values, and b is the vector of the linear regressionmodel parameters. The input parameters of the function are X, y, and alogical variable which indicates whether there is a free parameter. The returnedparameters are: and the respective confidence intervals, the calculated values

    of the dependent variable ycalc, the linear correlation coefficient R2

    , and the

    Chen CL 34

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    35/64

    variance. Test the function by fitting the Wagner equation to vapor pressuredata of ethane from TableF-3 of Appendix F.

    (b) Fit 3rd- and 5th-degree polynomials to the heat capacity of ethane for for the

    data given in Tables F-l and F-2 of Appendix F by using the multiple linearregression function developed in (a). Compare the quality of the representationof the various data sets with the polynomials of different degrees.

    (c) Fit the Antoine equation to liquid viscosity of ethane given in Table F-4 ofAppendix F.

    Chen CL 35

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    36/64

    % filename P5_04A_CCL

    clear, clc, format short g, format compact

    prob_title = ([Vapor Pressure Correlation for Ethane]);

    ind_var_name=[\bf Functions of Reduced Temp.];

    dep_var_name=[\bf Logarithm of Reduced Pressure];fname=input(Please enter the data file name > ); % VPfile.txt

    xyData=load(fname);

    X=xyData(:,2:end);

    y=xyData(:,1);

    [m,n]=size(X);

    freeparm=input(Input 1 if there is a free par., otherwise input 0>)[Beta,ConfInt, ycal,Var, R2]=MlinReg(X,y,freeparm);

    disp([ Results, prob_title]);

    Res=[];

    if freeparm==0, nparm = n-1; else nparm = n; end

    for i=0:nparm

    if freeparm==0; ii=i+1; else ii=i; end

    Res=[Res; ii Beta(i+1) ConfInt(i+1)];

    end

    disp( Parameter No. Beta Conf_int);

    disp(Res);

    disp([ Variance , num2str(Var)]);

    Chen CL 36

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    37/64

    disp([ Correlation Coefficient , num2str(R2)]);

    disp( Pause; Please press any key to continue ... )

    pause

    subplot(1,2,1)

    plot(y,y-ycal,*,Linewidth,2) % residual plotset(gca,FontSize,14,Linewidth,2)

    title([\bf Residual, prob_title],FontSize,12)

    xlabel([dep_var_name \bf (Measured)],FontSize,14)

    ylabel(\bf Residual,FontSize,14)

    disp( Pause; Please press any key to continue ... )

    pausesubplot(1,2,2)

    plot(X,ycal, r-,X,y,bo,Linewidth,2)

    title([\bf Cal/Exp Data prob_title],FontSize,12)

    set(gca,FontSize,14,Linewidth,2)

    xlabel([ind_var_name],FontSize,14)

    ylabel([dep_var_name],FontSize,14)

    % VPfile.txt : data file provided elsewhere

    Please enter the data file name > VPfile.txt

    Chen CL 37

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    38/64

    Input 1 if there is a free parameter, otherwise input 0> 0

    Results,Vapor Pressure Correlation for Ethane

    Parameter No. Beta Conf_int

    1 -6.4585 0.09508

    2 1.2895 0.21514

    3 -1.6712 0.26773

    4 -1.2599 0.29417

    Variance 9.3486e-005

    Correlation Coefficient 1

    Pause; Please press any key to continue ...

    Pause; Please press any key to continue ...

    Chen CL 38

    %

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    39/64

    % filename P5_04B_CCL

    clear, clc, format short g, format compact

    prob_title = ([Heat Capacity of Ethane]);

    ind_var_name=[\bf Normalized Temp];

    dep_var_name=[\bf Heat Capacity J/kmol*K ];fname=input(Please enter the data file name > ); % CPfile.txt

    xyData=load(fname);

    X=xyData(:,2:end);

    y=xyData(:,1);

    [m,n]=size(X);

    freeparm=input(Input 1 if there is a free par., otherwise input 0>)[Beta, ConfInt,ycal, Var, R2]=MlinReg(X,y,freeparm);

    disp([ Results, prob_title]);

    Res=[];

    if freeparm==0, nparm = n-1; else nparm = n; end

    for i=0:nparm

    if freeparm, ii=i+1; else ii=i; end

    Res=[Res; ii Beta(i+1) ConfInt(i+1)];

    end

    disp( Parameter No. Beta Conf_int);

    disp(Res);

    disp([ Variance , num2str(Var)]);

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    40/64

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    41/64

    Chen CL 41

    C l Ch i l E ilib i

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    42/64

    Complex Chemical Equilibrium

    by Gibbs Energy Minimization

    Concepts Utilized:Formulation of the chemical equilibrium problem as a Gibbs energy minimizationproblem with atomic balance constraints. The use of Lagrange multipliers tointroduce the constraints into the objective function. Conversion of theminimization problem into a system of nonlinear algebraic equations.

    Numerical Methods:

    Solution of a system of nonlinear algebraic equations.

    Problem Statement:

    Ethane reacts with steam to form hydrogen over a cracking catalyst at a

    temperature ofT= 1000 K and pressure ofP = 1 atm. The feed contains 4moles ofH2O per mole ofCH4. Balzisher et al. suggest that only the compoundsshown in Table 4-10 are present in the equilibrium mixture (assuming that nocarbon is deposited). The Gibbs energies of formation of the various compoundsat the temperature of the reaction (1000K) are also given in Table 4-10. Theequilibrium composition of the effluent mixture is to be calculated using these

    data.

    Chen CL 42

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    43/64

    Table 4-10: Compounds Present in Effluentof Steam Cracking Reactor

    Gibbs Energy Feed Effluent

    No. Comp. kcal/gm-mol gm-mol Ini. Est.1 CH4 4.61 0.001

    2 C2H4 28.249 0.001

    3 C2H2 40.604 0.001

    4 CO2

    94.61 0.993

    5 CO 47.942 1.6 O2 0. 0.0001

    7 H2 0. 5.992

    8 H2O 46.03 4 1.

    9 C2H6 26.13 1 0.001

    Formulate the problem as a constrained minimization problem. Introduce theconstraints into the objective function using Lagrange multipliers and differentiatethis function to obtain a system of nonlinear algebraic equations.

    Chen CL 43

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    44/64

    Solution:

    The objective function to be minimized is the total Gibbs energy given by

    min

    ni

    G

    RT

    = i=1

    cni Goi

    RT

    + ln ni

    ni (4 49)

    where ni is the number of moles of component i, c is the total number ofcompounds, R is the gas constant, and Go is the Gibbs energy of pure componenti at temperature T. The minimization of Equation (4-49) must be carried outsubject to atomic balance constraints

    Oxygen Balance 0 =g1 = 2n4+ n5+ 2n6+ n7 4 (4 50)Hydrogen Balance 0 =g2 = 4n1+ 4n2+ 2n3+ 2n7+ 2n8+ 6n9 14 (4 51)

    Carbon Balance 0 =g3 = n1+ 2n2+ 2n3+ n4+ n5+ 2n9 2 (4 52)

    The identification of the various components is given in Table 4-10. These threeconstraints can be introduced into the objective functions using Lagrangemultipliers: 1, 2,3. The extended objective function is

    minni,j

    F = i=1

    cni GoiRT

    + ln ni

    ni+

    3

    j=1

    jgj (4 53)

    Chen CL 44

    Th diti f i i f this f ti t ti l i t is th t ll th

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    45/64

    The condition for minimum of this function at a particular point is that all thepartial derivatives ofF with respect to ni andj vanish at this point. The partialderivative ofF with respect to n1 for example, is

    F

    n1 = Go

    1RT + ln

    n1ni + 4

    2+ 3 (4 54)

    The other partial derivatives with respect to ni can be obtained similarly. If it isexpected that the amount of a particular compound at equilibrium is very close tozero, it is preferable to rewrite the equation in a form that does not require

    calculation of the logarithm of a very small number. Rearranging Equation (4-54),for example, yields

    n1

    niexp

    Go1RT

    + 42+ 3

    = 0

    The partial derivatives ofFwith respect to 1, 2, and 3 areg1, g2, andg3,respectively.

    Chen CL 45

    function P5 05A1 CCL

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    46/64

    function P5_05A1_CCL

    clear, clc, format short g, format compact

    xguess = [10. 10. 10. 5.992 1. 1. 0.993 0.001 ...

    0.001 0.001 0.001 0.0001]; % initial guess vector

    disp(Variable values at the initial estimate);

    fguess = MNLEfun(xguess);

    disp( Variable Value Function Value)

    for i=1:size(xguess,2);

    disp([xint2str(i) num2str(xguess(i)) num2str(fguess(i))]);

    end

    options = optimset(Diagnostics,[off],TolFun,[1e-9],...TolX,[1e-9]);

    xsolv = fsolve(@MNLEfun,xguess,options);

    disp(Variable values at the solution);

    fsolv = MNLEfun(xsolv);

    disp( Variable Value Function Value)

    for i=1:size(xguess,2);disp([xint2str(i) num2str(xsolv(i)) num2str(fsolv(i))])

    end

    Chen CL 46

    function fx = MNLEfun(x)

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    47/64

    function fx = MNLEfun(x)

    lamda1 = x(1);

    lamda2 = x(2);

    lamda3 = x(3);

    H2 = x(4);

    H2O = x(5);

    CO = x(6);

    CO2 = x(7);

    CH4 = x(8);

    C2H6 = x(9);

    C2H4 = x(10);C2H2 = x(11);

    O2 = x(12);

    R = 1.9872;

    sum = H2 + O2 + H2O + CO + CO2 + CH4 + C2H6 + C2H4 + C2H2;

    fx(1,1) = 2 * CO2 + CO + 2 * O2 + H2O - 4; %Oxygen balance

    fx(2,1) = 4*CH4+4*C2H4+2*C2H2+2*H2+2*H2O+6*C2H6-14; %Hydrogen balancefx(3,1) = CH4 + 2 * C2H4 + 2 * C2H2 + CO2 + CO + 2 * C2H6 - 2; %Carbo

    fx(4,1) = log(H2 / sum) + 2 * lamda2;

    fx(5,1) = -46.03 / R + log(H2O / sum) + lamda1 + 2 * lamda2;

    fx(6,1) = -47.942 / R + log(CO / sum) + lamda1 + lamda3;

    fx(7,1) = -94.61 / R + log(CO2 / sum) + 2 * lamda1 + lamda3;

    Chen CL 47

    fx(8 1) = 4 61 / R + log(CH4 / sum) + 4 * lamda2 + lamda3;

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    48/64

    fx(8,1) = 4.61 / R + log(CH4 / sum) + 4 * lamda2 + lamda3;

    fx(9,1) = 26.13 / R + log(C2H6 / sum) + 6 * lamda2 + 2 * lamda3;

    fx(10,1) = 28.249 / R + log(C2H4 / sum) + 4 * lamda2 + 2 * lamda3;

    fx(11,1) = C2H2-exp(-(40.604/R+2*lamda2+2*lamda3))*sum;

    fx(12,1) = O2 - exp(-2 * lamda1) * sum;

    Variable values at the initial estimate

    Variable Value Function Value

    x1 10 -0.0138

    x2 10 0

    x3 10 0x4 5.992 19.5944

    x5 1 4.6407

    x6 1 -6.3214

    x7 0.993 -19.8127

    x8 0.001 43.2161

    x9 0.001 84.0454

    x10 0.001 65.1117

    x11 0.001 0.001

    x12 0.0001 9.9981e-005

    Optimization terminated: no further progress can be made.

    Trust-region radius less than 2*eps.

    Chen CL 48

    Problem may be ill-conditioned or Jacobian may be inaccurate

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    49/64

    Problem may be ill conditioned or Jacobian may be inaccurate.

    Try using exact Jacobian or check Jacobian for errors.

    Variable values at the solution

    Variable Value Function Value

    x1 10+7.44066e-015i -0.013798+4.9091e-

    x2 10-3.7436e-008i -0.015082-0.0002223

    x3 10-1.4705e-008i -0.0054569-7.4103e-

    x4 5.992+8.1803e-010i 19.5947+4.04813e

    x5 1+8.1803e-010i 4.6411+4.0488e-006i

    x6 1+8.182e-010i -6.3211+4.109e-006i

    x7 0.993+8.182e-010i -19.8124+4.10898ex8 0.00029165+6.9845e-010i 41.9842+6.3

    x9 -0.00037496-3.7053e-005i 83.0696-3.

    x10 -5.5221e-009-1.0635e-009i 53.0235-

    x11 0.0010003+8.1796e-010i 0.0010003+8

    x12 0.00010027+8.1823e-010i 0.00010025

    Chen CL 49

    function P5 05A2 CCL

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    50/64

    function P5_05A2_CCL

    clear, clc, format short g, format compact

    xguess = [10. 10. 10. 5.992 1. 1. 0.993 0.001...

    0.001 0.001 0.001 0.0001]; % initial guess vector

    disp(Variable values at the initial estimate);

    fguess = MNLEfun(xguess);

    disp( Variable Value Function Value)

    for i=1:size(xguess,2);

    disp([xint2str(i) num2str(xguess(i)) num2str(fguess(i))]);

    end

    options = optimset(Diagnostics,off,TolFun,1e-9,...TolX,1e-16,NonlEqnAlgorithm,gn);

    xsolv = fsolve(@MNLEfun,xguess,options);

    disp(Variable values at the solution);

    fsolv=MNLEfun(real(xsolv));

    disp( Variable Value Function Value)

    for i=1:size(xguess,2);disp([x int2str(i) num2str(real(xsolv(i))) num2str(fsolv(i))

    end

    Chen CL 50

    function fx = MNLEfun(x)

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    51/64

    function fx = MNLEfun(x)

    lamda1 = x(1);

    lamda2 = x(2);

    lamda3 = x(3);

    H2 = x(4);

    H2O = x(5);

    CO = x(6);

    CO2 = x(7);

    CH4 = x(8);

    C2H6 = x(9);

    C2H4 = x(10);C2H2 = x(11);

    O2 = x(12);

    R = 1.9872;

    sum = H2 + O2 + H2O + CO + CO2 + CH4 + C2H6 + C2H4 + C2H2;

    fx(1,1) = 2 * CO2 + CO + 2 * O2 + H2O - 4;

    fx(2,1) =4*CH4+4*C2H4+2*C2H2+2*H2+2*H2O+6*C2H6-14; %Hydrogen balancefx(3,1) = CH4 + 2 * C2H4 + 2 * C2H2 + CO2 + CO + 2 * C2H6 - 2; %Carbo

    fx(4,1) = log(H2 / sum) + 2 * lamda2;

    fx(5,1) = -46.03 / R + log(H2O / sum) + lamda1 + 2 * lamda2;

    fx(6,1) = -47.942 / R + log(CO / sum) + lamda1 + lamda3;

    fx(7,1) = -94.61 / R + log(CO2 / sum) + 2 * lamda1 + lamda3;

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    52/64

    Chen CL 52

    Variable Value Function Value

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    53/64

    Variable Value Function Value

    x1 24.4197 0

    x2 0.25306 1.7764e-015

    x3 1.5598 0

    x4 5.3452 -1.1102e-016

    x5 1.5216 2.1094e-015

    x6 1.3885 2.2204e-016

    x7 0.54492 -3.3307e-015

    x8 0.066564 0

    x9 1.6707e-007 1.3323e-015

    x10 9.5412e-008 1.3323e-015x11 3.157e-010 1.4387e-020

    x12 7.0058e-021 1.5466e-021

    Chen CL 53

    function P5 05B CCL

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    54/64

    function P5_05B_CCL

    clear, clc, format short g, format compact

    xguess = [10. 10. 10. 5.992 1. 1. 0.993 0.001...

    0.001 0.001 0.001 0.0001]; % initial guess vector

    disp(Variable values at the initial estimate);

    fguess = MNLEfun(xguess);

    disp( Variable Value Function Value)

    for i=1:size(xguess,2);

    disp([x int2str(i) num2str(xguess(i)) num2str(fguess(i))])

    end

    pote=[0 0 0 2 2 2 2 2 2 2 2 2];tol=1e-9;

    maxit=100;

    derfun=0;

    print=0;

    [xsolv,y,dy,info]=conles(@MNLEfun,xguess,pote,[],...

    tol,maxit,derfun,print);disp(Variable values at the solution);

    fsolv = MNLEfun(xsolv);

    disp( Variable Value Function Value)

    for i=1:size(xguess,2);

    disp([x int2str(i) num2str(xsolv(i)) num2str(fsolv(i))])

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    55/64

    Chen CL 55

    function fx = MNLEfun(x)

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    56/64

    function fx MNLEfun(x)

    lamda1 = x(1);

    lamda2 = x(2);

    lamda3 = x(3);

    H2 = x(4);

    H2O = x(5);

    CO = x(6);

    CO2 = x(7);

    CH4 = x(8);

    C2H6 = x(9);

    C2H4 = x(10);C2H2 = x(11);

    O2 = x(12);

    R = 1.9872;

    sum = H2 + O2 + H2O + CO + CO2 + CH4 + C2H6 + C2H4 + C2H2;

    fx(1,1) = 2 * CO2 + CO + 2 * O2 + H2O - 4;

    fx(2,1) = 4*CH4+4*C2H4+2*C2H2+2*H2+2*H2O+6*C2H6-14; %Hydrogen balancefx(3,1) = CH4 + 2 * C2H4 + 2 * C2H2 + CO2 + CO + 2 * C2H6 - 2; %Carbo

    fx(4,1) = log(H2 / sum) + 2 * lamda2;

    fx(5,1) = -46.03 / R + log(H2O / sum) + lamda1 + 2 * lamda2;

    fx(6,1) = -47.942 / R + log(CO / sum) + lamda1 + lamda3;

    fx(7,1) = -94.61 / R + log(CO2 / sum) + 2 * lamda1 + lamda3;

    Chen CL 56

    fx(8,1) = 4.61 / R + log(CH4 / sum) + 4 * lamda2 + lamda3;

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    57/64

    fx(8,1) 4.61 / R log(CH4 / sum) 4 lamda2 lamda3;

    fx(9,1) = 26.13 / R + log(C2H6 / sum) + 6 * lamda2 + 2 * lamda3;

    fx(10,1) = 28.249 / R + log(C2H4 / sum) + 4 * lamda2 + 2 * lamda3;

    fx(11,1) = C2H2-exp(-(40.604/R+2*lamda2+2*lamda3))*sum;

    fx(12,1) = O2 - exp(-2 * lamda1) * sum;

    Variable values at the initial estimate

    Variable Value Function Value

    x1 10 -0.0138

    x2 10 0

    x3 10 0x4 5.992 19.5944

    x5 1 4.6407

    x6 1 -6.3214

    x7 0.993 -19.8127

    x8 0.001 43.2161

    x9 0.001 84.0454

    x10 0.001 65.1117

    x11 0.001 0.001

    x12 0.0001 9.9981e-005

    Variable values at the solution

    Variable Value Function Value

    Chen CL 57

    x1 24.4197 0

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    58/64

    x2 0.25306 -1.7764e-015

    x3 1.5598 0

    x4 5.3452 -1.1102e-016

    x5 1.5216 -1.6653e-015

    x6 1.3885 -1.5543e-015

    x7 0.54492 5.5511e-015

    x8 0.066564 -4.4409e-016

    x9 1.6707e-007 -1.6964e-013

    x10 9.5412e-008 -2.589e-013

    x11 3.157e-010 9.3058e-025x12 5.4592e-021 -3.9873e-035

    Chen CL 58

    function P5_05C_CCL

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    59/64

    clear, clc, format short g, format compact

    xguess = [10. 10. 10. 5.992 1. 1. 0.993 0.001...

    0.001 0.001 0.001 0.0001]; % initial guess vector

    disp(Variable values at the initial estimate);

    fguess = MNLEfun(xguess);

    disp( Variable Value Function Value)

    for i=1:size(xguess,2);

    disp([x int2str(i) num2str(xguess(i)) num2str(fguess(i))]);

    end

    pote=[0 0 0 2 2 2 2 2 2 2 2 2];tol=1e-9; maxit=100;

    derfun=0; print=0;

    [xsolv,y,dy,info] = conles(@MNLEfun,xguess,pote,[],...

    tol,maxit,derfun,print);

    disp(Variable values at the solution);

    fsolv = MNLEfun(xsolv);disp( Variable Value Function Value)

    for i=1:size(xguess,2);

    disp([x int2str(i) num2str(xsolv(i)) num2str(fsolv(i))]);

    end

    H2 =xsolv(4);

    Chen CL 59

    H2O =xsolv(5);

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    60/64

    ;

    CO =xsolv(6);

    CO2 =xsolv(7);

    CH4 =xsolv(8);

    C2H6=xsolv(9);

    C2H4=xsolv(10);

    C2H2=xsolv(11);

    O2 =xsolv(12);

    R = 1.9872;

    sum = H2 + O2 + H2O + CO + CO2 + CH4 + C2H6 + C2H4 + C2H2;

    G_O2 = O2 * log(abs(O2 / sum));G_H2 = H2 * log(H2 / sum);

    G_H2O = H2O * (-46.03 / R + log(H2O / sum));

    G_CO = CO * (-47.942 / R + log(CO / sum));

    G_CO2 = CO2 * (-94.61 / R + log(CO2 / sum));

    G_CH4 = CH4 * (4.61 / R + log(abs(CH4 / sum)));

    G_C2H6 = C2H6 * (26.13 / R + log(abs(C2H6 / sum)));G_C2H4 = C2H4 * (28.249 / R + log(abs(C2H4 / sum)));

    G_C2H2 = C2H2 * (40.604 / R + log(abs(C2H2 / sum)));

    ObjFun=G_H2+G_H2O+G_CO+G_O2+G_CO2...

    +G_CH4+G_C2H6+G_C2H4+G_C2H2

    Chen CL 60

    function fx = MNLEfun(x)

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    61/64

    lamda1 = x(1);

    lamda2 = x(2);

    lamda3 = x(3);

    H2 = x(4);

    H2O = x(5);

    CO = x(6);

    CO2 = x(7);

    CH4 = x(8);

    C2H6 = x(9);

    C2H4 = x(10);C2H2 = x(11);

    O2 = x(12);

    R = 1.9872;

    sum = H2 + O2 + H2O + CO + CO2 + CH4 + C2H6 + C2H4 + C2H2;

    fx(1,1) = 2 * CO2 + CO + 2 * O2 + H2O - 4; %Oxygen balance

    fx(2,1) = 4*CH4+4*C2H4+2*C2H2+2*H2+2*H2O+6*C2H6-14; %Hydrogen balancefx(3,1) = CH4 + 2 * C2H4 + 2 * C2H2 + CO2 + CO + 2 * C2H6 - 2; %Carbo

    fx(4,1) = log(H2 / sum) + 2 * lamda2;

    fx(5,1) = -46.03 / R + log(H2O / sum) + lamda1 + 2 * lamda2;

    fx(6,1) = -47.942 / R + log(CO / sum) + lamda1 + lamda3;

    fx(7,1) = -94.61 / R + log(CO2 / sum) + 2 * lamda1 + lamda3;

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    62/64

    Chen CL 62

    x1 24.4197 0

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    63/64

    x2 0.25306 -1.7764e-015

    x3 1.5598 0

    x4 5.3452 -1.1102e-016

    x5 1.5216 -1.6653e-015

    x6 1.3885 -1.5543e-015

    x7 0.54492 5.5511e-015

    x8 0.066564 -4.4409e-016

    x9 1.6707e-007 -1.6964e-013

    x10 9.5412e-008 -2.589e-013

    x11 3.157e-010 9.3058e-025x12 5.4592e-021 -3.9873e-035

    ObjFun =

    -104.34

    Chen CL 63

  • 8/11/2019 13 Problem Solving with MATLAB.pdf

    64/64

    Thank You for Your Attention

    Questions Are Welcome