using excel_ nomenclature, macro and tips

2
HOME CONTACT US Download Chapters Cases studies Chapter 1: title Abstract Table of contents Examples Chapter 2: From Fundamental to Properties Abstract Table of contents Examples Chapter 3: title Abstract Table of contents Examples Chapter 4: title Abstract Table of contents Examples Chapter 5: title Abstract Table of contents Examples Chapter 6: title Abstract Table of contents Examples Chapter 7: Three phases reactions in Clauss tail gas treatment (CLAUSPOL) Chapter 10: Complex polar molecular description for high dilution VLE separation (ESTERFIPH) Select thermodynamic models for process simulation A Practical Guide to a Three Steps Methodology Using Excel: Nomenclature, macro and tips Nomenclature In each file associated to all the examples of the book, a simple colour code has been used to help user to differentiate data and results. The files are not blocked, nor password protected, so all cells can be changed. Nevertheless, only some cells are used as input cells to make all calculations. The input cells are written in blue and the calculated cells in black. Other cells are used to conduct iterative procedure to reach a specific result or optimize a specific objective function. In this case, the changing cell is written in red, while the resulting cell is written in brown. In most of the cases, an arrow will be placed in between cells to show the relationship from input to output. Macro Most of calculations in all the examples use macro commands. This technique is helpful and powerful. Reading of the worksheet is clearer and edition is easier. Suppose you want to calculate y=a x 2 + b. The common technique is to define a and b in two cell, say C3=a and D3=b. In other cell you give the value of x, say E5=x, then you can calculate the value of y in cell E6 as =C3*E5*E5+D3. You can do the same creating a Macro (menu Tools>Macro>Visual Basic Editor) and writing a small function in a Module. Our corresponding example will be: Public Function MySample(x As Double, a As Double, b As Double) As Double MySample = a * x * x + b End Function In the worksheet, the calculation can be made, for example in cell E7 writing =MySample(E5,C3,D3). An important feature of macro commands is the fact that you can make a complex calculation using logical tools. A very simple example can be constructed calculating the function sin(x)/x. This equation cannot be calculated numerically in x=0, nevertheless it is well known that the result tends to 1. This property can be used in our function: Public Function Sinx_x(x As Double) As Double If x = 0 Then< Sinx_x = 1# Else Sinx_x = Sin(x) / x End If End Function Tips An important tool used in these examples is the "Goal Seek" function, located in the "Tools" menu. This special feature is used to solve problems of the kind f(x)=b. b is the value of the goal (defined by the coordinate of the cell as B15 for example, written in brown in our nomenclature) and x is the value to be changed (defined by the coordinate of the cell as D21 for example, in red as mentioned above). It is convenient to install the "Solver" addin to your Excel. This sophisticated tool, allows multivariable optimization (or solution) used in fitting or regression for example. Some operations can be made on vectors or matrix and not only one cell. For example the sum of the she product of two arrays can be written easily as: =SUM(B4:B10*C4:C10) . Do not forget to press simultaneously the three keys "Shift" "Control" and "Enter" to specify that this cell is calculated as a vector cell. These samples can be seen in file (xls):

Upload: begenkz

Post on 08-Nov-2015

215 views

Category:

Documents


3 download

DESCRIPTION

VBA Excel

TRANSCRIPT

  • 6/1/2015 UsingExcel:Nomenclature,macroandtips

    http://books.ifpenergiesnouvelles.fr/ebooks/thermodynamics/help/help.html 1/2

    HOME CONTACTUS

    Download

    Chapters

    Casesstudies

    Chapter1:

    titleAbstract Tableofcontents Examples

    Chapter2:

    FromFundamentaltoPropertiesAbstract Tableofcontents Examples

    Chapter3:

    titleAbstract Tableofcontents Examples

    Chapter4:

    titleAbstract Tableofcontents Examples

    Chapter5:

    titleAbstract Tableofcontents Examples

    Chapter6:

    titleAbstract Tableofcontents Examples

    Chapter7:

    ThreephasesreactionsinClausstailgastreatment(CLAUSPOL)

    Chapter10:

    ComplexpolarmoleculardescriptionforhighdilutionVLEseparation(ESTERFIPH)

    SelectthermodynamicmodelsforprocesssimulationAPracticalGuidetoaThreeStepsMethodology

    UsingExcel:Nomenclature,macroandtips

    Nomenclature

    Ineachfileassociatedtoalltheexamplesofthebook,asimplecolourcodehasbeenusedtohelpusertodifferentiatedataandresults.Thefilesarenotblocked,norpasswordprotected,soallcellscanbechanged.Nevertheless,onlysomecellsareusedasinputcellstomakeallcalculations.Theinputcellsarewritteninblueandthecalculatedcellsinblack.

    Othercellsareusedtoconductiterativeproceduretoreachaspecificresultoroptimizeaspecificobjectivefunction.Inthiscase,thechangingcell iswritteninred,whiletheresultingcell iswritteninbrown. Inmostof thecases,anarrowwillbeplacedinbetweencellstoshowtherelationshipfrominputtooutput.

    Macro

    Most of calculations in all the examples use macro commands. This technique is helpful and powerful. Reading of the

    worksheetisclearerandeditioniseasier.Supposeyouwanttocalculatey=ax2+b.Thecommontechniqueistodefineaandbintwocell,sayC3=aandD3=b.Inothercellyougivethevalueofx,sayE5=x,thenyoucancalculatethevalueofyincellE6as=C3*E5*E5+D3.

    YoucandothesamecreatingaMacro(menuTools>Macro>VisualBasicEditor)andwritingasmallfunctioninaModule.Ourcorrespondingexamplewillbe:

    PublicFunctionMySample(xAsDouble,aAsDouble,bAsDouble)AsDoubleMySample=a*x*x+b

    EndFunction

    Intheworksheet,thecalculationcanbemade,forexampleincellE7writing

    =MySample(E5,C3,D3).

    An important featureofmacrocommands is the fact thatyoucanmakeacomplexcalculationusing logical tools.Averysimpleexamplecanbeconstructedcalculatingthefunctionsin(x)/x.Thisequationcannotbecalculatednumericallyinx=0,neverthelessitiswellknownthattheresulttendsto1.Thispropertycanbeusedinourfunction:

    PublicFunctionSinx_x(xAsDouble)AsDoubleIfx=0Then