Copyright © IFAC Computer Aided Design in
Control System s. Swansea. UK. 1991
SYMBOLIC DETERMINATION OF
PARAMETER SENSITIVITIES AND
ADJOINT DIFFERENTIAL EQUATIONS: A
FORTRAN SOURCE CODE GENERATOR
FOR THEIR NUMERICAL INTEGRATION
K. Thomaseth
CNR Institute/or System Dynamics and Bioengineering (LADSEB).
Corso Stati Uniti 4. Padua. ltaly
Abstract . This paper describes a software for the automated generation of FORTRAN source code sub-
routines for the numerical integration of non-linear differential equations describing dynamical systems.
The use of directed graphs for representing the systems greatly simplifies the definition of models and
allows an efficient use of symbolic differentiation rules for generating the source code for: i) the sensi-
tivity equati ons for the state / output trajectories with respect to model parameters; ii) the differential
equati ons for computing the adjoint variables of optimal control problems . Possible applications of
this software include model building, sensitivity analysis, identification, optimal experiment design and
numerical solution of optimal control problems.
Keywords. Model building; symbolic differentiation; sensitivity equations; optimal control; adjoint equa-
tions
INTRODUCTION
One of the most tedi ous and time consuming tasks in mod-
eling, identification, and optimal control studies involving
systems with nonlinear dynamics is represented by the sym-
bolic determination of derivatives for writing and coding
sensitivity or adjoint equations . Sensitivities are used in
applications such as: simulation studies , parameter estima-
tion, parameter optimization and optimal experiment de-
sign (Bard, 1974; Frank , 1978 ; Goodwin and Payne , 1977).
The time courses of the sensitivities of the state / output
traj ect ories with respect to parameters are very often com-
puted numerically by perturbing each parameter of int e rest
in turn . However, num erical diffe rentiati on is less accurate ,
when compared to the integration of the analytical sensitiv-
ity e quations , due to the computation of finite differences
between the state trajectories corresponding to the nominal
and to the perturbed parameter values . Furthermore , since
parameter variations must be ke pt small but significant, an
accurate choice of the steplengths of the perturbati ons for
each individual parameter is requir ed.
As far as the adjoint variables in o ptimal co ntrol problems
are concerned , thes e represent the sensitivities of the cost
function with res pe ct to changes in th e state variables, and
their numerical estimati on by means of finite differences may
become a time consuming task unless they have to be com-
puted only in a few time instants .
The analytic evaluati on of derivatives, necessary to write
the sensitivities or adjoint equati ons, can be aided by avail-
able software such as MACSYMA , MATHEMATICA or oth-
ers , which perform symb olic differentiation. However, the
straightforward approa ch of determining , symbolically, par-
tial derivatives of th e differential equati ons describing the
191
models may become a burdensome task for medium to large
scale systems, even with these soft wares.
In this paper a software developed on a Macintosh computer
using LPA MacPROLOG is presented . It automatically gen-
erates FORTRAN source code subroutines for the numeri cal
integration of non -linear differential equati ons together with
sensitivities and adjoint equations . The definition of model
structures is simplified by a system description based on
directed graphs , where the nodes corresp ond to the state
variables , and the links between the nodes describe th e in-
teracti ons between state variables and their time derivatives.
The software makes ext ensive use of a routine that dete r-
mines the symb olic derivatives of functions, which are nec-
essary for writing sensitivity and adjoint equations . Sym-
bolic differentiation is easy to perform in Prolog, and can
be found as an exampl e of application in many text-b oo ks ,
since the definition of the set of Prolog rules are straightfor-
ward translations of the standard mathematical differentia-
tion rules. In this software the soluti on proposed by Coelho,
Cotta and Pereira (1980) has been ad opted, and modified
to include the chain rule and the possibility of using user
defined functions (see below).
In the following, the classes of problems, for which this soft-
ware has been designed, will be presented first. Then , the
structure of the software will be described, in particular : i)
the way model structures are defined by means of direct ed
graphs ; ii) the functi ons, variables and other sy mb oli c names
used for building the mathematical expressions of the model
equati ons; iii) a brief description of th e main program steps
involved in the generati on of the final sour ce code. Lastly, an
example will be given with application to sensitivity e qua -
ti ons and to an optimal control problem .