Section L2.3: A Simple Dynamic Modelling Language

This section describes a simple language for describing models of dynamic systems. It is a text based language, and a WWW browser input form is available to help with model creation.

A model described in the language may be turned into Lotus-123 compatible spreadsheet code, saved and run using essentially any spreadsheet system, including Excel and the Psion spreadsheet.

The language allows the creation of differential-algebraic equation (DAE) models, although the solution facilities for algebraic equations in spreadsheets are somewhat limited.

The use of the language will be described using a simple example.

Example

A system is described by the following set of DAEs.

dx/dt = (z-x) / T1
dy/dt = (x-y) / T2
z = - A y

The initial conditions are: x = y = 0 at t=0

In the language, the equations are described as follows.


model test
! Simple example dynamic model

parameter
! These are quantities which are known, but which
! the user may wish to change to see their effect
 A=1 ;  t1=1
 t2 = 2 
! They will normally be given initial values
end parameter

variable
! These are the variables or unknowns of the problem
 x1 = 0 ! They may be given initial values
 x,  y  ! or not if preferred
end variable

Equation
! These are the equations

 y =  x*x ! This is an algebraic equation

! The  are differential equations...
 .x1 = (-A*y-x1)/T1
 .x = (x1-x)/T2
end equation

initial
! This is another way of giving a variable an initial value
 x=0
end initial

schedule
! This section defines how the model will be run
 deltat=0.5 ! Timestep
 steps=50   ! number of timesteps
end 

end model
It can be seen that the model consists of five sections, each introduced by a keyword, and terminated by the word end.

The model instructions are written in normal `computer notation'. There can either be one per line, or multiple instructions on a line, separated by either `;' or `,'. Multiline instructions are not allowed.

Any line beginning with a `!' is a comment and is ignored.

Each of the sections will be described briefly.

Parameter Section


parameter
! These are quantities which are known, but which
! the user may wish to change to see their effect
 A=1 ;  t1=1
 t2 = 2 
! They will normally be given initial values
end parameter


`Parameters' as distinct from `unknowns' in a mathematical problem are quantities which the user knows, but which might be changed at some point to see their effect. It is convenient to give them symbols rather than simply numbers.

A parameter may often be a physical property, e.g. a heat capacity, which can appear several times in a set of equations. If the parameter is defined in one place, then making one change will result in the new parameter value being used throughout the model.

This section of the model enables parameters to be defined and given values if required. If no values are given the parameter defaults to zero. New values can be given when the spreadsheet has been generated.

Variable Section

variable
! These are the variables or unknowns of the problem
 x1 = 0 ! They may be given initial values
 x,  y  ! or not if preferred
end variable
The variables are the unknowns in the model. As discussed elsewhere, there are two sorts of variables in DAEs, those which may appear as derivatives in the differential equations, and the `algebraic' variables which do not. This distinction is not made in this section, which serves mainly to define the names to be used for variables.

Variables may be given initial values in this section, as illustrated. These are relevant only for ODE variables, and will be ignored for algebraic variables. Initial conditions may also be specified in a separate section of the model.

Equation Section

Equation
! These are the equations

 y =  x*x ! This is an algebraic equation

! These are differential equations...
 .x1 = (-A*y-x1)/T1
 .x = (x1-x)/T2
end equation
This is the main part of the model and contains the differential and algebraic equations which describe the model. Note the following: All normal algebraic operators and functions may be used in equations.

Initial Section

initial
! This is another way of giving a variable an initial value
 x=0
end initial
This section provides another place where initial values may be given for variables. If no initial values is set for a variable which requires it, then it defaults to zero.

Schedule Section

schedule
! This section defines how the model will be run
 deltat=0.5 ! Timestep
 steps=50   ! number of timesteps
end 
This section describes how the model is to be run. At present this may specify any two of the three quantities:

General

The model is introduced by the keyword model and terminated by the words end model. all keywords must appear on separate lines.

There may be more than one of each of the sections, e.g. a variable section, an equation section, another variable section and another equation section. However, all variables must appear in a variable section before they are used in an equation.

Only one schedule section is allowed.


Return to Modelling Lab

Course Organiser
Last Modified 2/9/00