Part A. Introduction To Excel and VBA: Computer Lab #1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

CHE212- Process Engineering and Analysis 2016

Computer Lab #1

Download the Excel file from Blackboard. Save it as IC-1-yourstudentID.xlsm.

Part A. Introduction to Excel and VBA


Question A1
Calculate the change of enthalpy for all gases using the spreadsheet at 25 and
2000oC. (Fill out the cells in spreadsheet A1).

Note 1: if you type this formula into cell G5, you can copy and paste into G5:H8:

=$C5*G$4+$D5*G$4^2/2+$E5*G$4^3/3+$F5*G$4^4/4

Change manually H4 so that J10=L10.

Note 2: if you change the position of $ in above formula and copy/paste, what will happen?

Note 3: you can change $ by pressing “F4”

Question A2. Introduction to VBA


Step 1: Open Excel and get to VBA Editor: “Alt” + “F11”
Step 2: Insert a Module (see screen shot below).
CHE212- Process Engineering and Analysis 2016
CHE212- Process Engineering and Analysis 2016

Step 3: Start entering the function (such as in Question B1 & B2)


Step 4: Go back to Excel, save your file as Macro-Enabled Workbook (*.xlsm)
CHE212- Process Engineering and Analysis 2016

Part B. Bisection method


Question B1
Write a VBA code to calculate the “Enthalpy” of gas mixture at a given temperature:

Function enthalpy(T, xCO2, xH2O, xO2, xN2)


Dim a(4), b(4), c(4), d(4), ent(4)

a(1)= … b(1) =….


a(2)=
….. ‘ input all constants of heat capacity

For i = 1 To 4
ent(i) = a(i) * T + b(i) * T ^ 2 / 2 + c(i) * T ^ 3 / 3 + d(i) * T ^ 4 / 4
Next i
enthalpy= ent(1) * xCO2 + ent(2) * xH2O + ent(3) * xO2 + ent(4) * xN2

End Function

Where: T is the temperature, xCO2, xH2O, xO2, xN2 are moles of CO2, H2O, O2 and N2,
respectively.

Check your code in Excel spreadsheet by comparing to your answer in Question A1.

Question B2
Write a VBA code to calculate T2 so that:

enthalpy(T2, xCO2, xH2O, xO2, xN2) - enthalpy(25, xCO2, xH2O, xO2, xN2) = 826.957 kJ
CHE212- Process Engineering and Analysis 2016

Function BisectionX (Lo,Up, xCO2, xH2O, xO2, xN2, tolx)


Dim Mi, c1, c2, c3, i, n
n = Abs(Up - Lo) / tolx
For i = 1 To n
Mi = (Lo + Up) / 2: c1 = ff (Lo, xCO2, xH2O, xO2, xN2)
c2 = ff (Up, xCO2, xH2O, xO2, xN2):
c3 = ff (Mi, xCO2, xH2O, xO2, xN2)
if …………’ refer to lecture note about bisection method

end if

Next i
BisectionX = Mi
End Function

Function ff (T, xCO2, xH2O, xO2, xN2)


ff= enthalpy(T, xCO2, xH2O, xO2, xN2) - enthalpy(25, xCO2, xH2O, xO2, xN2) - 827000
End Function

Check your answer with homework.

Question B3
Fill out the spreadsheet B3 using your macro. Plot x versus T

What is the maximum excess air to have flame temperature at 1600oC.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy