44
 Exercise 1: Write a program to convert a given temperature from F to C : Solution: We will store a number in a variable. That number is the value of a temperature in Fahrenheit. We will convert this value to centigrate. Enter the following commands. >> tf=45; >> tc =(tf-32)*5/9 the result will be tc = 7.2222 Exercise 2: Write a program to calculate the vapor pressure of water according to Antoine equation: P o =exp(A-B/(T+C)) Where T is any given temperature in Kelvin and A, B, and C are Antoine coefficients: A=18.3036 B=3816.44 C= -46.13 Solution: Let temperature equal to 373.15 k, write the following code. >> T=373.15; >> A=18.3036; >> B=3816.44; >> C= -46.13; >> Pw =exp(A-B /(T+C) ) Pw = 759.9430  Note: you can use an y variable name in your code .

232541184 Certain Numerical Problems Chemical Engineering MATLAB

Embed Size (px)

DESCRIPTION

extra problems solved for chemical belonging

Citation preview

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    1/44

    Exercise 1:

    Write a program to convert a given temperature from F to C:

    Solution:We will store a number in a variable. That number is the value of a temperature in

    Fahrenheit. We will convert this value to centigrate. Enter the following commands.

    >> tf=45;

    >> tc=(tf-32)*5/9

    the result will be

    tc =

    7.2222

    Exercise 2:

    Write a program to calculate the vapor pressure of water according to Antoine equation:

    Po=exp(A-B/(T+C))

    Where T is any given temperature in Kelvin and A, B, and C are Antoine coefficients:

    A=18.3036

    B=3816.44

    C= -46.13

    Solution:

    Let temperature equal to 373.15 k, write the following code.

    >> T=373.15;

    >> A=18.3036;

    >> B=3816.44;

    >> C= -46.13;

    >> Pw=exp(A-B/(T+C))

    Pw =759.9430

    Note: you can use any variable name in your code.

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    2/44

    15% X

    25% S

    40% T

    20% Z

    D=80

    B=?

    F=100kg

    ?% X

    ?% S

    ?% T

    ?% Z

    15% X

    25% S

    40% T20% Z

    Exercise 3:

    For the following distillation column write a code to find the value of stream B and the

    compositions of stream D?Solution:

    Type the commands as m-file. Then copy it to command window.

    F=100;

    D=80;

    B=F-D

    XF=0.15;

    SF=0.25;

    TF=0.4;ZF=0.2;

    XB=0.15;

    SB=0.25;

    TB=0.4;

    ZB=0.2;

    XD=(F*XF-B*XB)/D*100

    SD=(F*SF-B*SB)/D*100

    TD=(F*TF-B*TB)/D*100

    ZD=(F*ZF-B*ZB)/D*100

    Then after pressing enter the result will be:

    B =

    20

    XD =

    15

    SD =25

    TD =

    40

    ZD =

    20

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    3/44

    Exercise 1:

    Find the slope of a tangent line tox+3x-2at x=2.

    Solution:

    To find the slope of a tangent line tox+3x-2 at point 2, we need to find the derivative

    and to evaluate it atx=2.

    First we find the derivative of the function;

    >> diff(x^2+3*x-2)

    ans =

    2*x+3

    Then we representative the derivative as inline function

    >>f = inl ine('2*x+3')

    f = Inline funct ion: f(x) = 2*x+3

    And, finally, we evaluate the derivative at 2

    >> f(2) ans = 7

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    4/44

    Solution:

    By making component material balance on each component within the mixer you can

    reach to a system of three equations which can be solve by using the command solve to find

    the unknowns A, B, C.

    Type the following command:

    [A,B,C]=solve('.5*A+.3*B=.4*C','.2*A+.3*B=.2*C','.3*A+.4*B+100=.4*C')The results will be:

    A =

    600.

    B =

    200.

    C =

    900.

    A= ?

    50% Xylene

    20% Toluene

    30% Benzene

    Exercise 2:

    For the mixer shown below write a code to find the values of streams A, B and C?

    W= 100 Kg/hr100% Benzene

    B= ?

    30% Xylene

    30% Toluene

    40% Benzene

    C= ?

    40% Xylene20% Toluene

    40% Benzene

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    5/44

    27

    Type the same command by entering w=100 as the fourth equation:

    >>[A,B,C,W]=solve('.5*A+.3*B=.4*C','.2*A+.3*B=.2*C','.3*A+.4*B+W=.4*C','W

    =100')The results will be:

    A =

    600.

    B =

    200.

    C =

    900.

    W =100.

    Practice problems:

    1. Factorx+3xy+3xy+y.

    2. Simplify (x-8)/(x-2).

    3. Expand (x+1)(x-5)(2x+3).

    4. Solve sinx = 2-x forx.

    5. Solve 5x+2y+4z = 8, -3x+y+2z = -7, 2x+y+z = 3 forx, y andz.

    6. Solvey-5xy-y+6x+x = 2 forx.

    7. Find the first derivative of the function (sinx/(ln(x2+1))-e

    xand evaluate it at x=3.

    8. Find the 12th derivative of the function (x/2+1)65

    9. Find the first and second partial derivatives of the function ex2

    sinxy

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    6/44

    Exercise 1:

    Estimate the average boiling point of a Water/Ethanol system at different water

    compositions (0, 0.1, 0.2 ,0.3.1.0) knowing that.Boiling point of water =100

    oC

    Boiling point of Ethanol =78.35oC

    Mixture boiling point= Xwater TBpwater+ Xethanol TBpethanol

    Solution:

    Write the code as m-file then copy it to command window.

    TBPwater=100;

    TBPethanol=78.35;

    Xwater=0:.1:1

    Xethanol=1-Xwater

    T=TBPwater*Xwater+TBPethanol*Xethanol

    Then press enter, then the output will be:

    Xwater =

    0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000

    0.8000 0.9000 1.0000

    Xethanol =1.0000 0.9000 0.8000 0.7000 0.6000 0.5000 0.4000 0.3000

    0.2000 0.1000 0

    T =

    78.3500 80.5150 82.6800 84.8450 87.0100 89.1750 91.3400 93.5050

    95.6700 97.8350 100.0000

    Exercise 2:

    Calculate the Reynold Number at two different diameters D=0.2 and 0.5 m, using

    different velocity's as u=0.1,0.2,0.3 1 m/s knowing that:

    Re= (ud)/ , =0.001 , =1000

    Solution:

    Type the code

    d1=0.2;

    d2=0.5;

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    7/44

    u=0.1:.1:1;

    m=0.001;

    p=1000;Re1=u*p*d1/m

    Re2=u*p*d2/m

    The results will be

    Re1 =

    1.0e+005 *

    0.2000 0.4000 0.6000 0.8000 1.0000 1.2000 1.4000 1.6000

    1.8000 2.0000

    Re2 =

    1.0e+005 *

    0.5000 1.0000 1.5000 2.0000 2.5000 3.0000 3.5000 4.0000

    4.5000 5.0000

    Practice Problems

    1. Create a vector of the even whole numbers between 31 and 75.

    2. Let x = [2 5 1 6].

    a. Add 16 to each element.

    b.

    Add 3 to just the odd-index elements.

    c. Compute the square root of each element.

    d. Compute the square of each element.

    3. Let x = [3 2 6 8]' and y = [4 1 3 5]' .

    a. Add the elements in x to y

    b. Raise each element of x to the power specified by the corresponding element in y.

    c. Divide each element of y by the corresponding element in x

    d. Multiply each element in x by the corresponding element in y, calling the result "z".

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    8/44

    Exercise 1:

    Start with a fresh M-file editing window. Write a code to convert the temperature in

    Celsius into F and then into R for every temperature from 0 increasing 15 to 100C.

    Combine the three results into one matrix and display them as a table.

    SolutionWrite the code

    tc = [0:15:100]; % tc is temperature Celsius, tf is temp deg F,

    tf = 1.8.*tc + 32; % and tr is temp deg Rankin.

    tr = tf + 459.69;

    t = [tc',tf',tr'] % combine answer into one matrix

    The results will be

    t =

    0 32.0000 491.6900

    15.0000 59.0000 518.6900

    30.0000 86.0000 545.6900

    45.0000 113.0000 572.6900

    60.0000 140.0000 599.6900

    75.0000 167.0000 626.6900

    90.0000 194.0000 653.6900

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    9/44

    Exercise 2:

    Estimate the average boiling point of a Water/Ethanol system at different water

    compositions (0, 0.1, 0.2 ,0.3.1.0) knowing that.Boiling point of water =100

    oC

    Boiling point of Ethanol =78.35oC

    Mixture boiling point= Xwater TBpwater+ Xethanol TBpethanol

    Note: Make a matrix of three columns; first and second for water and ethanol

    compositions and the third for average density.

    Solution:

    Write the codeWD=1000;

    ED=789;

    Xw=0:.1:1;

    Xe=1:-.1:0;

    AD=WD*Xw+ED*Xe;

    A=Xw';

    A(:,2)=Xe';

    A(:,3)=AD';A

    The output of the above code will be

    A =

    1.0e+003 *

    0 0.0010 0.7890

    0.0001 0.0009 0.8101

    0.0002 0.0008 0.8312

    0.0003 0.0007 0.8523

    0.0004 0.0006 0.8734

    0.0005 0.0005 0.8945

    0.0006 0.0004 0.9156

    0.0007 0.0003 0.9367

    0.0008 0.0002 0.9578

    0.0009 0.0001 0.9789

    0.0010 0 1.0000

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    10/44

    Exercise 3:

    Make a table of (x vs. y) values for the three component ethanol, water and benzene a

    T=373.15 k. Knowing that the vapor pressure of these three components are calculated by:Ethanol P

    oe=exp(18.5242-3578.91/(T-50.5))

    Water Pow=exp(18.3036-3816.44/(T-46.13))

    Benzene Pob=exp(15.9008-2788.51/(T-52.36))

    Where

    Ki= Poi /Pt, Pt=760, yi =Kixi

    Solution:

    T=373.15;

    Pe=exp(18.5242-3578.91/(T-50.5));

    Pw=exp(18.3036-3816.44/(T-46.13));

    Pb=exp(15.9008-2788.51/(T-52.36));

    Ke=Pe/760; Kw=Pw/760; Kb=Pb/760;

    Xe=0:.1:1; Ye=Ke*Xe;

    Xw=0:.1:1; Yw=Kw*Xw;

    Xb=0:.1:1; Yb=Kb*Xb;

    A=[Xe',Ye' ,Xw',Yw',Xb',Yb']The output of the above code will be:

    A=

    0 0 0 0 0 0

    0.1000 0.2223 0.1000 0.1000 0.1000 0.1777

    0.2000 0.4445 0.2000 0.2000 0.2000 0.3554

    0.3000 0.6668 0.3000 0.3000 0.3000 0.5331

    0.4000 0.8890 0.4000 0.4000 0.4000 0.7107

    0.5000 1.1113 0.5000 0.5000 0.5000 0.8884

    0.6000 1.3335 0.6000 0.6000 0.6000 1.0661

    0.7000 1.5558 0.7000 0.6999 0.7000 1.2438

    0.8000 1.7780 0.8000 0.7999 0.8000 1.4215

    0.9000 2.0003 0.9000 0.8999 0.9000 1.5992

    1.0000 2.2225 1.0000 0.9999 1.0000 1.7769

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    11/44

    Example:solve the following system equations:x + 2y = 5

    2x + 6y = 14

    To solve these equations write the code;

    a=[1 2; 2 6];

    b=[5; 14];

    z=a\b

    yields

    z =

    1.0000

    2.0000

    this results means that x=z(1)=1 and y=z(2)=2

    Example:Solve the system of linear equations given below using Matlab.

    3.5u+2v =5

    -1.5u+2.8v+1.9w=-1-2.5v+3w=2

    Solution

    A=[3.5 2 0;-1.5 2.8 1.9;0 -2.5 3];

    B=[5;-1;2]

    X=A\B

    X=

    1.4421

    -0.0236

    0.6470

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    12/44

    Exercise 1:

    For the following separation system, we know the inlet mass flowrate (in Kg/hr) and

    the mass fractions of each species in the inlet (stream 1) and each outlet (streams 2, 4, and

    5). We want to calculate the unknown mass flow rates of each outlet stream.

    Solution:

    If we define the unknowns as

    x1=F1, x2=F2 , x3=F3

    and set up the mass balances for

    1. the total mass flow rate

    x1 +x2 +x3 =10

    2. the mass balance on species 10.04x1+0.54x2+0.26x3=0.2*10

    3. the mass balance on species 2

    0.93x1+0.24X2 =0.6*10

    These three equations can be written in matrix form

    =

    6

    2

    10

    3

    2

    1

    024.093.0

    26.054.004.0

    111

    x

    x

    x

    To find the values of unknown flowrates write the code:

    A=[1, 1, 1; .04, .54, .26; .93, .24 ,0];

    B=[10; .2*10; .6*10];

    X=A\B;

    F1=X(1),F2=X(2),F3=X(3)

    The results will be

    F1 =5.8238

    F2 =

    2.4330

    F3 =

    1.7433

    F=10

    A=20%B=60%

    C=20%

    F3=?

    A=26%

    B=0 %

    C=74%

    F2=?

    A=54%B=24%

    C=22%

    F1=?

    A=4 %

    B=93%

    C=3 %

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    13/44

    Exercise 2:

    Fit the following data describing the accumulation of species A over time to a second

    order polynomial, then by using this polynomial, predict the accumulation at 15 hours.Time (hr) 1 3 5 7 8 10

    Mass A acc. 9 55 141 267 345 531

    Solution:

    First, input the data into vectors, let:

    a = [9, 55, 141, 267, 345, 531];

    time = [1, 3, 5, 7, 8, 10];

    Now fit the data using polyfit

    coeff = polyfit(time,a,2)

    coeff =

    5.0000 3.0000 1.0000

    So, Mass A = 5*(time)2+ 3 * (time) + 1

    Therefore to calculate the mass A at 15 hours

    MApred = polyval(coeff,15)

    MApred =

    1.1710e+003

    Exercise 3:

    Use matlab to fit the following vapor pressure vs temperature data in fourth order

    polynomial. Then calculate the vapor pressure when T=100 OC.

    Temp (C) -36.7 -19.6 -11.5 -2.6 7.6 15.4 26.1 42.2 60.6 80.1

    Pre. (kPa) 1 5 10 20 40 60 100 200 400 760

    Solution:

    vp = [ 1, 5, 10, 20, 40, 60, 100, 200, 400, 760];

    T = [-36.7, -19.6, -11.5, -2.6, 7.6, 15.4, 26.1, 42.2, 60.6, 80.1];

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    14/44

    p=polyfit(T,vp,4)

    %evaluate the polynomial at T=100

    pre= polyval(p,100)

    the results will be

    p =

    0.0000 0.0004 0.0360 1.6062 24.6788

    pre =

    1.3552e+003

    PRACTICE PROBLEMS1) Solve each of these systems of equations by using the matrix inverse ( Gaussian

    Elimination ) method.

    A) -2x1+x2=-3

    -2x1+x2=3.00001

    B) x1+ x2+ x3= 4

    2x1+ x2+ 3x3= 7

    3x1+ x2+6x3 = 2

    C ) x1+2x2-x3=3

    3x1-x2+2x3=1

    2x1-2x2+3x3=2

    x1-x2+x4=-1

    D) 5x1+3x2+7x3-4=03x1+26x2-2x3-9=0

    7x1+2x2+10x3-5=0

    2. Find the solution to

    r + s + t + w = 4

    2r - s + w = 2

    3r + s - t - w = 2

    r - 2s - 3t + w = -3

    using the matrix method.

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    15/44

    3. Find the solution to

    2x1+ x2- 4x3+ 6x4+ 3x5- 2x6= 16

    -x1+ 2x2+ 3x3+ 5x4- 2x5 = -7

    x1- 2x2- 5x3+ 3x4+ 2x5+ x6= 1

    4x1+ 3x2- 2x3+ 2x4 + x6= -1

    3x1 + x2- x3+ 4x4+ 3x5+ 6x6= -11

    5x1+ 2x2- 2x3+ 3x4+ x5+ x6= 5

    using the matrix method.

    4. Find the 3rd

    order polynomial that satisfies the above data of water for saturation

    temperature and pressure. Using the predicted polynomial, compute the saturation pressureat 65 C.

    Temp

    (C)

    0 10 20 30 40 50 60 70 80 90 100

    Pre.

    (kPa)

    .6108 1.227 2.337 4.241 7.375 12.335 19.92 31.16 47.36 70.11 101.33

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    16/44

    Exercise 1:

    Write a program to calculate average density, conductivity and specific heat for water in

    the range of temperatures from 0 to 50 C. Knowing that this parameters for water are afunction of temperature such as the following equations.

    The Density

    = 1200.92 1.0056 TKo+ 0.001084 * (TK

    o)

    2

    The condactivity

    K= 0.34 + 9.278 * 10-4

    .TKo

    The Specific heat

    CP= 0.015539 (TKo 308.2)

    2+ 4180.9

    Note: take 11 point of temperatures

    Solution:

    ap=0;

    aKc=0;

    aCp=0;

    for T=273:5:323

    p= 1200.92 - 1.0056*T+ 0.001084 * T^2;

    Kc = 0.34 + 9.278 * 10^-4 *T;

    Cp = 0.015539*(T - 308.2)^2 + 4180.9;

    ap=ap+p;

    aKc=aKc+Kc;

    aCp=aCp+Cp;

    end

    Averagedensity=ap/11

    Averageconductiv ity=aKc/11

    Averagespecif icheat=aCp/11Gives the results

    Averagedensi ty =

    997.7857

    Averageconduct ivi ty =

    0.6165

    Averagespecificheat =

    4.1864e+003

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    17/44

    Exercise 2:

    Use loop to find the bubble point of ternary system (Ethanol 40 mol%, Water 20 mol%

    and Benzene 40 mol%). Knowing that the vapor pressure for three components are calculatedby:

    Ethanol Poe=exp(18.5242-3578.91/(T-50.5))

    Water Pow=exp(18.3036-3816.44/(T-46.13))

    Benzene Pob=exp(15.9008-2788.51/(T-52.36))

    Where

    Ki= Poi /Pt

    Pt=760

    yi =Kixi

    At Bubble point yi=Kixi =1

    Solution:

    Xe=.4;Xw=.2;Xb=.4;

    for T=273.15:.01:450;

    Pe=exp(18.5242-3578.91/(T-50.5)); % Vapor pressure of Ethanol

    Pw=exp(18.3036-3816.44/(T-46.13)); % Vapor pressure of Water

    Pb=exp(15.9008-2788.51/(T-52.36)); % Vapor pressure of Benzene

    % evaluation of equilibrium constants

    Ke=Pe/760; % Ethanol

    Kw=Pw/760; % Water

    Kb=Pb/760; % Benzene

    % The condition to find the boiling point

    sum=Ke*Xe+Kw*Xw+Kb*Xb;

    if sum>1

    breakend

    end

    T

    Gives the result

    T =

    355.5300

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    18/44

    Exercise 3:

    Given that the vapor pressure of methyl chloride at 333.15 K is 13.76 bar, write a code

    to calculate the molar volume of saturated vapor at these conditions using Redlich/Kwongequation. Knowing;

    a=0.42748*R2Tc

    2.5/Pc

    b=0.08664*RTC/PC

    Vi+1=(RT/P)+b- (a*(Vi-b))/(T1/2

    PVi(Vi+b))

    R=83.14 , Tc= 416.3 k , Pc= 66.8 bar

    Solution:

    T=333.15; Tc=416.3;

    P=13.76; Pc=66.8; R=83.14;a=0.42748*R^2*Tc^2.5/Pc;

    b=0.08664*R*Tc/Pc;

    V(1)=R*T/P;

    for i=1:1:10

    V(i+1)=(R*T/P)+b-(a*(V(i)-b))/(T^.5*P*V(i)*(V(i)+b));

    end

    V'

    The program results as follows

    ans =

    1.0e+003 *

    2.0129

    1.7619

    1.7219

    1.7145

    1.71311.7129

    1.7128

    1.7128

    1.7128

    1.7128

    1.7128

    Note that after the 6 th trail the value of Vi is constant and further trails does not have

    any effect on its value.

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    19/44

    Practice problems:

    1/ evaluate the output of a given MATLAB code for each of the cases indicated below.

    if z < 5w = 2*z

    elseif z < 10

    w = 9 - z

    elsei f z < 100

    w = sqrt(z)

    else

    w = z

    end

    a. z = 1 w = ?

    b. z = 9 w = ?

    c. z = 60 w = ?

    d. z = 200 w = ?

    2/ Write brief code to evaluate the following functions.

    t = 200 when y is below 10,000

    = 200 + 0.1 (y - 10,000) when y is between 10,000 and 20,000

    = 1,200 + 0.15 (y - 20,000) when y is between 20,000 and 50,000

    = 5,700 + 0.25 (y - 50,000) when y is above 50,000

    Test cases:

    a. y = 5,000 t = ?

    b. y = 17,000 t = ?b. y = 25,000 t = ?

    c. y = 75,000 t = ?

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    20/44

    Exercise 1:

    The laminar velocity profile in a pipe, can be given in equation Vx=Vmax(1-(2*r/di)2)

    Where

    r= distance from pipe center

    di: Inner diameter of pipe (di=0.2 m)

    Vmax: maximum velocity in pipe (Vmax=2 m)

    Plot the velocity profile in a pipe?

    SolutionWrite the following code

    di=.2; Vmax=2

    r=-.1:.001:.1

    Vx=Vmax*(1-((2*r)/di).^2)

    plot(Vx,r)

    xlabel('Velocity (m/s)')

    ylabel('Distance from pipe center (m)')The result will be the figure.

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    21/44

    Exercise 2:

    Plot k as a function of temperature from 373 to 600 k (use 50 point of Temperature).

    If you know:

    K=A exp(B-(C/T)-ln(D*T)-E*T+F*T2)

    where

    A=3.33

    B=13.148

    C=5639.5

    D=1.077

    E=5.44*10-4

    F=1.125*10-7

    Solution

    Write the following code

    A=3.33; B=13.148; C=5639.5; D=1.077; E=5.44e-4; F=1.125e-7;Ts=(600-373)/49;%Ts means temperature increment

    m=0;

    for T=373:Ts:600

    m=m+1

    Temp(m)=T

    K(m)=A*exp(B-(C/T)-log(D*T)-E*T+F*T^2)

    end

    plot(Temp, K)

    xlabel('Temperature')

    ylabel('K value')

    The result will be the figure.

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    22/44

    Liquid x,T

    Vapor y,T

    Exercise 3:

    Plot Txy diagram for ethanol/water system. Knowing that the vapor pressure for three

    components are calculated by:

    Ethanol Poe=exp(18.5242-3578.91/(T-50.5))

    Water Pow=exp(18.3036-3816.44/(T-46.13))

    Where

    Ki= Poi /Pt

    Pt=760

    yi =Kixi

    At Bubble point yi=Kixi =1

    Solution:

    Xe=0:.1:1;

    Xw=1-Xe;

    for m=1:11

    for T=273.15:.01:450;

    Pe=exp(18.5242-3578.91/(T-50.5)); % Vapor pressure of Ethanol

    Pw=exp(18.3036-3816.44/(T-46.13)); % Vapor pressure of Water

    Ke=Pe/760; % Ethanol

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    23/44

    Kw=Pw/760; % Water

    sum=Ke*Xe(m)+Kw*Xw(m);

    if sum>1break

    end

    end

    Temp(m)=T;

    ye(m)=Ke*Xe(m);

    end

    plot(Xe,Temp,'k-+',ye,Temp,'k-*')

    axis ([0 1 340 380])

    xlabel('x,y for ethanol ')

    ylabel('Temperatre K')

    title('Txy diagram of ethanol/ water system')

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    24/44

    Practice Problems

    1. Plot the log of the values from 1 to 100.2. Plot the parametric curve x = t cos(t), y = t sin(t) for 0 < t < 10.

    3. Plot the cubic curve y = x. Label the axis and put a title "a cubic curve" on the top of

    the graph.

    4. Plot y=(x3+x+1)/x, for 4< x

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    25/44

    Practice Problems

    Q1:write program to calculate the volumetric and mass flow rate of a liquid flowing in a pipewith a velocity equal to 0.5 m/s. Knowing that the diameter of this pipe is 0.1 m and thedensity of this liquid is 890 kg/m3 ?

    Solution:

    d=0.1;p=890;u=.5;

    A=(pi/4)*d^2;

    Volflow=u*A

    Massflow=Volflow*p

    A =

    0.0079

    Volflow =

    0.0039

    Massflow =

    3.4950

    Q2:The heat capacity of ethylene is given by the equation:3925 T1017.6T108.30.156T3.95Cp ++=

    Write a program to evaluate the heat capacity T=40 C Then claculate the ethylene enthalpy(h) when T1=80 in which.H=Cp(T1-Tref)Tref=0 CSolution:

    T=40;

    Tref=0;

    T1=80;Cp=3.95+.159*T-8.3*10^-7*T^2+17.6*10^-9*T^3

    h=Cp*(T1-Tref)

    Cp =

    10.3098

    h =

    824.7839

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    26/44

    ATCost = 2000

    Q3:Write a program to calculate the cost of iron used in manufacturing a cylindrical tank,where.

    DLDA +=2

    5.0

    in which:T: Thickness= 0.01 mD: Diameter=2 mA: Surface areaL: length = 5 mCost in $ dollarSolution:

    T=0.01;

    L=5;

    D=2;

    A=0.5*pi*D^2+pi*D*L;

    % Cost in $ dollar

    Cost=2000*T*A

    Cost =

    753.9822

    Q4:Calculate the heat required to increase the temperature of 1 mol of methane from 533.15K to 873.15 C in a flow process at a pressure approximately 1 bar. where

    22 +++= DTCTBTAR

    Cp

    A=1.702 , B=9.081*10-3

    , C=-2.164*10-6

    , D=0R=8.314and

    =Tout

    Tin

    CpdtnQ

    Solution:

    syms T;

    T1=533.15;

    T2=873.15;

    A=1.702;

    B=9.081e-3;

    C=-2.164e-6;

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    27/44

    R=8.314;

    Cp=(A+B*T+C*T^2);

    Q=R*int(Cp,T1,T2)Q =

    1.9778e+004

    Q5:For the following distillation column calculate the values of F1, F3 and F4?

    solution:

    [F1,F3,F4]=solve('.2*F1+250=.5*F3+.2*F4','.3*F1+250=.3*F3+.4*F4','.

    5*F1=.2*F3+.4*F4')

    F1 =

    1000

    F3 =

    500

    F4=

    1000

    F1=?

    20%A

    30%B

    50%D

    F3=?

    50%A

    30%B20%D

    F4=?

    20%A

    40%B

    40%D

    F2=500

    50%A

    50%B

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    28/44

    Q6:Estimate the average density of a Water/Ethanol mixture at different water compositionsknowing that.Water density =1000 kg/m3Ethanol density =780 kg/m3Mixture density= Xwater Water density + Xethanol Ethanol densitySolution:

    Pwater=1000;

    Pethanol=780;

    Xwater=0:.1:1

    Xethanol=1-Xwater

    Pav=Pwater*Xwater+Pethanol*Xethanol

    Xwater =0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000

    0.7000 0.8000 0.9000 1.0000

    Xethanol =

    1.0000 0.9000 0.8000 0.7000 0.6000 0.5000 0.4000

    0.3000 0.2000 0.1000 0

    Pav =

    780 802 824 846 868 890 912

    934 956 978 1000

    Q7:Write a program to calculate the vapor pressure for the following system and to calculateand tabulate its k-values.P1=exp(14.2724-2945.47/(T+224))P2= exp(14.2043-2972.64/(T+209))Temperature range =75-125 C

    oUse 11 point for temperature

    Pt=101.3Ki= Pi /Pt

    Solution:T=75:5:125;

    P1=exp(14.2724-2945.47./(T+224))

    P2= exp(14.2043-2972.64./(T+209))

    Pt=101.3

    K1= P1/PtK2= P2/PtA=[T,P1,P2,K1,K2]

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    29/44

    Q8: Write a program to estimate the physical properties for water in the range oftemperatures from 273 to 323 K.The Density

    = 1200.92 1.0056 T + 0.001084 T2The conductivityK= 0.34 + 9.278 * 10

    -4T

    The Specific heatCP= 0.015539 (T 308.2)

    2+ 4180.9

    Note: take 101 points of temperaturesSolution:

    T=273:.5:323;

    %The Density

    P = 1200.92 - 1.0056*T + 0.001084*T.^2 ;

    %The conductivity

    K= 0.34 + 9.278* 10^-4*T;

    %The Specific heat

    CP = 0.015539*(T-308.2).^2 + 4180.9;

    A=[T',P',K',CP']

    Q9:Solve the following system of equations forx, y and zby using matrix method.

    10x+3y+5z = 88x+2y+2z = 73x+4y-z = 6 .

    Solution:

    A=[10,3,5;8,2,2;3,4,-1];

    B=[8;7;6];

    X=A\B;

    x=X(1),y=X(2),z=X(3)

    Gives the resultsx =

    0.7917

    y =

    0.7917

    z =

    -0.4583

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    30/44

    Q10: Find the solution to this system of equationsr + s + t + w = 4

    2r - s + w = 23r + s - t - w = 2r - 2s - 3t + w = -3

    using the matrix method.Solution:

    A=[ 1 1 1 1;2 -1 0 1;3 1 -1 -1; 1 -2 -3 1];

    B=[4;2;2;-3];

    X=A\B;

    r=X(1),s=X(2),t=X(3),w=X(4)

    r =1

    s =

    1

    t =

    1

    w =

    1

    Q11:Make a table of (x vs. y) values for the three component ethanol, water and benzene aT=373.15 k. Knowing that the vapor pressure of these three components are calculated by:

    Note: take 11 point for each component form 0 to 1Ethanol P

    oe=exp(18.5242-3578.91/(T-50.5))

    Water Po

    w=exp(18.3036-3816.44/(T-46.13))Benzene Pob=exp(15.9008-2788.51/(T-52.36))WhereKi= P

    oi /Pt, Pt=760, yi =Kixi

    Solution:T=373.15

    Pe=exp(18.5242-3578.91/(T-50.5));

    Pw=exp(18.3036-3816.44/(T-46.13));

    Pb=exp(15.9008-2788.51/(T-52.36));

    Ke=Pe/760;

    Kw=Pw/760;

    Kb=Pb/760;

    Xe=0:.1:1;

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    31/44

    Ye=Ke*Xe;

    Xw=0:.1:1;

    Yw=Kw*Xw;Xb=0:.1:1;

    Yb=Kb*Xb;

    A=[Xe',Ye',Xw',Yw',Xb',Yb']

    A =

    Xe Ye Xw Yw Xb Yb

    0 0 0 0 0 0

    0.1000 0.2223 0.1000 0.1000 0.1000 0.1777

    0.2000 0.4445 0.2000 0.2000 0.2000 0.3554

    0.3000 0.6668 0.3000 0.3000 0.3000 0.5331

    0.4000 0.8890 0.4000 0.4000 0.4000 0.7107

    0.5000 1.1113 0.5000 0.5000 0.5000 0.8884

    0.6000 1.3335 0.6000 0.6000 0.6000 1.0661

    0.7000 1.5558 0.7000 0.6999 0.7000 1.2438

    0.8000 1.7780 0.8000 0.7999 0.8000 1.4215

    0.9000 2.0003 0.9000 0.8999 0.9000 1.5992

    1.0000 2.2225 1.0000 0.9999 1.0000 1.7769

    Q12:Calculate the pressure of and ideal gas (with two digits accuracy) if the temperature ofideal gas is calculated from the equation;T=A*T^.3+B*T^.7A= 0.452B= 0.736Where this gas is follow ideal gas lawPV=RTV=1R=8.314Solution:

    clear all

    clc

    A= 0.452; B= 0.736; V=1; R=8.314;

    T(1)=273.15;

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    32/44

    P(1)=R*T(1)/V

    for m=1:100

    T(m+1)=A*T(m)^.3+B*T(m)^.7;P(m+1)=R*T(m+1)/V ;

    if abs(P(m+1)-P(m))

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    33/44

    Note: calculate the volumetric flow rate to four digit accuracySolution:

    A=0.35; B=0.98; C=0.342;

    di=0.2;

    u=1;%any initial assumption

    Area=(pi/4)*di^2

    Q(1)=u*Area

    for i=1:100

    u=A*u^.3+B*u^.6+C*u^.9;

    Q(i+1)= Area* u

    if abs(Q(i+1)-Q(i))

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    34/44

    Q14:For the vapor liuqid seperater shown in fig. Write a program to calculate the values ofXA,XB,YA,YB, L and VIf you know:XA+XB=1YA+YB=1YA=KA*XA=2XAYB=KB*XB=2XB

    Solution:

    A=[1,1,0,0;0,0,1,1;-2,0,1,0;0,-.5,0,1];B=[1;1;0;0];

    X=A\B;

    xa=X(1),xb=X(2),ya=X(3),yb=X(4)

    a=[xa,ya;xb,yb];

    b=[.4*100;.6*100];

    x=a\b;

    L=x(1),V=x(2)

    Gives the results

    xa =

    0.3333

    xb =

    0.6667

    ya =

    0.6667

    yb =

    0.3333

    L =

    80

    V =

    20.0000

    Q15:Xylene, styrene, toluene and benzene are to be separated with the array of distillationcolumns that is shown below. Write a program to calculate the amount of the streams D, B,

    D1, B1, D2 and B2 also to calculate the composition of streams D and B.

    liquid

    F=100 Kg/hr

    40% A

    60% B

    Vapor

    V=?

    YA=?YB=?

    L=?

    XA=?

    XB=?

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    35/44

    SolutionBy making material balances on individual components on the overall separation train yieldthe equation setXylene: 0.07D1+ 0.18B1+ 0.15D2+ 0.24B2= 0.15 70Styrene: 0.04D1+ 0.24B1+ 0.10D2+ 0.65B2= 0.25 70Toluene: 0.54D1+ 0.42B1+ 0.54D2+ 0.10B2= 0.40 70

    Benzene: 0.35D1+ 0.16B1+ 0.21D2+ 0.01B2= 0.20 70Overall material balances and individual component balances on column 2 can be used todetermine the molar flow rate and mole fractions from the equation of stream D.Molar Flow Rates: D = D1 + B1Xylene: XDxD = 0.07D1 + 0.18B1Styrene: XDsD = 0.04D1 + 0.24B1Toluene: XDtD = 0.54D1 + 0.42B1Benzene: XDbD = 0.35D1 + 0.16B1where

    XDx = mole fraction of Xylene.

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    36/44

    XDs = mole fraction of Styrene.XDt = mole fraction of Toluene.XDb =mole fraction of Benzene.Similarly, overall balances and individual component balances on column 3 can be used todetermine the molar flow rate and mole fractions of stream B from the equation set.Molar Flow Rates: B = D2 + B2Xylene: XBxB = 0.15D2 + 0.24B2Styrene: XBsB = 0.10D2 + 0.65B2Toluene: XBtB = 0.54D2 + 0.10B2Benzene: XBbB = 0.21D2 + 0.01B2where F, D, B, D1, B1, D2 and B2 are the molar flow rates in mol/min.

    Solution;clear all

    clc

    A=[0.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];

    B=[0.15*70; 0.25*70; 0.4*70; 0.2*70];

    X=A\B;

    D1=X(1),B1=X(2),D2=X(3),B2=X(4),

    D=D1+B1B=D2+B2

    XDx=(.07*D1+.18*B1)/D

    XDs=(.04*D1+.24*B1)/D

    XDt=(.54*D1+.42*B1)/D

    XDb=(.35*D1+.16*B1)/D

    XBx=(.15*D2+.24*B2)/B

    XBs=(.1*D2+.65*B2)/B

    XBt=(.54*D2+.1*B2)/B

    XBb=(.21*D2+.01*B2)/B

    The results will be

    D1 =

    26.2500

    B1 =

    17.5000

    D2 =

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    37/44

    8.7500

    B2 =

    17.5000D =

    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

    Q16:The experiemental values calculated for the heat capacity of ammonia from 0 to 500 are

    T (C) Cp ( cal /g.mol C)

    0 8.37118 8.472

    25 8.514

    100 9.035

    200 9.824

    300 10.606

    400 11.347

    500 12.045

    1. Fit the data for the following function

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    38/44

    32DTCTbTaCp +++=

    Where T is in C

    2. Then calculate amount of heat Q required to increase the temperature of 150 mol/hr ofammonia vapor from 0 C to 200 C if you know that:

    =Tout

    Tin

    CpdtnQ

    Solution:

    T=[0,18,25,100,200,300,400,500]

    Cp=[8.371, 8.472, 8.514, 9.035, 9.824, 10.606, 11.347, 12.045]

    P=polyfit(T,Cp,3)n=150;

    syms t

    Cpf=P(4)+P(3)*t+P(2)*t^2+P(1)*t^3;

    Q= n*int(Cpf, 0,200)

    2.7180e+005

    Q17: A simple force balance on a spherical particle reaching terminal velocity in a fluid isgiven by;Vt=((4g(p- )Dp)/(3CDp))^.5WhereVt : Terminalvelocity in m/sg : Acceleration of gravity

    pp: Particle densityDp: The diameter of the spherical particle in mCD: Dimensionless drag coefficient.The drag coefficient on a spherical particle at terminal velocity varies with Reynolds number(Re) as followings:

    CD=24/Re for Re< 0.1CD=24*(1+0.14* Re^0.7)/Re for 0.1=

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    39/44

    Calculate the terminal velocity of spherical particle?Solution:The above problem can not be solved without using trail and error method. Therefore youmust assume a velocity to calculate the CD which is a important to calculate new velocity.Write the following code:

    g=9.80665; p=994.6; pp=1800; mu=8.931e-4; Dp=0.000208;

    % Assume vt of any initial terminal velocity for first trail

    vt=1;

    Velocity(1)=vt;

    for m=1:1:20

    Re=(Dp*vt*p)/mu;

    if Re < 0.1

    CD=24/Re;

    elseif Re >= 0.1 & Re 1000 & Re 350000

    CD=0.19-8*10^4/Re;

    end

    vt=((4*g*(pp-p)*Dp)/(3*CD*p))^.5;

    Velocity(m+1)=vt;

    if abs (Velocity(m+1)-Velocity(m))

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    40/44

    0.0160

    0.0159

    0.01580.0158

    0.0158

    Q18: Unsteady-state ball loss 10% of its last height after each strike in ground. If this ball hasinitial height equal to 2 m and stop when its height reaches lower than 0.2 m. Plot its heightas a function of strike no.Solution:

    clear all ,clc

    h(1)=2;

    m=1

    while h(m)> .2

    h(m+1)=.9*h(m);

    m=m+1

    end

    plot(1:m,h,'k')

    xlabel ('Strike No.')

    ylabel('Ball Height m')

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    41/44

    Q19:a tree raise in different raising rate, when its initial height is 5 meter write a program toplot a tree height as a function of time within ten years.Raising rate = (1/time).Solution:

    clear all, clc

    m=1

    L(1)=5

    Time(1)=0

    for tim=1:10

    L(m+1)=L(m)+(1/tim)

    Time(m+1)=tim

    m=m+1

    end

    plot(Time,L,k)

    xlabel ('Time (year)')

    ylabel('Tree height m')

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    42/44

    Q20: A naphthalene sphere loss each day amount of weight equal to 0.2*(survace area)^0.5.If its initial diameter is 2 cm. write a program to plot naphthalene diameter, as a function oftime until the diameter is reach 0.2 m.

    Note:Naphthalene density=0.890 gm/cm3

    A=d2

    V=(4/3) d3

    Solution:

    clear all

    clc

    p=.89;

    m=1;ti=0;

    time(1)=0

    d(1)=2;

    V(1)=(4/3)*pi*d(1)^3;

    W(1)=V(1)*p;

    while d(m)>.2;

    ti=ti+1;

    time(m+1)=ti;

    A=pi*d(m)^2;

    W(m+1)=W(m)-.2*A^.5;

    V(m+1)=W(m+1)/p;

    d(m+1)=(V(m+1)*(3/4)*(1/pi))^(1/3);

    m=m+1;

    end

    plot(time,d,'k');xlabel('Time (day)')

    ylabel('Sphere diameter (cm)')

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    43/44

    Q21: Plot Pxy diagram for the Binary system of acetonitrile(1)/nitromethane(2). Vaporpressures for the pure species are given by the following equations.For acetonitrile(1) P

    o1=exp(14.2724-2945.47/(T+224))

    For nitromethane(2) Po2= exp(14.2043-2972.64/(T+209))In whichT=75 CoP1 and P2 in kpaKi= P

    oi /Pt

    At Bubble point yi=Kixi =1Solution:

    Write the following codeX1=0:.1:1;

    X2=1-X1;

    T=75;

    P1=exp(14.2724-2945.47/(T+224));% Vapor pressure of acetonitrile

    P2=exp(14.2043-2972.64/(T+209));% Vapor pressure of nitromethane

    for m=1:11

    for Pt=.1:.01:120;

    K1=P1/Pt; % acetonitrile

  • 5/21/2018 232541184 Certain Numerical Problems Chemical Engineering MATLAB

    44/44

    K2=P2/Pt; % nitromethane

    sum=K1*X1(m)+K2*X2(m);

    if sum