C hapter 3 VBA Practice Problems - d.umn.edu · this book, as g tools with . ... Answers: θ =...

7
6 C U S 1 2 3 4 94 6 Chapter 3 Use Excel and Solving steps 1. Create a V formly dis where x is random va normality 2. The visco units of de a. C b. U in c. U 3. Use progr (MS Offic ample, in Flowchart Symbol         4. Refer to E at the cen 4 Riggs, J.B. (2001 3 VBA Pra d VBA to solv outlined in Ta VBA user func stributed rand s a uniform ra alues for y. U y visually. osity () of me egree Kelvin. Create a user f Use the VBA u ncrements. Pl Use Goal Seek ramming flow ce application Excel select f Definition Start/end point Process step sequence of ste Alternate proce Decision bran point Data Input/Out Subroutine Internal storag Printable docum Example 2.1. nter of a recta 1) Chemical Proce actice Pro ve the followin able 1.2. ction for the dom numbers y x andom numbe Use a standard ethane gas ha . The viscosit function of the user function t lot the results to find the tem wchart symbo ns, such as Ex from the tab I Flowc Sym t  p or eps ess ching tput e ment Create VBA angle with thr ess Control, 2 nd ed. oblems ng problems. following equ (0<x<1) and 1.961 0.002432 x er (0<x<1) an d deviation of as the followin ty has units o 5.2546 1 e viscosity eq to generate da s in an yx scat mperature wh ols to diagram cel and Word nsert>Shapes chart mbol Defin  Flow l  Prepa  Manu  Repea mann  Conne chart  Conne chart Summ  Collat inform user function ree sides at th ., Ferret Publ., Lub Document yo uation to gen d the standard 0.5 1.002432 x nd is the sta f 1 and plot th ng function o of Pas: 7 0.59 6 10 105.67 T T quation in VBA ata for the vis tter plot. Lab hen the viscos m a macro in d have drawin s>Flowchart) nition line aration ual input at until stop nually ect remote f on the same pa ect remote f on different pag ming junction te/format order mation n of Fourier s he same temp bbock, p. 121. P our solutions nerate normal deviation: 94 0.203 x andard deviati he results in a of temperature A. scosity betwee bel the axes. sity of methan this book, as ng tools with ). Flowch Symb pped flow ge flow ge r of series for the perature and th PRACTICAL NUM using the Exp random num ion. Generate a histogram to e (T). The tem en 300K and ne is 210 -5 P Answ s assigned by flow chart sh hart bol Defini Delay i  Extract  Merge or mor  Store d  Disk s access  Display Or Sort da e dimensionle he fourth side MERICAL METHOD pert Problem mbers from un e 1000 norma o check for mperature has 1000K at 50K Pas. wer: 622.51 y the instructo hapes. For ex tion n the program t results from tw re subprocesses data torage or dire file y information ata ess temperatur e at a differen DS ni- al s K K or x- wo ect re nt

Transcript of C hapter 3 VBA Practice Problems - d.umn.edu · this book, as g tools with . ... Answers: θ =...

Page 1: C hapter 3 VBA Practice Problems - d.umn.edu · this book, as g tools with . ... Answers: θ = 0.25,0.4451, 0 ... humidity of 0.04 kg water in 1 kg of air. Answer: 0.061

6

CUS

1

2

3

4

94

6

Chapter 3Use Excel andSolving steps

1. Create a Vformly dis

where x israndom vanormality

2. The viscounits of de

a. C

b. Uin

c. U

3. Use progr(MS Officample, in

Flowchart Symbol 

 

 

 

 

 

 

 

 

4. Refer to Eat the cen

4 Riggs, J.B. (2001

3 VBA Prad VBA to solvoutlined in Ta

VBA user funcstributed rand

s a uniform raalues for y. U

y visually.

osity () of meegree Kelvin.

Create a user f

Use the VBA uncrements. Pl

Use Goal Seek

ramming flowce applicationExcel select f

Definition 

Start/end point

Process  stepsequence of ste

Alternate proce

Decision  branpoint 

Data Input/Out

Subroutine 

Internal storag

Printable docum

Example 2.1. nter of a recta

1) Chemical Proce

actice Prove the followinable 1.2.

ction for the dom numbers

y

x

andom numbeUse a standard

ethane gas ha. The viscosit

function of the

user function tlot the results

to find the tem

wchart symbons, such as Exfrom the tab I

FlowcSym

p  or eps 

ess 

ching 

tput 

ment 

Create VBA angle with thr

ess Control, 2nd ed.

oblems ng problems.

following equ(0<x<1) and

1.961

0.002432x

er (0<x<1) and deviation of

as the followinty has units o

5.2546

1

e viscosity eq

to generate das in an yx scat

mperature wh

ols to diagramcel and Wordnsert>Shapes

chart mbol 

Defin

  Flow l

 Prepa

 Manu

 

Repeamann

 

Connechart 

 

Connechart 

Summ

 Collatinform

A user functionree sides at th

., Ferret Publ., Lub

Document yo

uation to gend the standard

0.5

1.002432

x

nd is the staf 1 and plot th

ng function oof Pas:

7 0.596 10105.67

T

T

quation in VBA

ata for the vistter plot. Lab

hen the viscos

m a macro in d have drawins>Flowchart)

nition

line 

aration 

ual input 

at  until  stopnually 

ect  remote  fon the same pa

ect  remote  fon different pag

ming junction 

te/format  ordermation 

n of Fourier she same temp

bbock, p. 121.

P

our solutions

nerate normal deviation:94

0.203x

andard deviatihe results in a

of temperature

A.

scosity betweebel the axes.

sity of methan

this book, asng tools with ).

FlowchSymb

pped 

flow ge 

flow ge 

r  of 

series for theperature and th

PRACTICAL NUM

using the Exp

random num

ion. Generatea histogram to

e (T). The tem

en 300K and

ne is 210-5 P

Answ

s assigned byflow chart sh

hart bol 

Defini

Delay i

 Extract

 

Merge or mor

 Store d

 

Disk  saccess 

 Display

Or 

Sort da

e dimensionlehe fourth side

MERICAL METHOD

xpert Problem

mbers from un

e 1000 normao check for

mperature has

1000K at 50K

Pas.

wer: 622.51

y the instructohapes. For ex

tion 

n the program 

results  from  twre subprocesses

data 

torage  or  direfile 

y information 

ata 

ess temperature at a differen

DS

ni-

al

s

K

K

or x-

wo 

ect 

re nt

Page 2: C hapter 3 VBA Practice Problems - d.umn.edu · this book, as g tools with . ... Answers: θ = 0.25,0.4451, 0 ... humidity of 0.04 kg water in 1 kg of air. Answer: 0.061

PRACTICE PROBLEMS 7

temperature. Your code should have arguments for the ratio of width to length, the number of terms in the summation, and use a loop and worksheet functions. What is the dimensionless temperature for width to length ratios of 1, 0.5, 0.25, 0.125, 0.05, 0.025? How does the number of terms in the sum-mation affect the result?

Answers: θ = 0.25,0.4451, 0.4976, 0.4999, 0.5

5. Create a VBA user defined function to calculate the vapor pressure of ethanol using Antoine’s con-stants and temperature in degrees C.

10logP B

AmmHg T C

A = 8.11220, B = 1592.864, C = 226.184. Your function should return the vapor pressure in units of Pa. Test your function at T = 25°C

Answer: 7865 Pa

6. Write a VBA user defined function to convert a mole fraction into a mass fraction of a binary system. Test your function for a binary system of ethanol in water. What is the mass fraction of ethanol if the mole fraction is 0.85?

Answer: 0.9354

7. Write a VBA user defined function to convert a mass fraction into a mole fraction for a binary system. Test your function for a system of ethanol in water with a mass fraction of 30% water.

Answer: 0.5229

8. Create a VBA user-defined function to convert humidity to mole fraction. Test your function with a humidity of 0.04 kg water in 1 kg of air.

Answer: 0.061

9. Create a VBA macro to calculate the bubble point pressure for mixtures. Test your macro with a ter-nary mixture of 40 mol% butane, 40 mol% pentane, and 20 mol% hexane at 100°C. Assume Raoult’s law.

Antoine Equation for Vapor Pressure: lnb

P kPa aT C c

Component a b c Butane 13.6608 2154.70 238.789Pentane 13.7667 2451.88 232.014Hexane 13.8193 2696.04 224.317

Answer: 878.2 kPa

10. Write a VBA macro to calculate the bubble point temperature for a mixture at a given pressure using Goal Seek. Test your function with the ternary system of Problem 9 at 1 atm.

Answer: 17.9°C

11. Create a VBA macro for calculating the dew point pressure of a mixture at a given temperature. Test your function using the ternary system of Problem 9 at 1 atm pressure. Assume Raoult’s law.

12. Create a VBA macro for calculating the dew point temperature of a mixture at a given pressure using Goal seek. Assume Raoult’s law. Test your function.

13. Create a VBA macro to calculate the specific volume using the Peng-Robinson equation of state. Test your function.

14. Create a VBA macro to calculate the specific volume using the Suave Redlich Kwong equation of state. Test your function.

Page 3: C hapter 3 VBA Practice Problems - d.umn.edu · this book, as g tools with . ... Answers: θ = 0.25,0.4451, 0 ... humidity of 0.04 kg water in 1 kg of air. Answer: 0.061

8 PRACTICAL NUMERICAL METHODS

15. Consider a binary system of methanol and water at one atmosphere pressure. Create VBA functions of vapor pressure in terms of temperature and activity coefficients in terms of mole fraction and tem-perature for methanol and water. Show your work, including your VBA function code. Calculate the bubble point and dew point temperatures for the total range of methanol mole fractions. Show your results in a Txy plot.

Calculate the vapor-liquid-equilibrium (VLE) mole fractions for the total range of methanol mole fractions. Show your results in an yx plot to compare the results with the experimental data tabulated below.

Assume a modified form of Raoult’s law:

s si T i i i i i i i Ty P x P or y x P P (1)

where yi and xi are the vapor and liquid phase mole fractions of species i, PT and Ps are the total pres-sure and saturation vapor pressure of species i, respectively, and i is the activity-coefficient for spe-cies i. Apply Dalton’s law of partial pressure to calculate the bubble (boiling) point temperature from the expression:

si i i T

i

x P P (2)

The dew point temperature is calculated from the expression:

1i

sTi i i

y

PP (3)

For binary systems, the mole fraction of the second species is calculated from the mole fraction of the first species: x2 = 1 – x1. The bubble and dew point equations become:

1 1 1 2 1 21s sTx P x P P (4)

1

111

1 1 2 2 2 2 1 1 2 2

1 1 1 1 1 1s s s s s

T T

yyor y

P PP P P P P

(5)

Get temperature correlations for vapor pressure from DIPPR or use the Antoine correlations for vapor pressure in the appendices of your Material and Energy Balance or Thermodynamics textbooks. Use Wilson’s equation to calculate the activity coefficients:

T

x or y

Dew Pt

Bubble Pt

y

x

Page 4: C hapter 3 VBA Practice Problems - d.umn.edu · this book, as g tools with . ... Answers: θ = 0.25,0.4451, 0 ... humidity of 0.04 kg water in 1 kg of air. Answer: 0.061

PRACTICE PROBLEMS 9

12 211 1 12 2 2

1 12 2 21 1 2

ln ln x x xx x x x

(6)

12 212 2 21 1 1

1 12 2 21 1 2

ln ln x x xx x x x

(7)

2 12 1112

1

expgR T

and 1 21 22

212

expgR T

(8)

For the methanol (1), water (2) system95 the binary interaction parameters are: 12 11 = 82.9876

cal/mol, 21 22 = 520.6458 cal/mol, and the molar volumes are: 1 = 40.73 cm3/mol, 2 = 18.07 cm3/mol. Methanol-Water System VLE data at P = 1 atm96

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

16. Set up an Excel worksheet using VBA functions to calculate the adiabatic flame temperature of me-thane combustion in air.

4 2 2 22 2CH O CO H O (9)

Calculate the adiabatic flame temperature from an energy balance around the reactants and products that assumes no heat loss to the reactor surroundings:

0in in out outF H F H q (10)

where F and H are the inlet or outlet molar flow rates and enthalpies of the molecular species in-volved in the combustion reaction. The heat loss, q = 0 under adiabatic conditions. The exit stream molar flow rates are determined from the feed conditions and stoichiometry of the reaction in Equa-tion (9).

Calculate the enthalpy of each molecular species in either inlet or outlet streams from its heat of for-mation and heat capacity:

95 Perry’s Chemical Engineer’s Handbook, 7th ed., p. 13-20. 96 Seader and Henley, Separation Process Principles, 2nd ed., p. 119

FCH4 Fair Tin

FO2 or FCH4 FCO2 FH2O FN2 Tout

q=0

Page 5: C hapter 3 VBA Practice Problems - d.umn.edu · this book, as g tools with . ... Answers: θ = 0.25,0.4451, 0 ... humidity of 0.04 kg water in 1 kg of air. Answer: 0.061

10 PRACTICAL NUMERICAL METHODS

in out

r r

T T

in r p out r pT T

H H c dT H H c dT (11)

where Hr is the standard heat of formation at the reference temperature, Tr = 25C. The adiabatic flame temperature is the exit stream temperature, Tout.

Heat capacity functions of temperature use polynomials over a limited temperature range.

2 3pc T a bT cT dT (12)

Substitute Equation (12) into Equation (11) to give enthalpy as a function of temperature:

2 2 3 3 4 4

2 3 4o b c d

H H a T T T T T T T T (13)

The coefficients for each species are listed in Table 1. Equation (13) uses temperature in degree C.

Follow these steps to set up your Excel worksheet for calculating the adiabatic flame temperature:

(a) Set up the mole balances for each species in an Excel worksheet. Assume complete combus-tion and air is made up of 21 mole% O2 and 79 mole% N2. Although N2 is not directly in-volved in the combustion reaction, we must account for the effect of N2 on the temperature due to its sensible heat. Specify a ratio of air to methane in the feed. Use an IF() function in Excel to check for the limiting reactant, either CH4 or O2 in the feed streams.

(b) Create VBA user-defined functions for the enthalpies of each molecular species. Use the us-er-functions in your Excel worksheet to calculate the total energy in and out of the reactor. Specify an inlet stream temperature. Guess the exit stream temperature.

(c) Given the inlet stream temperature, the adiabatic flame temperature is the unknown exit stream temperature, Tout, from the reactor in Equation (10). Use Goal Seek to find the exit temperature that sets the energy balance to zero.

(d) Add a button to the worksheet that calls Goal Seek to calculate the flame temperature, or Tout, for different inlet conditions.

(e) Test your worksheet for different combinations of feed temperature, and flow rates of me-thane and air. Show all your work. Print the results for the following three cases of inlet temperature and feed ratio of air to methane. What do you observe?

Case Tin/C Fair/FCH4 1 30 5 2 40 10 3 50 15

Page 6: C hapter 3 VBA Practice Problems - d.umn.edu · this book, as g tools with . ... Answers: θ = 0.25,0.4451, 0 ... humidity of 0.04 kg water in 1 kg of air. Answer: 0.061

PRACTICE PROBLEMS 11

Table 1: Standard heats of formation (kJ/mol) at 25C and heat capacity coefficients97 for methane combustion in air (kJ/molC) for calculating enthalpy in Equation (12).98

Species Hr a × 102 b × 105 c × 109 d × 1012

CH4 -74.85 3.431 5.469 3.661 -11

O2 0 2.91 1.158 -6.076 1.311

CO2 -393.5 3.611 4.233 -28.87 7.464

H2O -241.83 3.346 0.688 7.604 -3.593

N2 0 2.9 0.2199 5.723 -2.871

Answers: 1799C, 2007C, 1478C

17. Create VBA user functions for density and viscosity of ethanol. Use your VBA functions to plot the Reynolds number (Re) versus temperature (T) over a range of 0<T<50C, given a diameter D=0.75 m and fluid velocity of v=0.15 m/s. Note that T has units of degrees K in the density and viscosity func-tions. Label the axes on the plot.

Density 0.232

3ln 0.489 1.29 1 1

514

T

kg m

Viscosity 782exp 7.88 3.04ln T

Pa s T

Reynolds Number (Re) ReD v

18. Refer to the following equation

2 0 0.51

0.5 1exp sin

xxy x

xx x

Create a VBA user function for y in terms of x.

Use your VBA user function to generate an x-y line plot with markers for the range 0≤x≤1. Use x in-crements of 0.1. Format the plot with x and y-axis labels.

Generate an x-y plot for the range 0≤x≤1.

19. Engineers use statistical quantities to describe experimental results, such as means and standard devi-ations. To remove experimental bias in our results, we randomize the order of experiments. We may obtain a random permutation of numbers by blindly picking numbers from hat. Alternatively, we may use Excel to generate a random permutation.

a. Fill a column of 10 cells with integers 1 through 10.

b. Select the cell on a worksheet adjacent to the first number from the previous step and add the worksheet formula

= Rand()

c. Select the cell and fill down 10 rows.

d. Select the range of cells containing the integers and random numbers and sort according to the second column Data>Sort>Custom Sort.

97 Note, the cp polynomial requires temperature in degrees C. 98 Felder, R. and R. Roussou, Elementary Principles of Chemical Processes, 3rd ed. Wiley, New York, p. 635 (2005).

Page 7: C hapter 3 VBA Practice Problems - d.umn.edu · this book, as g tools with . ... Answers: θ = 0.25,0.4451, 0 ... humidity of 0.04 kg water in 1 kg of air. Answer: 0.061

12 PRACTICAL NUMERICAL METHODS

Create a VBA sub procedure to generate a random permutation of numbers on a worksheet.

a. Open the VBE and insert a module. Insert a Sub procedure and give it a descriptive name, e.g., PERMUTATE.

b. Use an Input Box to prompt the user to select a range of cells on the worksheet for the random permutation of numbers. For example,

Set p = Application.Inputbox(Prompt:= “Select permutation range”, _ Type:= 8)

c. Assign the size of the range p to the variable n using the object modifier

n = p.Count.

d. Create a one-dimensional array named x with size n.

ReDim x(1 to n)

e. Use a For Next loop to fill x with numbers 1 to n.

f. Shuffle the integers in x:

‘ Loop through the array starting from the last position For i = n To 2 Step -1 r = Int((i) * Rnd()) + 1 ‘ generate a random integer between 1 and i s = x(r) ‘ Save the number in position r x(r) = x(i) ‘ Replace number in position r with number in position i x(i) = s ‘ Replace the number in position i with the saved number Next i

Use a For Next loop to fill the range p with the shuffled values.

Test your macro. 20. Create a VBA user defined function of the vapor pressure equation of methanol. Test your function

in an Excel worksheet to calculate P when T = 300 K:

exp ln EBP A C T DT

T

where P and T have units of Pa and K, respectively, and where A=82.718, B = -6904.5, C = -8.8622, D = 7.4664x10-6, E = 2.

Answer: 18.526 kPa