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 x2 + 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" add-in 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):