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:
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!
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.
Refer to the example here.
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. P for pressure, and mnemonic names for other quantities.
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 not appear on the LHS of an equals sign is the tear variable whose value has to be determined by the solver. As with the single equation solver, you must estimate and specify bounds on its value. This information is provided by entries in the Tear variable and bounds section of the model.
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.
Return to Modelling LabCourse Organiser Last Modified 2/9/00