One of the most widely used general languages historically is Fortran (section L3.1), and many large models, particularly of special purpose process units such as reactors will be found in this language. We have given a number of examples of algorithms in Fortran.

A very large number of models in the last few years have been written
to run in spreadsheet systems. The spreadsheet is extremely convenient,
as it can be found on every PC and most palmtops. However,
spreadsheets have several very serious disadvantages: **
**

**
**

- It is extremely difficult to document a spreadsheet model
- It is extremely difficult to develop a nontrivial spreadsheet model
- It is almost impossible to test a spreadsheet model
- It is essential impossible to determine what an undocumented spreadsheet model is supposed to do.

As a result of the above, ** manually generated spreadsheets
cannot be regarded as a safe modelling tool!**
The most important property which a model must have is that it should
be ** UNDERSTANDABLE. ** This is much more important
than that it should be correct!

- A model which is correct but incomprehensible may be useful to the person who created it if used exactly as originally intended, but cannot safely be modified even by its original author.It is thus almost useless.
- A model which is incorrect and incomprehensible can never be reliably corrected. It is completely useless.

- Named variables which represent the unknowns of the problem
- A means of describing the equations which constitute the model

- Named parameters which are have known numerical values, but which the modeller either prefers to denote by a symbol to make the model easier to understand, or which it may be wished to change between different runs of the model.

The model itself should be easy to read and self explanatory. In addition, a modelling system may usefully provide additional and/or summarised information information about the model.

A very similar format is used to model both steady state systems, represented by algebraic equations, and dynamic systems represented by differential-algebraic equations. The discussion below pertains specifically to algebraic equations.

The ability to give user specified names to variables is a key feature of any modelling language, and the choice of `meaningful' names is an important factor in making a model comprehensible.

For example, a very simple model is to be used to calculate the mass density in kg/m³ of an ideal gas at a given Kelvin temperature and pressure in atmospheres. We are also given the molecular weight of the gas. We decide that we need variables to represent the specific molar volume and mass and molar densities. Although the pressure is given, and is not an unknown or variable (it is a parameter, see below) the Gas Law requires pressure in pascals which the model will require to calculate, so we require a variable for this pressure, giving 4 variables in all. The model instructions are then:

vmolar, romolar, romass, PNote the use of both standard symbols for standard quantities, e.g.

MW = 16 T = 273 Patm = 1.0 R = 8.314Note the appearance of R, the gas constant in this section. strictly, R is a true constant, having a fixed value, but most modelling languages do not distinguish these from parameters.

The modelling languages requires initial values for parameters, but these can be changed once the model has been generated. Do not however change the values of constants like R!

The simplest version of the model generator requires that all equations
be written as formulas, and that every unknown (variable) appears once and
only once on the LHS of a formula.
This approach is discussed in the
general introduction to algebraic equations (section 3.1).
** The equations have to be ordered ** as
described in section 3.2, so that no variable appears on the RHS of the an equals sign until after it
has appeared on the LHS and so been given a value.

It will not always be possible to do this; in these cases a trial-and-error or iterative solution will be required, as described later.

The equations section for this model is as follows:

vmolar = R*T/P romolar = 1/ vmolar romass = romolar*MW/1000 P = Patm * 101300

This is indicated by typing
the word `none` in the **Tear variable ** box.
Ignore the ** Bounds ** boxes meantime as these are only
required for iterative solutions.

Note that all names used in the model must be a combination of letters and
number ** only **, and must start with a letter. Note that upper and lower case
letters
are **not ** the same.

If you want to put these values into a report, you can copy and paste them from this window.

Consider first a trivial model described by the single equation:

The user has to estimate and specify bounds on the solution, here set
to 0.0001 (why not zero?) and 10. Click the **Solve** button and you
will see the path followed to the solution in the lower box and also plotted
as points on the right.

Most real problems involve many equations, most of which, unlike the ideal gas example above, cannot be solved without iteration. But as described in Section 3.2 many problems can be manipulated so that iteration on only one of the variables is required. (However, there are still problems which would require trial-and-error solution on more than one variable; other methods have to be used for these.)

If you return to the ordered
equation solver and clich the **Example Model 2** button
you will get a model consisting of the equations:

As described in Section 3.2 all but one of the equations must be written as formulas, each with a different variable on the LHS. The final consists of an expression whose value is to be reduced to zero by the solution procedure, This must be written in the form:

Func = expressionThe variable which does

Click the ** Solve ** button and the popup window will display values
of all the variables and also the function (the expression to be reduced to zero)
as the solution proceeds. Scroll down to be bottom to see the final, and
so most accurate, solution values.

Course Organiser Last Modified 2/9/00