6 PRACTICAL NUMERICAL METHODS Chapter 3 VBA Practice Problem Ue Excel and VBA to olve the following problem. Document your olution uing the Expert Problem Solving tep outlined in Table 1.2. 1.961 x 0.5 y x 0.002432 1.002432 x 0.203 1. Create a VBA uer function for the following equation to generate normal random number from uni- formly ditributed random number (0<x<1) and the tandard deviation: 94 where x i a uniform random number (0<x<1) and i the tandard deviation. Generatee 1000 normal random value for y. Ue a tandardd deviation of 1 and plot the reult in a hitogram to check for normality viually. 2. The vicoity () of methane ga ha the following function of temperaturee (T). The temperature ha unit of degree Kelvin. The vicoity ha unit of Pa: 5.2546 10 T 105.67 1 T a. Create a uer function of the vicoity equation in VBA. b. Ue the VBA uer function to generate data for the vicoity between 300K and 1000K at 50K increment. Plot the reult in an yx catter plot. Label the axe. c. Ue Goal Seek to find the temperature when the vicoity of methane i 210-5 Pa. 3. Ue programming flowchart ymbol to diagram a macro in thi book, a aigned by the intructor (MS Office application, uch a Excel and Word have drawing tool with flow chart hape. For ex- ample, in Excel elect from the tab Inert>Shape>Flowchart) ). 7 0.59 Anwer: 622.51 K Flowchart Symbol Definition Flowchart Symbol Definition Flowchart Symbol Definition Start/end point Flow line Delay in the program Proce tep or equence of tep Alternate proce Deciion branching point Data Input/Output Subroutine Preparation Manual input Repeat until topped mannually Connect remote flow chart on the ame page Connect remote flow chart on different page Extractt Merge reult from two or more ubprocee Store data Dik torage or direct acce file Diplay information Internal torage Summing junction Or Printable document Collate/format orderr of information Sort data 4. Refer to Example 2.1. Create VBA uer functionn of Fourier erie for the dimenionle temperature at the center of a rectangle with three ide at the ame temperature and the fourth ide at a different 4 Rigg, J.B. (2001) Chemical Proce Control, 2 nd ed.., Ferret Publ., Lubbock, p. 121. 94
PRACTICE PROBLEMS 7 temperature. Your code hould have argument for the ratio of width to length, the number of term in the ummation, and ue a loop and workheet function. What i the dimenionle temperature for width to length ratio of 1, 0.5, 0.25, 0.125, 0.05, 0.025? How doe the number of term in the ummation affect the reult? Anwer: θ = 0.25,0.4451, 0.4976, 0.4999, 0.5 5. Create a VBA uer defined function to calculate the vapor preure of ethanol uing Antoine contant and temperature in degree C. log P B 10 A mmhg T C A = 8.11220, B = 1592.864, C = 226.184. Your function hould return the vapor preure in unit of Pa. Tet your function at T = 25 C Anwer: 7865 Pa 6. Write a VBA uer defined function to convert a mole fraction into a ma fraction of a binary ytem. Tet your function for a binary ytem of ethanol in water. What i the ma fraction of ethanol if the mole fraction i 0.85? Anwer: 0.9354 7. Write a VBA uer defined function to convert a ma fraction into a mole fraction for a binary ytem. Tet your function for a ytem of ethanol in water with a ma fraction of 30% water. Anwer: 0.5229 8. Create a VBA uer-defined function to convert humidity to mole fraction. Tet your function with a humidity of 0.04 kg water in 1 kg of air. Anwer: 0.061 9. Create a VBA macro to calculate the bubble point preure for mixture. Tet your macro with a ternary mixture of 40 mol% butane, 40 mol% pentane, and 20 mol% hexane at 100 C. Aume Raoult law. Antoine Equation for Vapor Preure: ln Component a b c Butane 13.6608 2154.70 238.789 Pentane 13.7667 2451.88 232.014 Hexane 13.8193 2696.04 224.317 b PkPa a T C c Anwer: 878.2 kpa 10. Write a VBA macro to calculate the bubble point temperature for a mixture at a given preure uing Goal Seek. Tet your function with the ternary ytem of Problem 9 at 1 atm. Anwer: 17.9 C 11. Create a VBA macro for calculating the dew point preure of a mixture at a given temperature. Tet your function uing the ternary ytem of Problem 9 at 1 atm preure. Aume Raoult law. 12. Create a VBA macro for calculating the dew point temperature of a mixture at a given preure uing Goal eek. Aume Raoult law. Tet your function. 13. Create a VBA macro to calculate the pecific volume uing the Peng-Robinon equation of tate. Tet your function. 14. Create a VBA macro to calculate the pecific volume uing the Suave Redlich Kwong equation of tate. Tet your function.
8 PRACTICAL NUMERICAL METHODS 15. Conider a binary ytem of methanol and water at one atmophere preure. Create VBA function of vapor preure in term of temperature and activity coefficient in term of mole fraction and temperature for methanol and water. Show your work, including your VBA function code. Calculate the bubble point and dew point temperature for the total range of methanol mole fraction. Show your reult in a Txy plot. Dew Pt T Bubble Pt x or y Calculate the vapor-liquid-equilibrium (VLE) mole fraction for the total range of methanol mole fraction. Show your reult in an yx plot to compare the reult with the experimental data tabulated below. y x Aume a modified form of Raoult law: i T i i i i i i i T yp xp or y xp P (1) where y i and x i are the vapor and liquid phae mole fraction of pecie i, P T and P are the total preure and aturation vapor preure of pecie i, repectively, and i i the activity-coefficient for pecie i. Apply Dalton law of partial preure to calculate the bubble (boiling) point temperature from the expreion: ixipi PT (2) i The dew point temperature i calculated from the expreion: yi 1 (3) P P i i i For binary ytem, the mole fraction of the econd pecie i calculated from the mole fraction of the firt pecie: x 2 = 1 x 1. The bubble and dew point equation become: 1 1 1 21 1 2 T x P x P P T (4) y1 1 y1 1 1 1 1 1 or y 1 1P1 2P2 PT PT 2P2 1P1 2P2 Get temperature correlation for vapor preure from DIPPR or ue the Antoine correlation for vapor preure in the appendice of your Material and Energy Balance or Thermodynamic textbook. Ue Wilon equation to calculate the activity coefficient: 1 (5)
PRACTICE PROBLEMS 9 12 21 ln1 ln x112x2x2 x x x x 1 12 2 21 1 2 12 21 ln 2 ln x2 21x1x1 x x x x 1 12 2 21 1 2 (6) (7) 2 12 11 12 exp 1 RT g 1 21 22 and 21 exp 2 RT g For the methanol (1), water (2) ytem 95 the binary interaction parameter are: 12 11 = 82.9876 cal/mol, 21 22 = 520.6458 cal/mol, and the molar volume are: 1 = 40.73 cm 3 /mol, 2 = 18.07 cm 3 /mol. Methanol-Water Sytem VLE data at P = 1 atm 96 x y x y 0.00 0.000 0.30 0.665 0.02 0.134 0.40 0.729 0.04 0.230 0.50 0.779 0.06 0.304 0.60 0.825 0.08 0.365 0.70 0.870 0.10 0.418 0.80 0.915 0.15 0.517 0.90 0.958 0.20 0.579 0.95 0.979 1.00 1.000 (8) 16. Set up an Excel workheet uing VBA function to calculate the adiabatic flame temperature of methane combution in air. CH 2O CO 2H O (9) 4 2 2 2 F CH4 F air T in q=0 F O2 or F CH4 F CO2 F H2O F N2 T out Calculate the adiabatic flame temperature from an energy balance around the reactant and product that aume no heat lo to the reactor urrounding: F in H in F out H out q 0 (10) where F and H are the inlet or outlet molar flow rate and enthalpie of the molecular pecie involved in the combution reaction. The heat lo, q = 0 under adiabatic condition. The exit tream molar flow rate are determined from the feed condition and toichiometry of the reaction in Equation (9). Calculate the enthalpy of each molecular pecie in either inlet or outlet tream from it heat of formation and heat capacity: 95 Perry Chemical Engineer Handbook, 7 th ed., p. 13-20. 96 Seader and Henley, Separation Proce Principle, 2 nd ed., p. 119
10 PRACTICAL NUMERICAL METHODS Tin Tout (11) H H c dt H H c dt in r p out r p Tr Tr where H r i the tandard heat of formation at the reference temperature, T r = 25C. The adiabatic flame temperature i the exit tream temperature, T out. Heat capacity function of temperature ue polynomial over a limited temperature range. p 2 3 c T abt ct dt (12) Subtitute Equation (12) into Equation (11) to give enthalpy a a function of temperature: 2 2 3 3 4 4 o b c d H H a T T T T T T T T 2 3 4 (13) The coefficient for each pecie are lited in Table 1. Equation (13) ue temperature in degree C. Follow thee tep to et up your Excel workheet for calculating the adiabatic flame temperature: (a) Set up the mole balance for each pecie in an Excel workheet. Aume complete combution and air i made up of 21 mole% O 2 and 79 mole% N 2. Although N 2 i not directly involved in the combution reaction, we mut account for the effect of N 2 on the temperature due to it enible heat. Specify a ratio of air to methane in the feed. Ue an IF() function in Excel to check for the limiting reactant, either CH 4 or O 2 in the feed tream. (b) Create VBA uer-defined function for the enthalpie of each molecular pecie. Ue the uer-function in your Excel workheet to calculate the total energy in and out of the reactor. Specify an inlet tream temperature. Gue the exit tream temperature. (c) Given the inlet tream temperature, the adiabatic flame temperature i the unknown exit tream temperature, T out, from the reactor in Equation (10). Ue Goal Seek to find the exit temperature that et the energy balance to zero. (d) Add a button to the workheet that call Goal Seek to calculate the flame temperature, or T out, for different inlet condition. (e) Tet your workheet for different combination of feed temperature, and flow rate of methane and air. Show all your work. Print the reult for the following three cae of inlet temperature and feed ratio of air to methane. What do you oberve? Cae Tin/C F air /F CH4 1 30 5 2 40 10 3 50 15
PRACTICE PROBLEMS 11 Table 1: Standard heat of formation (kj/mol) at 25C and heat capacity coefficient 97 for methane combution in air (kj/molc) for calculating enthalpy in Equation (12). 98 Specie H r a 10 2 b 10 5 c 10 9 d 10 12 CH 4-74.85 3.431 5.469 3.661-11 O 2 0 2.91 1.158-6.076 1.311 CO 2-393.5 3.611 4.233-28.87 7.464 H 2 O -241.83 3.346 0.688 7.604-3.593 N 2 0 2.9 0.2199 5.723-2.871 Anwer: 1799C, 2007C, 1478C 17. Create VBA uer function for denity and vicoity of ethanol. Ue your VBA function to plot the Reynold number (Re) veru temperature (T) over a range of 0<T<50C, given a diameter D=0.75 m and fluid velocity of v=0.15 m/. Note that T ha unit of degree K in the denity and vicoity function. Label the axe on the plot. Denity 0.232 T 3 ln 0.489 1.29 1 1 kg m 514 782 Pa T Vicoity exp 7.88 3.04lnT Reynold Number (Re) Re 18. Refer to the following equation Dv 2 x 1 0 x 0.5 yx expxinx 0.5 x 1 Create a VBA uer function for y in term of x. Ue your VBA uer function to generate an x-y line plot with marker for the range 0 x 1. Ue x increment of 0.1. Format the plot with x and y-axi label. Generate an x-y plot for the range 0 x 1. 19. Engineer ue tatitical quantitie to decribe experimental reult, uch a mean and tandard deviation. To remove experimental bia in our reult, we randomize the order of experiment. We may obtain a random permutation of number by blindly picking number from hat. Alternatively, we may ue Excel to generate a random permutation. a. Fill a column of 10 cell with integer 1 through 10. b. Select the cell on a workheet adjacent to the firt number from the previou tep and add the workheet formula = Rand() c. Select the cell and fill down 10 row. d. Select the range of cell containing the integer and random number and ort according to the econd column Data>Sort>Cutom Sort. 97 Note, the c p polynomial require temperature in degree C. 98 Felder, R. and R. Rouou, Elementary Principle of Chemical Procee, 3 rd ed. Wiley, New York, p. 635 (2005).
12 PRACTICAL NUMERICAL METHODS Create a VBA ub procedure to generate a random permutation of number on a workheet. a. Open the VBE and inert a module. Inert a Sub procedure and give it a decriptive name, e.g., PERMUTATE. b. Ue an Input Box to prompt the uer to elect a range of cell on the workheet for the random permutation of number. For example, Set p = Application.Inputbox(Prompt:= Select permutation range, _ Type:= 8) c. Aign the ize of the range p to the variable n uing the object modifier n = p.count. d. Create a one-dimenional array named x with ize n. ReDim x(1 to n) e. Ue a For Next loop to fill x with number 1 to n. f. Shuffle the integer in x: Loop through the array tarting from the lat poition For i = n To 2 Step -1 r = Int((i) * Rnd()) + 1 generate a random integer between 1 and i = x(r) Save the number in poition r x(r) = x(i) Replace number in poition r with number in poition i x(i) = Replace the number in poition i with the aved number Next i Ue a For Next loop to fill the range p with the huffled value. Tet your macro. 20. Create a VBA uer defined function of the vapor preure equation of methanol. Tet your function in an Excel workheet to calculate P when T = 300 K: B E P expa ClnT DT T where P and T have unit of Pa and K, repectively, and where A=82.718, B = -6904.5, C = -8.8622, D = 7.4664x10-6, E = 2. Anwer: 18.526 kpa