93% found this document useful (15 votes)
4K views550 pages

Advanced Control Using MATLAB

Stabilising the unstabilisable by Prof. David L. Wilson of Auckland University of Technology.

Uploaded by

Stuff84
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
93% found this document useful (15 votes)
4K views550 pages

Advanced Control Using MATLAB

Stabilising the unstabilisable by Prof. David L. Wilson of Auckland University of Technology.

Uploaded by

Stuff84
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 550

Advanced Control using

MATLAB
or Stabilising the
unstabilisable
David I. Wilson
Auckland University of Technology
New Zealand
April 12, 2013
Copyright 2013 David I. Wilson
Auckland University of Technology
New Zealand
Creation date: April, 2013.
All rights reserved. No part of this work may be reproduced, stored in a retrieval system, or
transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or
otherwise, without prior permission.
Contents
1 Introduction 1
1.1 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Matlab for computer aided control design . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2.1 Alternative computer design aids . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Economics of control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Laboratory equipment for control tests . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.4.1 Plants with one input and one output . . . . . . . . . . . . . . . . . . . . . . 6
1.4.2 Multi-input and multi-output plants . . . . . . . . . . . . . . . . . . . . . . . 8
1.5 Slowing down Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2 From differential to difference equations 13
2.1 Computer in the loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.1.1 Sampling an analogue signal . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.1.2 Selecting a sample rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.1.3 The sampling theorem and aliases . . . . . . . . . . . . . . . . . . . . . . . . 16
2.1.4 Discrete frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.2 Finite difference models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.2.1 Difference equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.3 The z transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.3.1 z-transforms of common functions . . . . . . . . . . . . . . . . . . . . . . . . 23
2.4 Inversion of z-transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.4.1 Inverting z-transforms with symbolically . . . . . . . . . . . . . . . . . . . . 25
2.4.2 The partial fraction method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.4.3 Long division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.4.4 Computational approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.4.5 Numerically inverting the Laplace transform . . . . . . . . . . . . . . . . . . 31
2.5 Discretising with a sample and hold . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.5.1 Converting Laplace transforms to z-transforms . . . . . . . . . . . . . . . . 37
2.5.2 The bilinear transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.6 Discrete root locus diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
2.7 Multivariable control and state space analysis . . . . . . . . . . . . . . . . . . . . . . 43
2.7.1 States and state space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.7.2 Converting differential equations to state-space form . . . . . . . . . . . . . 47
2.7.3 Interconverting between state space and transfer functions . . . . . . . . . . 50
2.7.4 Similarity transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
2.7.5 Interconverting between transfer functions forms . . . . . . . . . . . . . . . 55
2.7.6 The steady state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
2.8 Solving the vector differential equation . . . . . . . . . . . . . . . . . . . . . . . . . 58
2.8.1 Numerically computing the discrete transformation . . . . . . . . . . . . . . 61
2.8.2 Using MATLAB to discretise systems . . . . . . . . . . . . . . . . . . . . . . . 63
2.8.3 Time delay in state space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
2.9 Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
iii
iv CONTENTS
2.9.1 Stability in the continuous domain . . . . . . . . . . . . . . . . . . . . . . . . 70
2.9.2 Stability of the closed loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
2.9.3 Stability of discrete time systems . . . . . . . . . . . . . . . . . . . . . . . . . 73
2.9.4 Stability of nonlinear differential equations . . . . . . . . . . . . . . . . . . . 74
2.9.5 Expressing matrix equations succinctly using Kronecker products . . . . . . 80
2.9.6 Summary of stability analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
2.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
3 Modelling dynamic systems with differential equations 85
3.1 Dynamic system models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
3.1.1 Steady state and dynamic models . . . . . . . . . . . . . . . . . . . . . . . . 86
3.2 A collection of illustrative models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
3.2.1 Simple models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
3.3 Chemical process models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
3.3.1 A continuously-stirred tank reactor . . . . . . . . . . . . . . . . . . . . . . . 92
3.3.2 A forced circulation evaporator . . . . . . . . . . . . . . . . . . . . . . . . . . 94
3.3.3 A binary distillation column model . . . . . . . . . . . . . . . . . . . . . . . 95
3.3.4 Interaction and the Relative Gain Array . . . . . . . . . . . . . . . . . . . . . 103
3.4 Regressing experimental data by curve tting . . . . . . . . . . . . . . . . . . . . . . 107
3.4.1 Polynomial regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
3.4.2 Nonlinear least-squares model identication . . . . . . . . . . . . . . . . . . 112
3.4.3 Parameter condence intervals . . . . . . . . . . . . . . . . . . . . . . . . . . 116
3.5 Numerical tools for modelling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
3.5.1 Differential/Algebraic equation systems and algebraic loops . . . . . . . . . 123
3.6 Linearisation of nonlinear dynamic equations . . . . . . . . . . . . . . . . . . . . . . 125
3.6.1 Linearising a nonlinear tank model . . . . . . . . . . . . . . . . . . . . . . . 127
3.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
4 The PID controller 131
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
4.1.1 P, PI or PID control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
4.2 The industrial PID algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
4.2.1 Implementing the derivative component . . . . . . . . . . . . . . . . . . . . 133
4.2.2 Variations of the PID algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . 134
4.2.3 Integral only control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
4.3 Simulating a PID process in SIMULINK . . . . . . . . . . . . . . . . . . . . . . . . . . 135
4.4 Extensions to the PID algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
4.4.1 Avoiding derivative kick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
4.4.2 Input saturation and integral windup . . . . . . . . . . . . . . . . . . . . . . 140
4.5 Discrete PID controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
4.5.1 Discretising continuous PID controllers . . . . . . . . . . . . . . . . . . . . . 144
4.5.2 Simulating a PID controlled response in Matlab . . . . . . . . . . . . . . . . 146
4.5.3 Controller performance as a function of sample time . . . . . . . . . . . . . 148
4.6 PID tuning methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
4.6.1 Open loop tuning methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
4.6.2 Closed loop tuning methods . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
4.6.3 Closed loop single-test tuning methods . . . . . . . . . . . . . . . . . . . . . 159
4.6.4 Summary on closed loop tuning schemes . . . . . . . . . . . . . . . . . . . . 166
4.7 Automated tuning by relay feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
4.7.1 Describing functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
4.7.2 An example of relay tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
4.7.3 Self-tuning with noise disturbances . . . . . . . . . . . . . . . . . . . . . . . 173
4.7.4 Modications to the relay feedback estimation algorithm . . . . . . . . . . . 176
4.8 Drawbacks with PID controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
CONTENTS v
4.8.1 Inverse response processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
4.8.2 Approximating inverse-response systems with additional deadtime . . . . 183
4.9 Dead time compensation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
4.10 Tuning and sensitivity of control loops . . . . . . . . . . . . . . . . . . . . . . . . . . 187
4.11 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
5 Digital ltering and smoothing 193
5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
5.1.1 The nature of industrial noise . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
5.1.2 Differentiating without smoothing . . . . . . . . . . . . . . . . . . . . . . . . 196
5.2 Smoothing measured data using analogue lters . . . . . . . . . . . . . . . . . . . . 197
5.2.1 A smoothing application to nd the peaks and troughs . . . . . . . . . . . . 197
5.2.2 Filter types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
5.2.3 Classical analogue lter families . . . . . . . . . . . . . . . . . . . . . . . . . 201
5.3 Discrete lters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
5.3.1 A low-pass ltering application . . . . . . . . . . . . . . . . . . . . . . . . . . 209
5.3.2 Digital lter approximations . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
5.3.3 Efcient hardware implementation of discrete lters . . . . . . . . . . . . . 214
5.3.4 Numerical and quantisation effects for high-order lters . . . . . . . . . . . 217
5.4 The Fourier transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
5.4.1 Fourier transform denitions . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
5.4.2 Orthogonality and frequency spotting . . . . . . . . . . . . . . . . . . . . . . 224
5.4.3 Using MATLABs FFT function . . . . . . . . . . . . . . . . . . . . . . . . . . 225
5.4.4 Periodogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
5.4.5 Fourier smoothing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
5.5 Numerically differentiating industrial data . . . . . . . . . . . . . . . . . . . . . . . 230
5.5.1 Establishing feedrates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
5.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
6 Identication of process models 235
6.1 The importance of system identication . . . . . . . . . . . . . . . . . . . . . . . . . 235
6.1.1 Basic denitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
6.1.2 Black, white and grey box models . . . . . . . . . . . . . . . . . . . . . . . . 237
6.1.3 Techniques for identication . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
6.2 Graphical and non-parametric model identication . . . . . . . . . . . . . . . . . . 239
6.2.1 Time domain identication using graphical techniques . . . . . . . . . . . . 239
6.2.2 Experimental frequency response analysis . . . . . . . . . . . . . . . . . . . 246
6.2.3 An alternative empirical transfer function estimate . . . . . . . . . . . . . . 253
6.3 Continuous model identication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
6.3.1 Fitting transfer functions using nonlinear least-squares . . . . . . . . . . . . 254
6.3.2 Identication using derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . 256
6.3.3 Practical continuous model identication . . . . . . . . . . . . . . . . . . . . 258
6.4 Popular discrete-time linear models . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
6.4.1 Extending the linear model . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
6.4.2 Output error model structures . . . . . . . . . . . . . . . . . . . . . . . . . . 264
6.4.3 General input/output models . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
6.5 Regressing discrete model parameters . . . . . . . . . . . . . . . . . . . . . . . . . . 266
6.5.1 Simple ofine system identication routines . . . . . . . . . . . . . . . . . . 268
6.5.2 Bias in the parameter estimates . . . . . . . . . . . . . . . . . . . . . . . . . . 269
6.5.3 Using the System Identication toolbox . . . . . . . . . . . . . . . . . . . . . 270
6.5.4 Fitting parameters to state space models . . . . . . . . . . . . . . . . . . . . 274
6.6 Model structure determination and validation . . . . . . . . . . . . . . . . . . . . . 276
6.6.1 Estimating model order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
6.6.2 Robust model tting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
vi CONTENTS
6.6.3 Common nonlinear model structures . . . . . . . . . . . . . . . . . . . . . . 280
6.7 Online model identication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
6.7.1 Recursive least squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
6.7.2 Recursive least-squares in MATLAB . . . . . . . . . . . . . . . . . . . . . . . 286
6.7.3 Tracking the precision of the estimates . . . . . . . . . . . . . . . . . . . . . . 290
6.8 The forgetting factor and covariance windup . . . . . . . . . . . . . . . . . . . . . . 292
6.8.1 The inuence of the forgetting factor . . . . . . . . . . . . . . . . . . . . . . . 294
6.8.2 Covariance wind-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
6.9 Identication by parameter optimisation . . . . . . . . . . . . . . . . . . . . . . . . . 296
6.10 Online estimating of noise models . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
6.10.1 A recursive extended least-squares example . . . . . . . . . . . . . . . . . . 302
6.10.2 Recursive identication using the SI toolbox . . . . . . . . . . . . . . . . . . 305
6.10.3 Simplied RLS algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
6.11 Closed loop identication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
6.11.1 Closed loop RLS in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
6.12 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
7 Adaptive Control 317
7.1 Why adapt? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
7.1.1 The adaption scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
7.1.2 Classication of adaptive controllers . . . . . . . . . . . . . . . . . . . . . . . 319
7.2 Gain scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
7.3 The importance of identication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
7.3.1 Polynomial manipulations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
7.4 Self tuning regulators (STRs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
7.4.1 Simple minimum variance control . . . . . . . . . . . . . . . . . . . . . . . . 323
7.5 Adaptive pole-placement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
7.5.1 The Diophantine equation and the closed loop . . . . . . . . . . . . . . . . . 326
7.5.2 Solving the Diophantine equation in Matlab . . . . . . . . . . . . . . . . . . 327
7.5.3 Adaptive pole-placement with identication . . . . . . . . . . . . . . . . . . 330
7.6 Practical adaptive pole-placement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
7.6.1 Dealing with non-minimum phase systems . . . . . . . . . . . . . . . . . . . 335
7.6.2 Separating stable and unstable factors . . . . . . . . . . . . . . . . . . . . . . 338
7.6.3 Experimental adaptive pole-placement . . . . . . . . . . . . . . . . . . . . . 340
7.6.4 Minimum variance control with dead time . . . . . . . . . . . . . . . . . . . 341
7.7 Summary of adaptive control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
8 Multivariable controller design 351
8.1 Controllability and observability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
8.1.1 Controllability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
8.1.2 Observability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
8.1.3 Computing controllability and observability . . . . . . . . . . . . . . . . . . 355
8.1.4 State reconstruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
8.2 State space pole-placement controller design . . . . . . . . . . . . . . . . . . . . . . 359
8.2.1 Poles and where to place them . . . . . . . . . . . . . . . . . . . . . . . . . . 362
8.2.2 Deadbeat control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
8.3 Estimating the unmeasured states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
8.4 Combining estimation and state feedback . . . . . . . . . . . . . . . . . . . . . . . . 367
8.5 Generic model control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
8.5.1 The tuning parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
8.5.2 GMC control of a linear model . . . . . . . . . . . . . . . . . . . . . . . . . . 373
8.5.3 GMC applied to a nonlinear plant . . . . . . . . . . . . . . . . . . . . . . . . 375
8.6 Exact feedback linearisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
8.6.1 The nonlinear system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
CONTENTS vii
8.6.2 The input/output feedback linearisation control law . . . . . . . . . . . . . 380
8.6.3 Exact feedback example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
8.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
9 Classical optimal control 387
9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
9.2 Parametric optimisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
9.2.1 Choosing a performance indicator . . . . . . . . . . . . . . . . . . . . . . . . 388
9.2.2 Optimal tuning of a PID regulator . . . . . . . . . . . . . . . . . . . . . . . . 389
9.2.3 Using SIMULINK inside an optimiser . . . . . . . . . . . . . . . . . . . . . . . 395
9.2.4 An optimal batch reactor temperature policy . . . . . . . . . . . . . . . . . . 396
9.3 The general optimal control problem . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
9.3.1 The optimal control formulation . . . . . . . . . . . . . . . . . . . . . . . . . 399
9.3.2 The two-point boundary problem . . . . . . . . . . . . . . . . . . . . . . . . 401
9.3.3 Optimal control examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
9.3.4 Problems with a specied target set . . . . . . . . . . . . . . . . . . . . . . . 406
9.4 Linear quadratic control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
9.4.1 Continuous linear quadratic regulators . . . . . . . . . . . . . . . . . . . . . 409
9.4.2 Analytical solution to the LQR problem . . . . . . . . . . . . . . . . . . . . . 411
9.4.3 The steady-state solution to the matrix Riccati equation . . . . . . . . . . . . 415
9.4.4 The discrete LQR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
9.4.5 A numerical validation of the optimality of LQR . . . . . . . . . . . . . . . . 423
9.4.6 An LQR with integral states . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
9.5 Estimation of state variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
9.5.1 Random processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
9.5.2 Combining deterministic and stochastic processes . . . . . . . . . . . . . . . 437
9.5.3 The Kalman lter estimation scheme . . . . . . . . . . . . . . . . . . . . . . . 438
9.5.4 The steady-state form of the Kalman lter . . . . . . . . . . . . . . . . . . . . 442
9.5.5 Current and future prediction forms . . . . . . . . . . . . . . . . . . . . . . . 443
9.5.6 An application of the Kalman lter . . . . . . . . . . . . . . . . . . . . . . . . 447
9.5.7 The role of the Q and R noise covariance matrices in the state estimator . . 448
9.5.8 Extensions to the basic Kalman lter algorithm . . . . . . . . . . . . . . . . . 452
9.5.9 The Extended Kalman Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
9.5.10 Combining state estimation and state feedback . . . . . . . . . . . . . . . . . 457
9.5.11 Optimal control using only measured outputs . . . . . . . . . . . . . . . . . 457
9.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
10 Predictive control 461
10.1 Model predictive control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461
10.1.1 Constrained predictive control . . . . . . . . . . . . . . . . . . . . . . . . . . 464
10.1.2 Dynamic matrix control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
10.2 A Model Predictive Control Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
10.2.1 A model predictive control GUI . . . . . . . . . . . . . . . . . . . . . . . . . 474
10.2.2 MPC toolbox in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
10.2.3 Using the MPC toolbox in SIMULINK . . . . . . . . . . . . . . . . . . . . . . 476
10.2.4 Further readings on MPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
10.3 Optimal control using linear programming . . . . . . . . . . . . . . . . . . . . . . . 478
10.3.1 Development of the LP problem . . . . . . . . . . . . . . . . . . . . . . . . . 479
viii CONTENTS
11 Expert systems and neural networks 487
11.1 Expert systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
11.1.1 Where are they used? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
11.1.2 Features of an expert system . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
11.1.3 The user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
11.1.4 Expert systems used in process control . . . . . . . . . . . . . . . . . . . . . 490
11.2 Neural networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
11.2.1 The architecture of the neural network . . . . . . . . . . . . . . . . . . . . . . 495
11.2.2 Curve tting using neural networks . . . . . . . . . . . . . . . . . . . . . . . 499
11.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
A List of symbols 505
B Useful utility functions in Matlab 507
C Transform pairs 509
D A comparison of Maple and MuPad 511
D.1 Partial fractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511
D.2 Integral transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511
D.3 Differential equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
D.4 Vectors and matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513
E Useful test models 515
E.1 A forced circulation evaporator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515
E.2 Aircraft model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
List of Figures
1.1 Traditional vs. Advanced control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 Economic improvements of better control . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3 Blackbox conguration. The manual switch marked will toggle between either 7
or 9 low-pass lters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.4 The Black-box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.5 Balance arm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.6 The apper wiring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.7 Flapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.8 Helicopter plant with 2 degrees of freedom. See also Fig. 1.9(a). . . . . . . . . . . . 10
1.9 Helicopter control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.10 Helicopter ying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.11 Real-time Simulink simulations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.1 The computer in the control loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.2 3 bit sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3 A time series with unknown frequency components . . . . . . . . . . . . . . . . . . 18
2.4 The frequency component of a sampled signal . . . . . . . . . . . . . . . . . . . . . 18
2.5 Frequency aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.6 The Scarlet Letter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.7 H enons attractor in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.8 H enons attractor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.9 Inverting z-transforms using dimpulse . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.10 Numerically inverting the Laplace transform using the Bromwich integral . . . . . 33
2.11 Numerically inverting the Laplace transform . . . . . . . . . . . . . . . . . . . . . . 33
2.12 Numerically inverting Laplace transforms . . . . . . . . . . . . . . . . . . . . . . . . 34
2.13 Ideal sampler and zeroth-order hold . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.14 Zeroth-order hold effects on the discrete Bode diagram . . . . . . . . . . . . . . . . 41
2.15 Bode plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
2.16 The discrete root locus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.17 Various discrete closed loop responses . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.18 A binary distillation column with multiple inputs and multiple outputs . . . . . . 45
2.19 A block diagram of a state-space dynamic system, (a) continuous system: x =
Ax +Bu, and (b) discrete system: x
k+1
= x
k
+u
k
. (See also Fig. 2.20.) . . . . 47
2.20 A complete block diagram of a state-space dynamic system with output and direct
measurement feed-through, Eqn. 2.41. . . . . . . . . . . . . . . . . . . . . . . . . . . 48
2.21 Unsteady and steady states for level systems . . . . . . . . . . . . . . . . . . . . . . 57
2.22 Submarine step response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
2.23 Issues in assessing system stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
2.24 Nyquist diagramof Eqn. 2.94 in (a) three dimensions and (b) as typically presented
in two dimensions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
2.25 Liapunov (18571918) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
2.26 Regions of stability for the poles of continuous (left) and discrete (right) systems . 82
ix
x LIST OF FIGURES
3.1 A stable and unstable pendulum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
3.2 Simple buffer tank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
3.3 The UK growth based on the GDP . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
3.4 A CSTR reactor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
3.5 A forced circulation evaporator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
3.6 Schematic of a distillation column . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
3.7 Wood-Berry step response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
3.8 Wood-Berry column in SIMULINK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
3.9 Distillation tower . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
3.10 Sparsity of the distillation column model . . . . . . . . . . . . . . . . . . . . . . . . 101
3.11 Open loop distillation column control . . . . . . . . . . . . . . . . . . . . . . . . . . 102
3.12 Distillation column control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
3.13 Distillation column control (in detail) . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
3.14 Distillation interactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
3.15 Dynamic RGA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
3.16 Dynamic RGA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
3.17 Density of Air . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
3.18 Fitting a high-order polynomial to some physical data . . . . . . . . . . . . . . . . . 111
3.19 A bio-chemical reaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
3.20 Model of compressed water . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
3.21 Experimental pressure-rate data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
3.22 Parameter condence regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
3.23 Linear and nonlinear trajectories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
3.24 Linearising a nonlinear tank model . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
4.1 Comparing PI and integral-only control for the real-time control of a noisy apper
plant with sampling time T = 0.08. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
4.2 PID simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
4.3 PID internals in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
4.4 Block diagram of PID controllers as implemented in SIMULINK (left) and classical
text books (right). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
4.5 Realisable PID controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
4.6 PID controller in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
4.7 PID controller with anti-derivative kick. . . . . . . . . . . . . . . . . . . . . . . . . . 139
4.8 Avoiding derivative kick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
4.9 Illustrating the improvement of anti-derivative kick schemes for PID controllers
when applied to the experimental electromagnetic balance. . . . . . . . . . . . . . . 140
4.10 Derivative control and noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
4.11 Anti-windup comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
4.12 Discrete PID controller in SIMULINK . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
4.13 Headbox control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
4.14 Headbox controlled response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
4.15 A PID controlled process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
4.16 Sample time and discrete PID control . . . . . . . . . . . . . . . . . . . . . . . . . . 149
4.17 The parameters T and Lto be graphically estimated for the openloop tuning method
relations given in Table 4.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
4.18 Cohen-Coon model tting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
4.19 Cohen-Coon tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
4.20 PID tuning using a GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
4.21 Solving for the ultimate frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
4.22 Ziegler-Nichols tuned responses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
4.23 Typical response of a stable system to a P-controller. . . . . . . . . . . . . . . . . . . 160
4.24 A Yuwana-Seborg closed loop step test . . . . . . . . . . . . . . . . . . . . . . . . . . 163
4.25 Closed loop responses using the YS scheme . . . . . . . . . . . . . . . . . . . . . . . 164
LIST OF FIGURES xi
4.26 A self-tuning PID controlled process . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
4.27 A process under relay tuning with the PID regulator disabled. . . . . . . . . . . . . 167
4.28 An unknown plant under relay feedback exhibits an oscillation . . . . . . . . . . . 169
4.29 Nyquist & Bode diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
4.30 PID Relay tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
4.31 Relay tuning with noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
4.32 Relay tuning of the blackbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
4.33 Relay tuning results of the blackbox . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
4.34 A relay with hysteresis width h and output amplitude d. . . . . . . . . . . . . . . . 177
4.35 Relay feedback with hysteresis width h. . . . . . . . . . . . . . . . . . . . . . . . . . 178
4.36 Relay feedback with hysteresis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
4.37 Relay feedback with an integrator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
4.38 2-point Relay identication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
4.39 The J curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
4.40 An inverse response process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
4.41 A NMP plant controlled with a PI controller . . . . . . . . . . . . . . . . . . . . . . 183
4.42 Approximating inverse-response systems with additional deadtime . . . . . . . . . 184
4.43 The Smith predictor structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
4.44 The Smith predictor structure from Fig. 4.43 assuming no model/plant mis-match. 186
4.45 Smith predictor in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
4.46 Dead time compensation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
4.47 Deadtime compensation applied to the blackbox . . . . . . . . . . . . . . . . . . . . 188
4.48 Closed loop with plant G(s) and controller C(s) subjected to disturbances and
measurement noise. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
4.49 Sensitivity transfer functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
4.50 Sensitivity robustness measure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
5.1 A lter as a transfer function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
5.2 A noisy measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
5.3 Noise added to a true, but unknown, signal . . . . . . . . . . . . . . . . . . . . . . . 195
5.4 Derivative action given noisy data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
5.5 Smoothing industrial data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
5.6 Low-pass lter specication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
5.7 Three single low-pass lters cascaded together to make a third-order lter. . . . . . 199
5.8 Amplitude response for ideal, low-pass, high pass and band-pass lters. . . . . . . 200
5.9 Analogue Butterworth lter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
5.10 Analogue Chebyshev lter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
5.11 Butterworth and Chebyshev lters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
5.12 Using a Butterworth lter to smooth noisy data . . . . . . . . . . . . . . . . . . . . . 211
5.13 The frequency response for Butterworth lters . . . . . . . . . . . . . . . . . . . . . 212
5.14 Various Butterworth lters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
5.15 Advantages of frequency pre-warping . . . . . . . . . . . . . . . . . . . . . . . . . . 214
5.16 Hardware difference equation in Direct Form I . . . . . . . . . . . . . . . . . . . . . 215
5.17 An IIR lter with a minimal number of delays, Direct Form II . . . . . . . . . . . . 216
5.18 Cascaded second-order sections to realise a high-order lter. See also Fig. 5.19. . . 217
5.19 A second-order section (SOS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
5.20 Comparing single precision second-order sections with lters in direct form II
transposed form. Note that the direct form II lter is actually unstable when run
in single precision. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
5.21 Approximating square waves with sine waves . . . . . . . . . . . . . . . . . . . . . 223
5.22 The Fourier approximation to a square wave . . . . . . . . . . . . . . . . . . . . . . 223
5.23 Two signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
5.24 Critical radio frequencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
5.25 Power spectrum for a signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
xii LIST OF FIGURES
5.26 Smoothing by Fourier transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
5.27 Differentiating and smoothing noisy measurement . . . . . . . . . . . . . . . . . . . 232
5.28 Filtering industrial data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
6.1 The prediction problem: Given a model and the input, u, can we predict the out-
put, y? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
6.2 A good model, M, duplicates the behaviour of the true plant, S. . . . . . . . . . . . 237
6.3 An experimental setup for input/output identication. We log both the input and
the response data to a computer for further processing. . . . . . . . . . . . . . . . . 238
6.4 Typical open loop step tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
6.5 Areas method for model identication . . . . . . . . . . . . . . . . . . . . . . . . . . 241
6.6 Examples of the Areas method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
6.7 Identication of the Blackbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
6.8 Balance arm step test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
6.9 Random signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
6.10 A 5-element binary shift register to generate a pseudo-random binary sequence. . 245
6.11 Pseudo-random binary sequence generator in SIMULINK . . . . . . . . . . . . . . . 245
6.12 Black box experimental setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
6.13 Black box response analysis using a series of sine waves . . . . . . . . . . . . . . . . 247
6.14 Black box response using an input chirp signal. . . . . . . . . . . . . . . . . . . . . . 249
6.15 Black box frequency response analysis using a chirp signal. . . . . . . . . . . . . . . 249
6.16 Flapper response to a chirp signal. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
6.17 Experimental setup to subject a random input into an unknown plant. The in-
put/output data was collected, processed through Listing 6.2 to give the frequency
response shown in Fig. 6.18. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
6.18 The experimental frequency response compared to the true analytical Bode dia-
gram. See the routine in Listing 6.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
6.19 Black box response given a pseudo-random input sequence. . . . . . . . . . . . . . 252
6.20 Black box frequency response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
6.21 Empirical transfer function estimate . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
6.22 Experimental data from a continuous plant . . . . . . . . . . . . . . . . . . . . . . . 255
6.23 A continuous-time model tted to input/output data . . . . . . . . . . . . . . . . . 256
6.24 Continuous model identication strategy . . . . . . . . . . . . . . . . . . . . . . . . 257
6.25 Continuous model identication simulation . . . . . . . . . . . . . . . . . . . . . . . 259
6.26 Continuous model identication of the blackbox . . . . . . . . . . . . . . . . . . . . 260
6.27 Identication using Laguerre functions . . . . . . . . . . . . . . . . . . . . . . . . . 261
6.28 A signal ow diagram of an auto-regressive model with exogenous input or ARX
model. Compare this structure with the similar output-error model in Fig. 6.30. . . 262
6.29 A signal ow diagram of a ARMAX model. Note that the only difference between
this, and the ARX model in Fig. 6.28, is the inclusion of the C polynomial ltering
the noise term. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
6.30 A signal ow diagram of an output-error model. Compare this structure with the
similar ARX model in Fig. 6.28. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
6.31 A general input/output model structure . . . . . . . . . . . . . . . . . . . . . . . . . 265
6.32 ARX estimation exhibiting bias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
6.33 Ofine system identication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
6.34 Identication of deadtime from the step response . . . . . . . . . . . . . . . . . . . 278
6.35 Deadtime estimation at fast sampling . . . . . . . . . . . . . . . . . . . . . . . . . . 278
6.36 Deadtime estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
6.37 Blackbox step model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
6.38 Hammerstein and Wiener model structures . . . . . . . . . . . . . . . . . . . . . . . 281
6.39 Ideal RLS parameter estimation. (See also Fig. 6.41(a).) . . . . . . . . . . . . . . . . 286
6.40 Recursive least squares estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
6.41 RLS under SIMULINK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
LIST OF FIGURES xiii
6.42 RLS under SIMULINK (version 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
6.43 Estimation of a two parameter plant . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
6.44 Condence limits for estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
6.45 RLS and an abrupt plant change . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
6.46 The memory when using a forgetting factor . . . . . . . . . . . . . . . . . . . . . . . 293
6.47 Identication using various forgetting factors . . . . . . . . . . . . . . . . . . . . . . 294
6.48 Covariance wind-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
6.49 The MIT rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
6.50 Optimising the adaptation gain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
6.51 Addition of coloured noise to a dynamic process. See also Fig. 6.31. . . . . . . . . . 301
6.52 RLS with coloured noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
6.53 Nonlinear parameter estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
6.54 Recursive extended least-squares estimation . . . . . . . . . . . . . . . . . . . . . . 305
6.55 A simplied recursive least squares algorithm . . . . . . . . . . . . . . . . . . . . . 307
6.56 Furnace input/output data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
6.57 Closed loop estimation using Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . 309
6.58 RLS in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
7.1 The structure of an indirect adaptive controller . . . . . . . . . . . . . . . . . . . . . 319
7.2 Varying process gain of a spherical tank . . . . . . . . . . . . . . . . . . . . . . . . . 320
7.3 Simple minimum variance control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
7.4 Simple minimum variance control (zoomed) . . . . . . . . . . . . . . . . . . . . . . 325
7.5 Adaptive pole-placement control structure . . . . . . . . . . . . . . . . . . . . . . . 325
7.6 Adaptive pole-placement control structure with RLS identication . . . . . . . . . 331
7.7 Control of multiple plants with an adapting controller. We desire the same closed
loop response irrespective of the choice of plant. . . . . . . . . . . . . . . . . . . . . 332
7.8 Three open loop plants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
7.9 Desired closed loop response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
7.10 Adaptive pole-placement with identication . . . . . . . . . . . . . . . . . . . . . . 334
7.11 Comparing the adaptive pole-placement with the reference trajectory . . . . . . . . 335
7.12 Bursting in adaptive control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
7.13 A plant with poorly damped zeros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
7.14 Adaptive pole-placement with an unstable B . . . . . . . . . . . . . . . . . . . . . . 339
7.15 Pole-zero map of an adaptive pole-placement . . . . . . . . . . . . . . . . . . . . . . 340
7.16 Areas of well-damped poles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
7.17 Adaptive pole-placement of the black-box . . . . . . . . . . . . . . . . . . . . . . . . 342
7.18 Adaptive pole-placement of the black-box . . . . . . . . . . . . . . . . . . . . . . . . 343
7.19 A non-minimum phase plant with an unstable zero which causes an inverse step
response. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
7.20 Moving average control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
8.1 Reconstructing states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
8.2 Pole-placement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
8.3 Deadbeat control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
8.4 Simultaneous control and state estimation . . . . . . . . . . . . . . . . . . . . . . . . 368
8.5 Control and estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
8.6 GMC tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
8.7 GMC tuning characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
8.8 Linear GMC response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
8.9 Linear GMC comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
8.10 GMC CSTR control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
8.11 A CSTR phase plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
8.12 The conguration of an input/output feedback linearisation control law . . . . . . 381
8.13 Exact feedback linearisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
xiv LIST OF FIGURES
9.1 IAE areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
9.2 ITAE breakdown . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
9.3 Optimal responses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
9.4 Optimal PID tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
9.5 Optimum PI tuning of the blackbox plant . . . . . . . . . . . . . . . . . . . . . . . . 394
9.6 SIMULINK model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
9.7 Production of a valuable chemical in a batch reactor. . . . . . . . . . . . . . . . . . . 396
9.8 Temperature prole optimisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
9.9 Temperature prole optimisation using 3 temperatures . . . . . . . . . . . . . . . . 398
9.10 Optimum temperature prole comparison for different number of temperatures . 398
9.11 Optimal control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
9.12 Optimal control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
9.13 Optimal control with targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
9.14 Steady-state and time-varying LQR control . . . . . . . . . . . . . . . . . . . . . . . 414
9.15 Steady-state continuous LQR controller . . . . . . . . . . . . . . . . . . . . . . . . . 417
9.16 Comparing discrete and continuous LQR controllers . . . . . . . . . . . . . . . . . . 420
9.17 LQR control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
9.18 Pole-placement and LQR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
9.19 Pole-placement and LQR showing the input . . . . . . . . . . . . . . . . . . . . . . 425
9.20 Trial pole locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
9.21 Trial pole-placement performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426
9.22 State feedback control system with an integral output state . . . . . . . . . . . . . . 428
9.23 State feedback with integral states . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
9.24 Black box servo control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
9.25 A state-based estimation and control scheme . . . . . . . . . . . . . . . . . . . . . . 431
9.26 PDF of a random variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
9.27 Correlated noisy x, y data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
9.28 2D ellipse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
9.29 Kalman lter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
9.30 A block diagram of a steady-state prediction-type Kalman lter applied to a linear
discrete plant. Compare with the alternative form in Fig. 9.31. . . . . . . . . . . . . 444
9.31 A block diagram of a steady-state current estimator-type Kalman lter applied to
a linear discrete plant. Compare with the alternative prediction form in Fig. 9.30. . 445
9.32 Kalman lter demonstration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448
9.33 The performance of a Kalman lter for different q/r ratios . . . . . . . . . . . . . . 451
9.34 A random walk process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
9.35 LQG in SIMULINK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
10.1 Horizons used in model predictive control . . . . . . . . . . . . . . . . . . . . . . . 462
10.2 Predictions of the Reserve Bank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
10.3 Inverse plant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
10.4 Predictive control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466
10.5 Acausal response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467
10.6 Varying the horizons of predictive control . . . . . . . . . . . . . . . . . . . . . . . . 468
10.7 MPC on the blackbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
10.8 Step response coefcients, g
i
, for a stable system. . . . . . . . . . . . . . . . . . . . . 469
10.9 DMC control details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
10.10DMC control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
10.11Adaptive DMC of the blackbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
10.12An MPC graphical user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
10.13Multivariable MPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
10.14SIMULINK and MPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
10.15MPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
10.16LP constraint matrix dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
LIST OF FIGURES xv
10.17LP optimal control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484
10.18LP optimal control with active constraints . . . . . . . . . . . . . . . . . . . . . . . . 485
10.19Non-square LP optimal control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
10.20LP optimal control showing acausal behaviour . . . . . . . . . . . . . . . . . . . . . 486
11.1 Possible neuron activation functions. . . . . . . . . . . . . . . . . . . . . . . . . . . 495
11.2 A single neural processing unit with multiple inputs . . . . . . . . . . . . . . . . . . 496
11.3 Single layer feedforward neural network . . . . . . . . . . . . . . . . . . . . . . . . 497
11.4 A 3 layer fully interconnected feedforward neural network . . . . . . . . . . . . . . 497
11.5 Single layer network with feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
11.6 An unknown input/output function . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
11.7 Fitting a Neural-Network to an unknown input/output function . . . . . . . . . . 501
11.8 Tide predictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502
xvi LIST OF FIGURES
List of Tables
1.1 Computer aids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1 Final and initial value theorems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.2 Inverting a z transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.3 Laplace transform pairs used for testing . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.1 Standard nomenclature used in modelling dynamic systems . . . . . . . . . . . . . 90
3.2 Parameters of the CSTR model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
3.3 The important variables in the forced circulation evaporator . . . . . . . . . . . . . 94
3.4 Compressed water . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
3.5 The parameter values for the CSTR model . . . . . . . . . . . . . . . . . . . . . . . . 122
3.6 The initial state and manipulated variables for the CSTR simulation . . . . . . . . . 123
4.1 Alternative PID tuning parameter conventions . . . . . . . . . . . . . . . . . . . . . 132
4.2 Ziegler-Nichols open-loop PID tuning rules . . . . . . . . . . . . . . . . . . . . . . . 152
4.3 PID controller settings based on IMC for a small selection of common plants where
the control engineer gets to chose a desired closed loop time constant,
c
. . . . . . . 154
4.4 Various alternative Ziegler-Nichols type PID tuning rules as a function of the
ultimate gain, K
u
, and ultimate period, P
u
. . . . . . . . . . . . . . . . . . . . . . . . 155
4.5 Closed-loop single-test PID design rules . . . . . . . . . . . . . . . . . . . . . . . . . 161
4.6 Relay based PID tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
5.1 Filter transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
6.1 Experimentally determined frequency response of the blackbox . . . . . . . . . . . 248
6.2 Identication in state-space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
8.1 The relationship between regulation and estimation . . . . . . . . . . . . . . . . . . 367
8.2 Litcheld nonlinear CSTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
9.1 Common integral performance indices . . . . . . . . . . . . . . . . . . . . . . . . . . 391
11.1 Comparing expert systems and neural networks . . . . . . . . . . . . . . . . . . . . 494
xvii
xviii LIST OF TABLES
Listings
2.1 Symbolic Laplace to z-transform conversion . . . . . . . . . . . . . . . . . . . . . . 37
2.2 Symbolic Laplace to z-transform conversion with ZOH . . . . . . . . . . . . . . . . 37
2.3 Extracting the gain, time constants and numerator time constants froman arbitrary
transfer function format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
2.4 Submarine simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
2.5 Example of the Routh array using the symbolic toolbox . . . . . . . . . . . . . . . . 71
2.6 Solve the continuous matrix Lyapunov equation using Kronecker products . . . . 77
2.7 Solve the matrix Lyapunov equation using the lyap routine . . . . . . . . . . . . . 78
2.8 Solve the discrete matrix Lyapunov equation using Kronecker products . . . . . . 79
3.1 Computing the dynamic relative gain array analytically . . . . . . . . . . . . . . . . 105
3.2 Computing the dynamic relative gain array numerically as a function of . See
also Listing 3.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
3.3 Curve tting using polynomial least-squares . . . . . . . . . . . . . . . . . . . . . . 109
3.4 Polynomial least-squares using singular value decomposition. This routine fol-
lows from, and provides an alternative to Listing 3.3. . . . . . . . . . . . . . . . . . 111
3.5 Curve tting using a generic nonlinear optimiser . . . . . . . . . . . . . . . . . . . . 113
3.6 Curve tting using the OPTI optimisation toolbox. (Compare with Listing 3.5.) . . 113
3.7 Fitting water density as a function of temperature and pressure . . . . . . . . . . . 115
3.8 Parameter condence limits for a nonlinear reaction rate model . . . . . . . . . . . 118
3.9 Comparing the dynamic response of a pendulum to the linear approximation . . . 121
3.10 Using linmod to linearise an arbitrary SIMULINK module. . . . . . . . . . . . . . . 127
4.1 Constructing a transfer function of a PID controller . . . . . . . . . . . . . . . . . . 133
4.2 Constructing a discrete (ltered) PID controller . . . . . . . . . . . . . . . . . . . . . 145
4.3 A simple PID controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
4.4 Ziegler-Nichols PID tuning rules for an arbitrary transfer function . . . . . . . . . . 159
4.5 Identies the characteristic points for the Yuwana-Seborg PID tuner from a trial
closed loop response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
4.6 Compute the closed loop model from peak and trough data . . . . . . . . . . . . . 165
4.7 Compute the ultimate gain and frequency from the closed loop model parameters. 165
4.8 Compute the open loop model, G
m
, Eqn. 4.31. . . . . . . . . . . . . . . . . . . . . . 165
4.9 Compute appropriate PI or PID tuning constants based on a plant model, G
m
,
using the IMC schemes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
4.10 Calculates the period and amplitude of a sinusoidal time series using least-squares. 174
5.1 Designing Butterworth Filters using Eqn. 5.4. . . . . . . . . . . . . . . . . . . . . . . 203
5.2 Designing a low-pass Butterworth lter with a cut-off frequency of f
c
= 800 Hz. . 203
5.3 Designing a high-pass Butterworth lter with a cut-off frequency of f
c
= 800 Hz. . 203
5.4 Designing Chebyshev Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
5.5 Computing a Chebyshev Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
5.6 Converting a 7th-order Butterworth lter to 4 second-order sections . . . . . . . . . 218
5.7 Comparing DFII and SOS digital lters in single precision. . . . . . . . . . . . . . . 219
5.8 Routine to compute the power spectral density plot of a time series . . . . . . . . . 226
xix
xx LISTINGS
5.9 Smoothing and differentiating a noisy signal . . . . . . . . . . . . . . . . . . . . . . 232
6.1 Identication of a rst-order plant with deadtime from an openloop step response
using the Areas method from Algorithm 6.1. . . . . . . . . . . . . . . . . . . . . . . 241
6.2 Frequency response identication of an unknown plant directly from input/out-
put data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
6.3 Non-parametric frequency response identication using etfe. . . . . . . . . . . . . 253
6.4 Function to generate output predictions given a trial model and input data. . . . . 255
6.5 Optimising the model parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
6.6 Validating the tted model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
6.7 Continuous model identication of a non-minimum phase system . . . . . . . . . . 258
6.8 Generate some input/output data for model identication . . . . . . . . . . . . . . 268
6.9 Estimate an ARX model from an input/output data series using least-squares . . . 269
6.10 An alternative way to construct the data matrix for ARX estimation using Toeplitz
matrices. See also Listing 6.9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
6.11 Ofine system identication using arx from the System Identication Toolbox . . 271
6.12 Ofine system identication with no model/plant mismatch . . . . . . . . . . . . . 271
6.13 Demonstrate the tting of an AR model. . . . . . . . . . . . . . . . . . . . . . . . . . 272
6.14 Create an input/output sequence from an output-error plant. . . . . . . . . . . . . 273
6.15 Parameter identication of an output error process using oe and arx. . . . . . . . 273
6.16 A basic recursive least-squares (RLS) update (without forgetting factor) . . . . . . . 284
6.17 Tests the RLS identication scheme using Listing 6.16. . . . . . . . . . . . . . . . . . 286
6.18 A recursive least-squares (RLS) update with a forgetting factor. (See also List-
ing 6.16.) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
6.19 Adaption of the plant gain using steepest descent . . . . . . . . . . . . . . . . . . . 299
6.20 Create an ARMAX process and generate some input/output data suitable for sub-
sequent identication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
6.21 Identify an ARMAX process from the data generated in Listing 6.20. . . . . . . . . 303
6.22 Recursively identify an ARMAX process. . . . . . . . . . . . . . . . . . . . . . . . . 303
6.23 Kaczmarzs algorithm for identication . . . . . . . . . . . . . . . . . . . . . . . . . 306
7.1 Simple minimum variance control where the plant has no time delay . . . . . . . . 323
7.2 A Diophantine routine to solve FA+BG = T for the polynomials F and G. . . . . 328
7.3 Alternative Diophantine routine to solve FA+BG = T for the polynomials F and
G. Compare with Listing 7.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
7.4 Constructing polynomials for the Diophantine equation example . . . . . . . . . . 329
7.5 Solving the Diophantine equation using polynomials generated from Listing 7.4. . 330
7.6 Adaptive pole-placement control with 3 different plants . . . . . . . . . . . . . . . . 333
7.7 The pole-placement control law when H = 1/B . . . . . . . . . . . . . . . . . . . . 337
7.8 Factorising a polynomial B(q) into stable, B
+
(q) and unstable and poorly damped,
B

(q) factors such that B = B


+
B

and B
+
is dened as monic. . . . . . . . . . . . 338
7.9 Minimum variance control design . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
8.1 A simple state reconstructor following Algorithm 8.1. . . . . . . . . . . . . . . . . . 359
8.2 Pole-placement control of a well-behaved system . . . . . . . . . . . . . . . . . . . . 362
8.3 A deadbeat controller simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
8.4 Pole placement for controllers and estimators . . . . . . . . . . . . . . . . . . . . . . 369
8.5 GMC on a Linear Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
8.6 GMC for a batch reactor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
8.7 The dynamic equations of a batch reactor . . . . . . . . . . . . . . . . . . . . . . . . 377
8.8 Find the Lie derivative for a symbolic system . . . . . . . . . . . . . . . . . . . . . . 383
8.9 Establish relative degree, r (ignore degree 0 possibility) . . . . . . . . . . . . . . . . 384
8.10 Design Butterworth lter of order r. . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
8.11 Symbolically create the closed loop expression . . . . . . . . . . . . . . . . . . . . . 384
9.1 Returns the IAE performance for a given tuning. . . . . . . . . . . . . . . . . . . . . 392
9.2 Optimal tuning of a PID controller for a non-minimum phase plant. This script le
uses the objective function given in Listing 9.1. . . . . . . . . . . . . . . . . . . . . . 392
LISTINGS xxi
9.3 Returns the ITSE using a SIMULINK model. . . . . . . . . . . . . . . . . . . . . . . . 395
9.4 Analytically computing the co-state dynamics and optimum input trajectory as a
function of states and co-states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
9.5 Solving the reaction prole boundary value problem using the boundary value
problem solver, bvp4c.m. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
9.6 Computes the full time-evolving LQR solution . . . . . . . . . . . . . . . . . . . . . 413
9.7 The continuous time differential Riccati equation. This routine is called from List-
ing 9.8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
9.8 Solves the continuous time differential Riccati equation using a numerical ODE
integrator. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
9.9 Calculate the continuous optimal steady-state controller gain. . . . . . . . . . . . . 416
9.10 Closed loop simulation using an optimal steady-state controller gain. . . . . . . . . 416
9.11 Solving the algebraic Riccati equation for P

using Kronecker products and vec-


torisation given matrices A, B, Qand R. . . . . . . . . . . . . . . . . . . . . . . . . 417
9.12 Calculate the discrete optimal steady-state gain by iterating until exhaustion.
Note it is preferable for numerical reasons to use lqr for this computation. . . . . 419
9.13 Comparing the continuous and discrete LQR controllers. . . . . . . . . . . . . . . . 419
9.14 An LQR controller for the blackbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
9.15 Comparing an LQR controller from Listing 9.14 with a pole-placement controller . 424
9.16 Computing the closed loop poles from the optimal LQR controller from Listing 9.14.426
9.17 Comparing the actual normally distributed random numbers with the theoretical
probability density function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
9.18 Probability and inverse probability distributions for the F-distribution. . . . . . . . 434
9.19 Generate some correlated random data. . . . . . . . . . . . . . . . . . . . . . . . . . 434
9.20 Plot a 3D histogram of the random data from Listing 9.19. . . . . . . . . . . . . . . 435
9.21 Compute the uncertainty regions from the random data from Listing 9.20. . . . . . 436
9.22 Validating the uncertainty regions computed theoretically from Listing 9.21. . . . . 436
9.23 Solving the discrete time Riccati equation using exhaustive iteration around Eqn. 9.98
or alternatively using the dare routine. . . . . . . . . . . . . . . . . . . . . . . . . . 443
9.24 Alternative ways to compute the Kalman gain . . . . . . . . . . . . . . . . . . . . . 445
9.25 State estimation of a randomly generated discrete model using a Kalman lter. . . 447
9.26 Computing the Kalman gain using dlqe. . . . . . . . . . . . . . . . . . . . . . . . . 449
9.27 Demonstrating the optimality of the Kalman lter. . . . . . . . . . . . . . . . . . . . 450
9.28 Potters algorithm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
10.1 Predictive control with input saturation constraints using a generic nonlinear op-
timiser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
10.2 Objective function to be minimised for the predictive control algorithm with input
saturation constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466
10.3 Dynamic Matric Control (DMC) control . . . . . . . . . . . . . . . . . . . . . . . . . 471
10.4 Setting up an MPC controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
10.5 Optimal control using linear programming . . . . . . . . . . . . . . . . . . . . . . . 482
11.1 Generate some arbitrary data to be used for subsequent tting . . . . . . . . . . . . 500
B.1 Polynomial addition. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
B.2 Multiple convolution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
B.3 Strip leading zeros from a polynomial. . . . . . . . . . . . . . . . . . . . . . . . . . . 508
xxii LISTINGS
Chapter 1
Introduction
Mathematicians may atter themselves that they posses new ideas which mere human language is as yet
unable to express. Let them make the effort to express those ideas in appropriate words without the aid of
symbols, and if they succeed, they will not only lay us laymen under a lasting obligation but, we venture to
say, they will nd themselves very much enlightened during the process, and will even be doubtful
whether the ideas expressed as symbols had ever quite found their way out of the equations into their
minds.
James Clerk Maxwell, 1890
Control, in an engineering sense, is where actions are taken to ensure that a particular physi-
cal process responds in some desired manner. Automatic control is where we have relieved the
human operator from the tedium of consistently monitoring the process and supplying the nec-
essary corrections. Control as a technical discipline is therefore important not only in the elds
of engineering, but also in economics, sociology and indeed in most aspects of our life. When
studying control, we naturally assume that we do conceivably have some chance of inuencing
things. For example, it is worthwhile to study the operation of a coal red power plant in order
to minimise possibly polluting emissions, but it is not worth our time to save the world from the
next ice age, or as the results of a special study group who investigated methods designed to pro-
tect the world from a stray comet (such as the one postulated to have wiped out the dinosaurs 80
million years ago) concluded, there was nothing feasible we could do, such as change the earths
orbit, or blast the asteroid, to avoid the collision. In these latter examples, the problem exists, but
our inuence is negligible.
The teaching of control has changed in emphasis over the last decade from that of linear single-
input/single-output systems elegantly described in the Laplace domain, to general nonlinear
multiple-input/multiple-output systems best analysed in the state space domain. This change
has been motivated by the increasing demands by industry and public to produce more, faster or
cleaner and is now much more attractive due to the impressive improvements in computer aided
tools, such as MATLAB used in these notes. This new emphasis is called advanced (or modern)
control as opposed to the traditional or classical control. This set of notes is intended for students
who have previously attended a rst course in automatic control covering the usual continuous
control concepts like Laplace transforms, Bode diagrams, stability of linear differential equations,
PID controllers, and perhaps some exposure to discrete time control topics like z transforms and
state space.
This book attempts to describe what advanced control is, and how it is applied in engineering
applications with emphasis on the construction of controllers using computer aided design tools
such as the numerical programming environment MATLAB from the MathWorks, [134]. With
1
2 CHAPTER 1. INTRODUCTION
this tool, we can concentrate on the intentions behind the design procedures, rather than the
mechanics to follow them.
1.1 Scope
Part one contains some revision material in z-transforms, modelling and PID controller tuning.
The discrete domain, z-transforms, and stability concepts with a brief discussion of appropriate
numerical methods are introduced in chapter 2. A brief potpourri of modelling is summarised
in chapter 3. Chapter 4 is devoted to the most common industrial controller, the three term PID
controller with emphasis on tuning, implementation and limitations. Some basic concepts from
signal processing such as ltering and smoothing are introduced in chapter 5. Identication and
the closely related adaptive control are together in chapters 6 and 7. State space analysis and
optimal control design are given in the larger chapters 8 and 9.
Notation conventions
Throughout these notes I have used some typographical conventions. In mathematical expres-
sions, scalar variables are written in italic such as a, b, c, or if Greek, , while vectors x, y are
upright bold lower case and matrices, A, are bold upper case. More notation is introduced as
required.
Computer commands and output and listings are given in a xed-width font as A=chol(B
*
B).
In some cases where you are to type an interactive command, the MATLAB prompt >> is given,
and the computed solution returned. If no ambiguity exists such as in the case for functions, the
prompt is omitted.
1.2 Matlab for computer aided control design
Modern control design has heavy computing requirements. In particular one needs to:
1. manipulate symbolic algebraic expressions, and
2. performintensive numerical calculations and simulations for proto-typing and testing quickly
and reliably, and nally
3. to implement the controller at high speed in special hardware such as an embedded con-
troller or a digital signal processing (DSP) chip perhaps using assembler.
To use this new theory, it is essential to use computer aided design (CAD) tools efciently as
real-world problems can rarely be solved manually. But as [170] point out, the use of computers
in the design of control systems has a long and fairly distinguished history. This book uses
MATLAB for the design, simulation and prototyping of controllers.
MATLAB, (which is short for MATrix LABoratory), is a programming environment that grew out
of an effort to create an easy user-interface to the very popular and well regarded public domain
FORTRAN linear algebra collection of programmes, LINPACK and EISPACK. With this direct inter-
pretive interface, one can write quite sophisticated algorithms in a very high level language, that
are consequently easy to read and maintain. Today MATLAB is a commercial package, (although
1.2. MATLAB FOR COMPUTER AIDED CONTROL DESIGN 3
some public domain lookalikes exist), that is supported with a variety of toolboxes comprising
of collections of source code subroutines organised in areas of specic interest. The toolboxes we
are most interested in, and used in this book are:
Control toolbox containing functions for controller design, frequency domain analysis, conver-
sions between various models forms, pole placement, optimal control etc. (Used through-
out)
Symbolic toolbox which contains a gateway to the symbolic capabilities of MAPLE.
Signal processing toolbox containing lters, wave form generation and spectral analysis. (Used
principally in chapter 5.)
System identication toolbox for identifying the parameters of various dynamic model types.
(Used in chapter 6.) You may also nd the following free statistics toolbox useful available
at: www.maths.lth.se/matstat/stixbox/.
Real-time toolbox can be used to interface MATLAB to various analogue to digital converters.
The student version of MATLAB (at time of writing) has a special SIGNALS & SYSTEMS TOOLBOX
that has a subset of routines from the control and signal processing toolboxes. Other toolboxes
used for some sections of the notes are the OPTIMISATION TOOLBOX, used in chapter 9 and the
NEURAL NETWORK toolbox.
Additional documentation to that supplied with MATLAB is the concise and free summary notes
[183] or the more recent [68]. Recently there has been exponential growth of other texts that heav-
ily use MATLAB (such as this one), and a current list is available fromthe Mathworks anonymous
ftp server at www.mathworks.com. This server also contains many user contributed codes, as
well as updates, bug xes etc.
If MATLAB, or even programming a high level language is new to you, then [201] is a cheap
recommended compendium, similar in form to this, covering topics in numerical analysis, again
with many MATLAB examples.
1.2.1 Alternative computer design aids
Table 1.1 lists a number of alternatives computer-aided design and modelling environments sim-
ilar and complimentary to MATLAB.
Product WWW site comment
SCILAB www.scilab.org Free Matlab/Simulink clone
OCTAVE www.octave.org Free Matlab clone, inactive
RLAB rlabplus.sourceforge.net Matlab clone, Linux
VISUALMODELQ www.qxdesign.com shareware Simulink clone
MATHVIEWS www.mathwizards.com shareware
MUPAD www.mupad.de Interfaces with SCILAB
MAPLE www.maplesoft.com commercial CAS
MATHEMATICA www.mathematica.com commercial CAS
Table 1.1: Shareware or freeware Matlab lookalikes and computer algebra systems
Unlike MATLAB, symbolic manipulators are computer programs that by manipulating symbols
can perform algebra. Such programs are alternatively known as computer algebra systems or
4 CHAPTER 1. INTRODUCTION
CAS. The most well known examples are MATHEMATICA, MAPLE, MUPAD, and MACSYMA,
(see Table 1.1). These programs can nd analytical solutions to many mathematical problems
involving integrals, limits, special functions and so forth. They are particularly useful in the
controller design stage.
The Numerics in Control
1
group in Europe have collect together a freeware FORTRAN subroutine
library SLICOT for routines relevant in systems and control.
Problem 1.1 1. Familiarise yourself with the fundamentals of MATLAB. Run the MATLAB
demo by typing demo once inside MATLAB.
2. Try the MATLAB tutorial (part 1).
3. Read through the MATLAB primer, [183] or [68], and you should get acquainted with the
MATLAB users manual.
1.3 Economics of control
Most people would agree that Engineers apply technology, but what do these two words really
mean? Technology is derived from two Greek words, techne which means skill or art, and logia
which means science or study. The interesting point here is that the art component is included.
The English language unfortunately confuses the word engine with engineering so that many peo-
ple have the mistaken view that engineers drive engines (mostly). Actually engineer is derived
from the Latin ingeniatorium which means one who is ingenious at devising. A far cry from the
relatively simple act of piloting jumbos. An interesting American perspective of the professional
engineer and modern technology is given as light reading in [2] and Flormans The Existential
Pleasures of Engineering, [66].
Chemical engineering is, succinctly put, chemistry constrained by cost. The chemist wants the
reaction to proceed, the chemical engineer takes that for granted, but is interested in increasing
the rate, or pushing the equilibrium, or in most cases both at the same time. As the incentive to
produce better products increases, accompanied by an awareness of potent global competition
driving one to reduce costs, process control becomes an important aspect of engineering.
Obviously modern computerised process control systems are expensive. They are especially ex-
pensive compared with other computers such as ofce or nancial computers because the market
is smaller, the environment harsher, the graphical requirements more critical, the duties more var-
ied, and the potential payoffs larger. Process control has at least two main duties to perform; rst
to ensure that the plant is operated safely (that is protect the plant, environment and people), and
second that the product quality is consistent with some customer or regulatory body demanded
specications. There is always a trade off between how much control you apply and the bene-
ts that result. An automobile manufacturer could produce an almost totally indestructible car
(ie, tank), but the expense of raw materials required, and the high running costs would certainly
deem the project an economic failure.
On the other hand, in 1965 Ralph Nader complained in the aptly named Unsafe at Any Speed
about the poor quality of American automotive engineering, the lack of controls and the unsafe
result. This inuential book challenged the balance from between commercial prots and more
quality control. A product with less variation in quality may be worth more than a product that
has a higher average quality, but more variation. A potentially dangerous production facility that
regularly destroys equipment, people or surroundings is not usually tolerated by the licensing
authorities.
1
The home page is located at http://www.win.tue.nl/niconet/niconet.html
1.3. ECONOMICS OF CONTROL 5
Safety concerns motivate
better control.
Fig. 1.1, adapted from [6], gives an industrial perspective of the status of process control in 1994.
The techniques are divided into those considered classical or traditional, which demand only
modest digital online computing power, (if any), little in the way of explicit process models or
understanding, and those termed loosely advanced.
compensation
Valves
Onstream analysers
Process computer
multivariable
feedforward control
smart transmitters
DCS
single variable
Online simulation
Deadtime
Transmitters
Advanced control
PLCs
PID algorithm
dynamic methods
Rule definition
Direct search
Regulatory
Constraint
Optimisation
Basic
Field
Signal condition
Steady state
analogue control
Traditional control
Figure 1.1: A comparison of traditional vs. advanced process control techniques. Adapted from
[6].
One of the major concerns for the process control engineer is to reduce the output variance. If
the variation about the setpoint is small, then the setpoint can be shifted closer to the operating
constraint, without increasing the frequency of alarms. Fig. 1.2 demonstrates the ideal case that
while popular in the advertising literature, is harder to achieve unambiguously in practice.
Many text books in the control eld are very vague about the actual conguration of real pro-
cess control systems used today. Other books that take a more trade oriented approach, are
vague about the academic side of the control performance. There are a number of reasons for
this. First many texts try hard to describe only the theoretical aspects of digital control, and any-
thing remotely applied is not considered worthy of their attention. Secondly, the control systems
are rapidly changing as the cost of micro-processors drop in price, and different programming
methods come into avour. Thirdly many industries are deliberately vague about publishing
the details of their control system since they perceive that this information could help their com-
petitors. However some information of this type is given in [63, pp131-149] and [17]. One good
6 CHAPTER 1. INTRODUCTION
spt #3
manual control
advanced control
upper quality constraint
process output
regulatory
loss ($)
violations
time
setpoint #1
spt #2
Figure 1.2: Economic improvements owing to better control. If the control scheme can reduce
the variance, the setpoint can be shifted closer to the operating or quality constraint, thereby
decreasing operating costs.
balance for the practitioner is [143].
1.4 Laboratory equipment for control tests
Obviously if we are to study automatic control with the aimto control eventually chemical plants,
manufacturing processes, robots, undertake ltering to do active noise cancellation and so forth,
we should practice, preferably on simpler, more well understood, and potentially less hazardous
equipment.
In the Automatic Control Laboratory in the Department of Electrical Engineering at the Karlstad
University, Sweden we have a number of simple bench-scale plants to test identication and
control algorithms on.
1.4.1 Plants with one input and one output
The blackbox
Fig. 1.3 and Fig. 1.4(a) shows what we perhaps unimaginatively refer to as a black-box. It is a
box, and it is coloured black. Subjecting the box to an input voltage from 0 to 5 volts delivers an
output voltage also spanning from around 0 to 5 volts, but lagging behind the input voltage since
the internals of the blackbox are simply either 7 or 9 (depending on the switch position) low-pass
passive lters cascaded together.
The blackbox is a relatively well behaved underdamped stable system with dominant time con-
stants of around 5 to 10 seconds. Fig. 1.4(b) shows the response of the blackbox to two input
steps. The chief disadvantage of using this device for control studies is that the output response
1.4. LABORATORY EQUIPMENT FOR CONTROL TESTS 7


D/A
A/D
Earth
input indicator
blue
blue
GND
Input Output
(connector #1) (connector #10)
(connector #11)
BLACK-BOX

Sluggish
Fast
To computer
From computer
Figure 1.3: Blackbox conguration. The manual switch marked will toggle between either 7 or 9
low-pass lters.
(a) Black-box wiring to the National Instruments
LabPC terminator.
input
output
15 20 25 30 35 40 45 50
0.05
0
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
0.45
ip
n
u
t
/
o
u
t
p
u
t
time (s)
Blackbox step response
(b) The response of the blackbox to 2 step inputs
Figure 1.4: The Black-box
is not visible to the naked eye, and that we cannot manually introduce disturbances. One com-
plication you can do is to cascade two blackboxes together to modify the dynamics.
Electro-magnetic balance arm
The electromagnetic balance arm shown in Fig. 1.5(a) is a fast-acting, highly oscillatory, plant
with little noise. The aim is to accurately weigh small samples by measuring the current required
to keep the balance arm level, or alternatively just to position the arm at different angles. The
output response to a step in input shown in Fig. 1.5(b) indicates how long it would take for the
oscillations to die away.
8 CHAPTER 1. INTRODUCTION
(a) The electromagnetic balance arm
20 30 40 50 60 70 80 90 100
0.4
0.2
0
0.2
0.4
0.6
0.8
1
a
r
m

p
o
s
i
t
i
o
n
Step response of the balance arm
20 30 40 50 60 70 80 90 100
0.2
0.1
0
0.1
0.2
0.3
time T=0.05 seconds
i
n
p
u
t
(b) The response of the arm to a step changes in input.
Figure 1.5: The electromagnetic balance arm
Flapper
Contrary to the balance arm, the apper in Fig. 1.6 and Fig. 1.7(b) has few dynamics, but signif-
icant low-pass ltered measurement noise. An interesting exercise is to place two apper units
in close proximity. The air from one then disturbs the apper from the other which makes an
interacting multivariable plant.
Stepper motors
A stepper motor is an example of a totally discrete system.
1.4.2 Multi-input and multi-output plants
It is possible to construct multivariable interacting plants by physically locating two plants close
to each other. One possibility is to locate two appers adjacent to each other, another possibility
is one apper and one balance arm. The extent of the interaction can be varied by adjusting the
relative position of the two plants.
Helicopter
The model helicopter, Fig. 1.8, is an example of a highly unstable, multivariable (3 inputs, 2
outputs) nonlinear, strongly interacting plant. It is a good example of where we must apply
control (or crash and burn). Fig. 1.9(b) shows the controlled response using 2 PID controllers to
control the direction and altitude. Fig. 1.10(a) shows a 3 dimensional view of the desired and
actual ight path.
1.4. LABORATORY EQUIPMENT FOR CONTROL TESTS 9
manual
auto/man
` `
Digital to Analogue
(Fan speed)
` `
`

- -
Flapper arm

A/D
On/Off switch
Motor

position transducer
.
angle
`
`
power to the motor
Figure 1.6: The apper wiring
(a) The fan/apper equipment
0 5 10 15 20 25 30 35 40 45 50
0.1
0
0.1
0.2
0.3
0.4
i
n
p
u
t
time (sec) dt=0.05
0 5 10 15 20 25 30 35 40 45 50
0.1
0.15
0.2
0.25
0.3
0.35
o
u
t
p
u
t
Step response of the flapper
(b) Step response of the apper
Figure 1.7: The Fan and apper.
10 CHAPTER 1. INTRODUCTION
top rotor
side rotor
support stand
.

moveable counter weight


.

azimuth
_

_
plant outputs
..
control inputs
elevation angle
Figure 1.8: Helicopter plant with 2 degrees of freedom. See also Fig. 1.9(a).
1.5 Slowing down Simulink
For some applications like the development of PID controllers you want to be able to slow down
the SIMULINK simulation to have time to manually introduce step changes, add disturbances,
switch from automatic to manual etc. If left alone in simulation mode, SIMULINK will run as fast
as possible, but it will slow down when it needs to sub-sample the integrator around discontinu-
ities or periods when the system is very stiff.
The SIMULINK Execution Control block allows you to specify that the simulation runs at a multi-
ple of real-time. This is most useful when you want to slow down a simulation, or ensure that it
runs at a constant rate.
The block is available from: http://www.mathworks.com/matlabcentral/fileexchange
The implementation is shown in Fig. 1.11 where the Simulation Execution Control block looks
like an A/D card but in fact is not connected to anything, although it does export some diagnostic
timing information.
An alternative method to slow down a Simulink simulation and force it to run at some set rate is
to use the commercial Humusoft real-time toolbox, but not with the A/D card actually interfaced
to anything.
1.5. SLOWING DOWN SIMULINK 11
(a) The ying helicopter balanced using 2 PID controllers since it is openloop unstable and would otherwise crash.
0 10 20 30 40 50 60 70 80 90 100
1.5
1
0.5
0
0.5
1
1.5
o
u
t
p
u
t
Helicopter
0 10 20 30 40 50 60 70 80 90 100
1
0.5
0
0.5
1
i
n
p
u
t
Time (sec)
(b) Multivariable PID control of the helicopter exhibiting mediocre controlled response and severe
derivative kick.
Figure 1.9: Multivariable PID control of an unstable helicopter
12 CHAPTER 1. INTRODUCTION
0
50
100
150
200
250
1.5
1
0.5
0
0.5
1
1.5
1
0.5
0
0.5
time
Helicopter flight path
East/West
U
p
/
D
o
w
n
(a) Multivariable helicopter control (b) Model helicopter in the trees
Figure 1.10: Helicopter ying results
1
s+1
Transfer Fcn
Simulink
Execution
Control
Signal
Generator
Scope1
Scope
Figure 1.11: Real-time Simulink simulations. A parameter in the SIMULINK EXECUTION CON-
TROL block sets the speed of the simulation.
Chapter 2
From differential to difference
equations
Excerpt from What a sorry state of affairs, Martin Walker, Guardian Weekly, June 29, 1997.
. . . But then he said something sensible, as he quite often does. . . .
We need to treat individuals as individuals and we need to address discrete problems for what they are,
and not presume them to be part of some intractable racial issue. Gingrich, properly understood, is a
national treasure, and not only because he is one of the few Americans who understand the difference
between discreet and discrete.
2.1 Computer in the loop
The cost and exibility advantages of implementing a control scheme in software rather than
fabricating it in discrete components today are simply too large to ignore. However by inserting a
computer to run the software necessitates that we work with discrete regularly sampled signals.
This added complexity, which by the way is more than compensated by the above mentioned
advantages, introduces a whole new control discipline, that of discrete control.
Fig. 2.1 shows a common conguration of the computer in the loop. For the computer to respond
to any outside events, the signals must rst be converted from an analogue form to a digital
signal, say 1 to 5 Volts, which can, with suitable processing be wired to an input port of the
computers processor. This device that accomplishes this conversion is called an Analogue to
Digital converter or A/D. Similarly, any binary output fromthe pins on a processor must rst be
converted to an analogue signal using a Digital to Analogue converter, or D/A. In some micro-
controllers, (rather than micro-processors), such as Intels 8048 or some versions of the 8051, these
converters may be implemented on the microcontroller chip.
Digital to analogue conversion is easy and cheap. One simply loads each bit across different re-
sistors, and sums the resultant voltages. The conversion is essentially instantaneous. Analogue
to digital is not nearly as easy nor cheap, and this is the reason that the common data acquisition
cards you can purchase for your PC will often multiplex the analogue input channel. There are
various schemes for the A/D, one using a D/A inside a loop using a binary search algorithm.
Obviously this conversion is not instantaneous, although this is not normally considered a prob-
lem for process control applications. Any introductory electrical engineering text such as [171]
13
14 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

Process control computer


D/A

A/D +
`

+

computer r(t)
setpoint
y(t)
output
Plant
Figure 2.1: The computer in the control loop
will give further details on the implementation details.
2.1.1 Sampling an analogue signal
It is the A/D converter that is the most interesting for our analysis of the discrete control loop.
The A/D converter will at periodic intervals dened by the computers clock sample the continu-
ous analogue input signal. The value obtained is typically stored in a device called a zeroth-order
hold until it is eventually replaced by the new sample collected one sample time later. Given con-
straints on cost, the A/D converter will only have a limited precision, or limited number of bits
in which to store the incoming discrete value. Common A/D cards such as the PCLabs card,
[3], use 12 bits giving 2
12
or slightly over 4 thousand discretisation levels. The residual chopped
away is referred to as the quantisation error. For a given number of bits, b, used in the converter,
the amplitude quantisation is
= 2
b
Low cost analogue converters may only use 8 bits, while digital audio equipment use between
16 and 18 bits.
Fig. 2.2 shows the steps in sampling an analogue signal with a three bit (8 discrete levels), A/D
sampler. The dashed stair plot gives an accurate representation of the sampled signal, but owing
to the quantisation error, we are left with the solid stair plot. You can reproduce Fig. 2.2 in
MATLAB using the fix command to do the chopping, and stairs to construct the stair plot.
While other types of hold are possible, anything higher than a rst-order hold is rarely used.
2.1.2 Selecting a sample rate
Once we have decided to implement discrete control, rather than continuous control, we must
decided on a reasonable sampling rate. This is a crucial parameter in discrete control systems.
The sample time, (T or sometimes denoted t ), is measured in time units, say seconds or in
industrial applications, minutes. The reciprocal of the sample time is the sample frequency, f,
and is usually measured in cycles/second or Hertz. The radial or angular velocity (which some
confusingly also term frequency) is denoted and is measured in radians/second. The inter-
relationships between these quantities are
f =
1
T
_
cycles
second
_
=

2
_
radians/s
radians/cycle
_
(2.1)
2.1. COMPUTER IN THE LOOP 15
0 2 4 6 8 10 12
0
1
2
3
4
5
6
7
Sample time, (kT)
S
i
g
n
a
l
Sampling a continuous signal


Analogue
Sampled
Sampled & quantisized
Figure 2.2: Sampling an analogue signal (heavy
solid) with a three bit (8 discrete levels) A/D con-
verter and zeroth-order hold. The sampled val-
ues, , are chopped to the next lowest discrete
integer level giving the sampled and quantisied
output
The faster the sampling rate, (the smaller the sampling time, T), the better our discretised signal
approximates the real continuous signal. However, it is uneconomic to sample too fast, as the
computing and memory hardware may become too expensive. When selecting an appropriate
sampling interval, or sample rate, we should consider the following issues:
The maximum frequency of interest in the signal
The sampling theoremwhich species a lower limit required on the sampling rate to resolve
any particular frequency unambiguously. (See 2.1.3 following.)
Any analogue ltering that may be required (to reduce the problem of aliasing)
The cost of the hardware and the speed of the A/D converters.
Ogata discusses the selection of a sample time qualitatively in [148, p38]. However for most
chemical engineering processes, which are dominated by relatively slow and overdamped pro-
cesses, the sample time should lie somewhere between ten times the computational delay of the
hardware t
c
and some small fraction of the process dominant time constant , say
10t
c
T

10
(2.2)
For most chemical engineering applications, the computational delay is negligible comparedwith
the process time constant, (t
c
0), so we often choose T /10. Thus for a simple rst order
rise, we would expect to have about 2030 data samples from 0 to 99%. Some may argue that
even this sampling rate is too high, and opt for a more conservative (larger) sample time down
to /6. Note that commonly used guidelines such as presented in Table 22.1 in [179, p535] span a
wide range of recommended sample times.
Overly fast sampling
Apart fromthe high cost of fast A/D converters, there is another argument against fast sampling.
When one samples a continuous system, the poles of a stable continuous system map to the poles
of a stable discrete system as T goes to zero. However the zeros in the LHP of a continuous
system may not map to zeros inside the unit disk of a discrete system as T tends to zero. This
nonintuitive result could create problems if one samples a system, and then uses the inverse
of this system within a one step controller, since now the zeros outside the unit circle become
16 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
unstable poles inside the controller for small sample times. Note that the inverse continuous
system is stable, and the discrete inverse system will be stable for large sample times, and it will
only be unstable for small sample times.
2.1.3 The sampling theorem and aliases
Dinsdale was a gentleman. And whats more he knew how to treat a female impersonator
John Cleese in Monty Python (15-9-1970)
The sampling theorem gives the conditions necessary to ensure that the inverse sampling pro-
cedure is a one to one relationship. To demonstrate the potential problems when sampling,
consider the case where we have two sinusoidal signals, but at different frequencies.
1
y
1
= sin
_
2
7
8
t
_
and y
2
= sin
_
2
1
8
t
_
If we sample these two signals relatively rapidly, say at 25Hz (T=40ms) then we can easily see
two distinct sine curves. However if we sample at T = 1, we obtain identical points.
1 t = [0:0.04:8]';
y1= -sin(2
*
pi
*
7/8
*
t);
y2= sin(2
*
pi/8
*
t);
plot(t,[y1, y2])
As shown opposite, we note that y
1
(solid) and y
2
(dashed) just happen to
coincide at t = 0, 1, 2, 3, . . . ().
0 2 4 6 8
1
0.5
0
0.5
1
Aliasing
time (s)
s
i
g
n
a
l
Consequently, at the slower sampling rate of 1 Hz, we cannot distinguish between the two dif-
ferent signals. This is the phenomenon known as aliasing since one of the frequencies pretends
to be another. In conclusion, two specic sinusoids of different frequencies can have identical
sampled signals. Thus in the act of taking samples from a continuous measurement, we have lost
some information. Since we have experienced a problem when we sample too slowly, it is rea-
sonable to ask what the minimum rate is so that no aliasing occurs. This question is answered by
the sampling theorem which states:
To recover a signal from its sample, one must sample at least two times a
period, or alternatively sample at a rate twice the highest frequency of interest
in the signal.
Alternatively, the highest frequency we can unambiguously reconstruct for a given sampling
rate, 1/T, is half of this, or 1/(2T). This is called the Nyquist frequency, f
N
.
In the second example above when we sampled at 1 Hz, the sampling radial velocity was
s
=
2 = 6.28 rad/s. This was satisfactory to reconstruct the low frequency signal (f
1
= 1/8 Hz) since
1
This example was adapted from Franklin & Powell p81
2.1. COMPUTER IN THE LOOP 17
2
1
= 1.58 rad/s. We are sampling faster than this minimum, so we can reconstruct this signal.
However for the faster signal (f
2
= 7/8 Hz), we cannot reconstruct this signal since 2
2
= 11.0
rad/s, which is faster than the sampling radial velocity.
2.1.4 Discrete frequency
If we sample the continuous signal,
x(t) = Acos(t)
with a sample time of T,
x(nT) = Acos(nT) = Acos(n)
where the digital frequency, , is dened as

def
= T = 2f T = 2
f
f
s
then the range of analogue frequencies is 0 < f < while the range of digital frequencies is
limited by the Nyquist sampling limit, f
s
/2 giving the allowable range for the digital frequency
as
0
MATLAB unfortunately decided on a slightly different standard in the SIGNAL PROCESSING tool-
box. Instead of a range from zero to , MATLAB uses a range from zero to 2 where 1 corresponds
to half the sampling frequency or the Nyquist frequency. See [42].
In summary:
symbol units
sample time T or t s
sampling frequency f
s
=
1
T
Hz
angular velocity = 2f rad/s
digital frequency = T =
2f
fs

where the allowable ranges are:


0 < , continuous
0 , sampled
and Nyquist frequency, f
N
, and the dimensionless Nyquist frequency,
N
are:
f
N
=
f
s
2
=
1
2T
[Hz]

N
=
2f
N
f
s
=
It is practically impossible to avoid aliasing problems when sampling, using only digital lters.
Almost all measured signals are corrupted by noise, and this noise has usually some high or even
innite frequency components. Thus the noise is not band limited. With this noise, no matter
how fast we sample, we will always have some reection of a higher frequency component that
appears as an impostor or alias frequency.
18 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
If aliasing is still a problem, and you cannot sample at a higher rate, then you can insert a low
pass analogue lter between the measurement and the analogue to digital converter (sampler).
The analogue lter or in this case known as an anti-aliasing lter, will band-limit the signal, but
not corrupt it with any aliasing. Expensive high delity audio equipment will still use analogue
lters in this capacity. Analogue and digital lters are discussed in more detail in chapter 5.
Detecting aliases
Consider the trend y(t) in Fig. 2.3 where we wish to estimate the important frequency compo-
nents of the signal. It is evident that y(t) is comprised of one or two dominating harmonics.
Figure 2.3: Part of a noisy time series with
unknown frequency components. The con-
tinuous underlying signal (solid) is sam-
pled at T = 0.7, (), and at T = 1.05 s ().
0 1 2 3 4 5 6 7
2
1
0
1
2
3
time (s)
o
u
t
p
u
t


continuous
T
s
=0.7
T
s
=1.05
The spectral density when sampling at T = 0.7s ( in Fig.2.3) given in the upper trend of Fig. 2.4
exhibits three distinct peaks. These peaks are the principle frequency components of the signal
and are obtained by plotting the absolute value of the Fourier transform of the time signal
2
,
|DFT {y(t)}|. Reading off the peak positions, and for the moment overlooking any potential
10
0
10
2
T
s
= 0.7 s
f
N
=0.71
p
o
w
e
r
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8
10
0
10
2
T
s
= 1.05 s
f
N
=0.48
frequency (Hz)
p
o
w
e
r
Figure 2.4: The frequency component of a signal sampled at T
s
= 0.7s (upper) and T
s
= 1.05s
(lower). The Nyquist frequencies for both cases are shown as vertical dashed lines. See also
Fig. 2.5.
problems with undersampling, we would expect y(t) to be something like
y(t) sin(20.1t) + sin(20.5t) + sin(20.63t)
However in order to construct Fig. 2.4 we had to sample the original time series y(t) possibly
introducing spurious frequency content. The Nyquist frequency f
N
= 1/(2T
s
) is 0.7143 and is
2
More about the spectral analysis or the power spectral density of signals comes in chapter 5.
2.1. COMPUTER IN THE LOOP 19
shown as a vertical dashed line in Fig. 2.4(top). The power spectrum is reected in this line, but
is not shown in Fig. 2.4.
If we were to re-sample the process at a different frequency and re-plot the power density plot
then the frequencies that were aliased will move in this second plot. The points in Fig. 2.3 are
sampled at t = 1.05s with corresponding spectral power plot in Fig. 2.4. The important data
from Fig. 2.4 is repeated below.
Curve T
s
(s) f
N
(Hz) peak 1 peak 2 peak 3
top 0.7 0.7143 0.1 0.50 0.63
bottom 1.05 0.4762 0.1 0.152 0.452
First we note that the low frequency peak (f
1
= 0.1Hz) has not shifted from curve a (top) to
curve b (bottom), so we would be reasonably condent that f
1
= 0.1Hz and is not corrupted by
the sampling process.
However, the other two peaks have shifted, and this shift must be due to the sampling process.
Let us hypothesize that f
2
= 0.5Hz. If this is the case, then it will appear as an alias in curve b
since the Nyquist frequency for curve b (f
N
(b) = 0.48) is less than the proposed f
2
= 0.5, but it
will appear in the correct position on curve a. The apparent frequency

f
2
(b) on curve b will be

f
2
(b) = 2f
N
(b) f
2
= 2 0.4762 0.5 = 0.4524
which corresponds to the third peak on curve b. This would seem to indicate that our hypothesis
is correct for f
2
. Fig. 2.5 shows this reection.
10
0
10
2
T
s
= 0.7 s
f
N
=0.71
p
o
w
e
r
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8
10
0
10
2
T
s
= 1.05 s
f
N
=0.48
frequency (Hz)
p
o
w
e
r
Figure 2.5: Reecting the frequency re-
sponse in the Nyquist frequency from
Fig. 2.4 shows why one of the peaks is ev-
ident in the frequency spectrum at T
s
=
1.05, but what about the other peak?
Now we turn our attention to the nal peak. f
3
(a) = 0.63 and f
2
(b) = 0.152. Let us again try
the fact that f
3
(a) is the true frequency = 0.63Hz. If this were the case the apparent frequency
on curve b would be

f
3
(b) = 2f
N
(b) f
2
= 0.3224Hz. There is no peak on curve b at this
frequency so our guess is probably wrong. Let us suppose that the peak at f
3
(a) is the rst
harmonic. In that case the true frequency will be f
3
= 2f
N
(a)

f
3
(a) = 0.8Hz. Now we check
using curve b. If the true third frequency is 0.8Hz, then the apparent frequency on curve b will
be

f
3
(b) = 2f
N
(b) f
3
= 0.153Hz. We have a peak here which indicates that our guess is a good
one. In summary, a reasonable guess for the unknown underlying function is
y(t) sin(20.1t) + sin(20.5t) + sin(20.8t)
although we can never be totally sure of the validity of this model. At best we could either re-
sample at a much higher frequency, say f
s
> 10Hz, or introduce an analogue low pass lter to cut
out, or at least substantially reduce, any high frequencies that may be reected.
20 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
2.2 Finite difference models
To compute complex mathematical operations such as differentiation or integration, on a digital
computer, we must rst discretise the continuous equation into a discrete form. Discretising is
where we convert a continuous time differential equation into a difference equation that is then
possible to solve on a digital computer.
Figure 2.6: In Nathaniel Hawthornes The Scarlet Letter, Hester
Prynne is forced to wear a large, red A on her chest when she is
found guilty of adultery and refuses to name the father of her illegiti-
mate child.
In control applications, we are often required to solve ordinary differential equations such as
dy
dt
= f(t, y) (2.3)
for y(t). The derivative can be approximated by the simple backward difference formula
dy
dt

y
t
y
tT
T
(2.4)
where T is the step size in time or the sampling interval. Provided T is kept sufciently small,
(but not zero) the discrete approximation to the continuous derivative is reasonable. Inserting
this approximation, Eqn. 2.4 into our original differential equation, Eqn. 2.3, and re-arranging for
y
t
results in the famous Euler backward difference scheme;
y
t
= y
tT
+Tf(t T, y
tT
) (2.5)
Such a scheme is called a recurrence scheme since a previous solution, y
tT
, is used to calculate
y
t
, and is suitable for computer implementation. The beauty of this crude method of differen-
tiation is the simplicity and versatility. Note that we can discretise almost any function, linear
or nonlinear without needing to solve analytically the original differential equation. Of course
whether our approximation to the original problem is adequate is a different story and this com-
plex, but important issue is addressed in the eld of numerical analysis.
Problem 2.1 1. What is the nite difference approximation for a third order derivative?
2. Write down the second order nite difference approximation to

2
d
2
y
dt
2
+ 2
dy
dt
+y = ku
2.2.1 Difference equations
Difference equations are the discrete counterpart to continuous differential equations. Often the
difference equations we are interested in are the result of the discretisation of a continuous dif-
ferential equation, but sometimes, as in the case below, we may be interested in the difference
2.2. FINITE DIFFERENCE MODELS 21
equation in its own right. Difference equations are much easier to simulate and study in a digital
computer than a differential equation for example, since they are already written in a form where
we can just step along following a relation
x
k+1
= f (x
k
)
rather than resorting to integration. This step by step procedure is also known as a mathematical
mapping since we map the old vector x
k
to a new vector x
k+1
.
H enons chaotic attractor
The system of discrete equations known as H enons attractor,
x
k+1
= (y
k
+ 1) 1.4x
2
k
, x
0
= 1 (2.6)
y
k+1
= 0.3x
k
, y
0
= 1 (2.7)
is an interesting example of a discrete mapping which exhibits chaotic behaviour.
We will start from point x
0
= (x
0
, y
0
) = (1, 1) and investigate the subsequent behaviour using
SIMULINK. Since H enons attractor is a discrete system, we will use unit delays to shift back
fromx
k+1
x
k
and to better visualise the results we will plot an (x, y) phase plot. The SIMULINK
simulation is given in Fig. 2.7. Compare this SIMULINK construction (which I have drawn de-
liberately to ow from right to left) so that it matches the way we read the system equations,
Eqn. 2.6-Eqn. 2.7.
1/z
y1
1/z
x1
XY Graph
y
To Workspace2
x
To Workspace Sum1
Product
1.4
Gain2
0.3
Gain
1
Constant
Figure 2.7: H enons attractor, (Eqns 2.62.7), modelled in SIMULINK. See also Fig. 2.8.
The time response of x and y, (left gures in Fig. 2.8), of this mapping is not particularly inter-
esting, but the result of the phase plot (without joining the dots), (right gure in Fig. 2.8), is an
interesting mapping.
Actually what the chaotic attractor means is not important at this stage, this is after all only a
demonstration of a difference equation. However the points to note in this exercise are that we
never actually integrated any differential equations, but only stepped along using the unit delay
blocks in SIMULINK. Consequently these types of simulations are trivial to program, and run
very fast in a computer. Another example of a purely discrete system is given in later Fig. 6.10.
22 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
2
1
0
1
2
x
k
0 5 10 15 20 25 30 35
0.5
0
0.5
1
y
k
time counter
(a) The time response
1.5 1 0.5 0 0.5 1 1.5
0.5
0
0.5
1
x
k
y
k
Start point
(b) The (x, y) or phase response
Figure 2.8: The time response (left) and phase plot (right) of H enons attractor as computed by
the SIMULINK block diagram in Fig. 2.7.
2.3 The z transform
The sampling of a continuous function f(t) at regular sampling intervals equally spaced T time
units apart creates a new function f

(t),
f

(t) =

n=0
f(kT) (t kT) (2.8)
where (x) is the Dirac delta function which is dened as being a perfect impulse at x = 0,
and zero elsewhere. Note that the actual value of (0) is innity, but the integral of (t) is 1.0.
Expanding the summation term in Eqn 2.8 gives
f

(t) = f
0
(t) +f
T
(t T) +f
2T
(t 2T) +f
3T
(t 3T) +
Now suppose we wish to know the value of the third sampled function f

(t = 3T). For simplicity


we will assume the sample time is T = 1.
f

(3) = f
0
(3) +f
1
(2) +f
2
(1)
. .
all zero
+f
3
(0) +f
4
(1) +
. .
all zero
All the terms except for the term containing (0) are zero, while (0) = . Thus the value
of the function f

(3) = . Often you will see a graph of f

(t) depicted where the heights of


the values at the sample times are the same as the height of the continuous distribution such as
sketched in Fig. 2.13. Strictly this is incorrect, as it is the strength or integral of f

(t) which is the


same as the value of the continuous distribution f(t). I think of the function f

(t) as a series of
impulses whose integral is equal to the value of the continuous function f(t).
If we take the Laplace transform of the sampled function f

(t), we get
L{f

(t)} = L
_

n=0
f
kT
(t kT)
_
(2.9)
Now the function f
kT
is assumed constant so it can be factored out of the Laplace transform,
and the Laplace transform of the (0) is simply 1.0. If the impulse is delayed kT units, then the
2.3. THE Z TRANSFORM 23
Laplace transform is e
kT
1. Thus Eqn. 2.9 simplies to
L{f

(t)} =

n=0
f
kT
e
kTs
=

k=0
f
k
z
k
where we have dened
z
def
= e
sT
(2.10)
In summary, the z-transform of the sampled function f

(t) is dened as
F(z)
def
= Z {f

(t)} =

k=0
f
k
z
k
(2.11)
The function F(z) is an innite series, but can be written in a closed form if f(t) is a rational
function.
2.3.1 z-transforms of common functions
We can use the denition of the z-transform, Eqn. 2.11, to compute the z-transform of common
functions such as steps, ramps, sinusoids etc. In this way we can build for ourselves a table of
z-transforms such as those found in many mathematical or engineering handbooks.
Sampled step function
The unit sampled step function is simply s(kT) = 1, k 0. The z-transform of s(kT) following
the denition of Eqn. 2.11 is
S(z) =

k=0
k
n
z
k
= 1 + 1 z
1
+ 1 z
2
+ 1 z
3
+ (2.12)
By using the sum to innity for a geometric series,
3
we obtain the closed form equivalent for
Eqn. 2.12 as
S(z) =
1
1 z
1
(2.13)
Ramp and exponential functions
For the ramp function, x(k) = n for k 0, and the exponential function, x(k) = e
an
, k 0, we
could go through the same formal analytical procedure, but in this case we can use the ztrans
command from the symbolic toolbox in MATLAB.
3
The sum of a geometric series of n terms is
a + ar + ar
2
+ + ar
n1
=
a (1 r
n
)
1 r
; r = 1
and if |r| < 1, then the sum for an innite number of terms converges to
S =
a
1 r
24 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
z-transform of the ramp function using the Symbolic
toolbox for MATLAB.
Z {k}
1 >> syms k T
>> ztrans(k
*
T)
ans =
T
*
z/(z-1)2
z-transform of the exponential function.
Z
_
e
ak
_
1 >> syms k T a
>> ztrans(exp(-a
*
k
*
T))
ans =
z/exp(-a
*
T)/(z/exp(-a
*
T)-1)
>> simplify(ans)
6 ans =
z
*
exp(a
*
T)/(z
*
exp(a
*
T)-1)
In a similar manner we can build our own table of z-transforms of common functions.
Final and initial value theorems
Tables and properties of z-transforms of common functions are given in many handbooks and
texts such as [148, p49,67], but two of the more useful theorems are the initial value and the nal
value theorems given in Table 2.1. As in the continuous case, the nal value theorem is only
applicable if the transfer function is stable.
Table 2.1: Comparing nal and initial value theorems for continuous and discrete systems
Continuous Discrete
Initial value, lim
t0
y(t) lim
s
sY (s) lim
z
Y (z)
Final value, lim
t
y(t) lim
s0
sY (s) lim
z1
__
1 z
1
_
Y (z)

2.4 Inversion of z-transforms


The usefulness of the z-transformis that we can do algebraic manipulations on discrete difference
equations in the same way we can do algebraic manipulations on differential equations using the
Laplace transform. Generally we:
1. Convert to z-transforms, then
2. do some relatively simple algebraic manipulations to make it easier to
3. invert back to the time domain.
The nal step, the inversion, is the tricky part. The process of obtaining f

(t) back from F(z) is


called inverting the z-transform, and is written as
f

(t) = Z
1
{F(z)} (2.14)
Note that only the sampled function is returned f

(t), not the original f(t). Thus the full inver-


sion process to the continuous domain f(t) is a one to many operation.
There are various ways to invert z-transforms:
2.4. INVERSION OF Z-TRANSFORMS 25
1. Use tables of z-transforms and their inverses in handbooks, or use a symbolic manipulator.
(See 2.4.1.)
2. Use partial-fraction expansion and tables. In MATLAB use residue to compute the partial
fractions. (See 2.4.2.)
3. Long division for rational polynomial expressions in the discrete domain. In MATLAB use
deconv to do the polynomial division. (See 2.4.3.)
4. Computational approach while suitable for computers, has the disadvantage that the an-
swer is not in a closed form. (See 2.4.4.)
5. Analytical formula from complex variable theory. (Not useful for engineering applications,
see 2.4.5.)
2.4.1 Inverting z-transforms with symbolically
The easiest, but perhaps not the most instructive, way to invert z-transforms is to use a computer
algebra package or symbolic manipulator such as the symbolic toolbox or MUPAD. One simply
enters the z-transform, then requests the inverse using the iztrans function in a manner similar
to the forward direction shown on page 24.
>> syms z % Dene a symbolic variable z
>> G = (10
*
z+5)/(z-1)/(z-1/4) % Construct G(z) = (10z + 5)/(z 1)/(z 1/4)
3 G =
(10
*
z+5)/(z-1)/(z-1/4)
>> pretty(G) % check it
10 z + 5
-----------------
8 (z - 1) (z - 1/4)
>> iztrans(G) % Invert the z-transform, Z
1
{G(z)}
ans =
20
*
kroneckerDelta(n, 0) - 40
*
(1/4)n + 20
The Kronecker function, or kroneckerDelta(n, 0) is a shorthand way of expressing piece-
wise functions in MATLAB. The expression kroneckerDelta(n, 0) returns 1 when n = 0,
and 0 for all other values.
This is a rather messy and needlessly complicated artifact due to the fact that the symbolic toolbox
does not know that n is dened as positive. We can explicitly inform MATLAB that n > 0, and
then we get a cleaner solution.
>> syms z
>> syms n positive
>> G = (10
*
z+5)/(z-1)/(z-1/4);
4
>> y=iztrans(G) % Invert to get,y[n] = Z
1
{G(z)}
y =
20-40
*
(1/4)n
>> limit(y,n,inf) % y[]
9 ans =
20
The last command computed the steady-state by taking the limit of y[n] as n .
26 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
2.4.2 The partial fraction method
Inverting transforms by partial fractions is applicable for both discrete z-transforms and con-
tinuous Laplace transforms. In both cases, we nd an equivalent expression for the transform
in simple terms that are summed together. Hopefully we can then consult a set of tables, such
as [148, Table 2.1 p49], to invert each term individually. The inverse of the sum, is the sum of
the inverses meaning that these expressions when summed together give the full inversion. The
MATLAB function residue forms partial fractions froma continuous transfer function, although
the help le warns that this operation is numerically poorly conditioned. Likewise the routine
residuez (that is residue with a trailing z) is designed to extract partial fractions in a form
suitable when using ztransforms.
As an example, suppose we wish to invert
G(s) =
4s
2
58s 24
s
3
+ 2s
2
24s
=
4s
2
58s 24
s(s + 6)(s 4)
using partial fractions noting that it contains no multiple or complex roots.
It is easy to spot the pole at s = 0, and the two remaining can be found by synthetic division, or
by factorising using the roots([1 2 -24 0]) command. The partial fraction decomposition
of G(s) can be written as
G(s) =
4s
2
58s 24
s(s + 6)(s 4)
=
A
s
+
B
s + 6
+
C
s 4
where the coefcients A, B and C can be found either by equating the coefcients or using the
cover-up rule shown below.
A =
4s
2
58s 24
(s + 6)(s 4)

s=0
= 1, B =
4s
2
58s 24
s(s 4)

s=6
= 3
C =
4s
2
58s 24
s(s + 6)

s=4
= 8
In MATLAB we can use the residue command to extract the partial fractions.
>> B = [-4 -58 -24]; % Numerator of G(s) = (4s
2
58s 24)/(s(s + 6)(s 4))
>> A = [ 1 2 -24 0]; % Denominator of G(s)
>> [r,p,k] = residue(B,A) % Find partial fractions
r = % residues (top line)
5 3
-8
1
p = % factors or poles
-6
10 4
0
k = % No extra parts
[]
The order of the residue and pole coefcient produced by residue is the same for each, so the
partial fraction decomposition is again
G(s) =
4s
2
58s 24
s
3
2s 24s
=
3
s + 6
+
8
s 4
+
1
s
2.4. INVERSION OF Z-TRANSFORMS 27
and we can invert each termindividually perhaps using tables to obtain the time domain solution
g(t) = 3e
6t
8e
4t
+ 1
If the rational polynomial has repeated roots or complex poles, slight modications to the proce-
dure are necessary so you may need to consult the help le.
Special cases for z-transforms
We can invert z-transforms in a manner similar to Laplace, but if you consult a table of z-
transforms and their inverses in standard control textbooks such as Table 2-1 in [149, p49], you
will discover that the table is written in terms of factors of the form z/(z + a) or alternatively
1/(1 z
1
rather than say 1/(z +a). This means that we should rst perform the partial fraction
decomposition on X(z)/z, rather than just X(z) as in the continuous case. An outline to follow
is given in Algorithm 2.1.
Algorithm 2.1 Inverting z-transforms by partial fractions
To invert a z transform, X(z), using partial fractions, do the following:
1. Divide X(z) by z obtaining X(z)/z.
2. Find the partial fractions of X(z)/z perhaps using residue.
3. Multiply each partial fraction by z to obtain a fraction of the form z/(z +a)
4. Find the inverse of each fraction separately using tables, and sum together to nd x(t).
Symbolic partial fractions in MATLAB
Suppose we want to invert
G(z) =
10z
z
2
+ 4z + 3
to g[n] using partial fractions. Unfortunately there is no direct symbolic partial fraction command,
but Scott Budge from Utah University found the following sneaky trick which involves rst inte-
grating, then differentiating the polynomial. This round-about way works because MATLAB in-
tegrates the expression by internally forming partial fractions and then integrating term by term.
Taking the derivative brings you back to the original expression, but now in partial fraction form.
>> syms z
2 >> G = 10
*
z/(z2 + 4
*
z + 3);
>> G= diff(int(G/z)) % Extract partial fractions of G(z)/z
G =
5/(z+1)-5/(z+3)
>> G=expand(G
*
z)
7 G =
5
*
z/(z+1)-5
*
z/(z+3) % Gives us G(z)/z =
5z
z+1

5z
z+3
>> syms n positive; iztrans(G,z,n)
ans =
12 -5
*
(-3)n+5
*
(-1)n
28 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
While this strategy currently works, we should take note that in future versions of the symbolic
toolbox this may not continue to work. In the above example we also have the option of using
residuez.
2.4.3 Long division
Consider the special case of the rational polynomial where the denominator is simply 1,
F(z) = c
0
+c
1
z
1
+c
2
z
2
+c
3
z
3
+
The inverse of this transformis trivial since the time solution at sample number k or t = kT is sim-
ply the coefcient of the term z
k
. Consequently it follows that f(0) = c
0
, f(T) = c
1
, f(2T) =
c
2
, . . . , f(kT) = c
k
etc. Thus if we have a rational transfer function, all we must do is to synthet-
ically divide out the two polynomials to obtain a single, albeit possibly innite, polynomial in
z.
Ogata refers to this approach as direct division [148, p69]. In general the division will result
in an innite power series in z, and so is not a particularly elegant closed-form solution, but for
most stable systems, the power series can be truncated eventually with little error.
So to invert a z-transform using long-division, we:
1. Convert the z-transform to a (possibly innite) power series by dividing the denominator
into the numerator using long division or deconv.
2. The coefcients of z
k
are the solutions at the sample times kT.
Long division by hand is tedious and error-prone, but we can use the polynomial division capa-
bilities of MATLABs deconv to do this long division automatically. Since deconv only performs
integer division returning a quotient and remainder, we must fool it into giving us the in-
nite series by padding the numerator with zeros.
To invert
Y (z) =
z
2
+z
(z 1)(z
2
1.1z + 1)
=
z
2
+z
z
3
2.1z
2
+ 2.1z 1
using deconv for the long division, we pad the numerator on the right with say 5 zeros, (that is,
we multiply by z
5
), and then do the division.
z
7
+z
6
z
3
2.1z
2
+ 2.1z 1
= z
4
+ 3.1z
3
+ 4.41z
2
+ 3.751z + 1.7161
. .
Q
+ remainder
We are not particularly interested in the remainder polynomial. The more zeros we add, (5 in the
above example), the more solution points we get.
>> Yn = [1,1,0]; % Numerator of G(z)
>> Yd = conv([1,-1],[1 -1.1 1]); % Denominator of G(z) is (z 1)(z
2
1.1z + 1)
3 >> [Q,R] = deconv([Yn,0,0,0,0,0],Yd) % Multiply by z
5
to zero pad, then do long division
Q =
1.0000 3.1000 4.4100 3.7510 1.7161
>> dimpulse(Yn,Yd,7); % Matlab's check
2.4. INVERSION OF Z-TRANSFORMS 29
0 1 2 3 4 5 6
0
1
2
3
4
5
sample #
O
u
t
p
u
t
Figure 2.9: Inverting z-transforms using dimpulse for
the rst six samples. It is possible also to construct a
discrete transfer function object and then use the generic
impulse routine.
We can also numerically verify the inversion using dimpulsefor six samples as shown in Fig. 2.9.
Problem 2.2 1. The pulse transfer function of a process is given by
Y (z)
X(z)
=
4(z + 0.3)
z
2
z + 0.4
Calculate the response of y(nT) to a unit step change in x using long division.
2. Determine the inverse by long division of G(z)
G(z) =
z(z + 1)
(z 1)(z
2
z + 1)
2.4.4 Computational approach
The computational method is so-called because it is convenient for a computer solution technique
such as MATLAB as opposed to an analytical explicit solution. In the computational approach we
convert the z-transform to a difference equation and use a recurrence solution. Consider the
following transform (used in the example from page 25) which we wish to invert back to the time
domain.
X(z)
U(z)
=
10z + 5
(z 1)(z 0.25)
=
10z + 5
z
2
1.25z + 0.25
=
10z
1
+ 5z
2
1 1.25z
1
+ 0.25z
2
(2.15)
The inverse is equivalent to solving for x(t) when u(t) is an impulse function. The transform can
be expanded and written as a difference equation
x
k
= 1.25x
k1
0.25x
k2
+ 10u
k1
+ 5u
k2
(2.16)
Since U(z) is an impulse, thus U(z) = 1 which means that u(0) = 1 and u(k) = 0, k > 0. Now
we substitute k = 0 to start, and note that u(k) = x(k) = 0 when k < 0 by denition. We now
have enough information to compute x(0).
x
0
= 1.25x
1
0.25x
2
+ 10u
1
+ 5u
2
= 1.25 0 0.25 0 + 10 0 + 5 0
= 0
30 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
Continuing, we substitute k = 1 into Eqn 2.16 and using our previously computed x
0
and nd
the next term.
x
1
= 1.25x
0
0.25x
1
+ 10u
0
+ 5u
1
= 1.25 0 0.25 0 + 10 1 + 5 0
= 10
and just to clarify this recurrence process further, we can try the next iteration of Eqn. 2.16 with
k = 2,
x
2
= 1.25x
1
0.25x
0
+ 10u
1
+ 5u
0
= 1.25 10 0.2 0 + 10 0 + 5 1
= 17.5
Now we can use the full recurrence relation, (Eqn 2.16), to obtain the solution in a stepwise
manner to build up the solution as shown in Table 2.2. All the terms on the right hand side of
Eqn 2.16 are either known initially (u(t)), or involve past information, hence it is possible to solve.
Note that in this inversion scheme, u(t) can be any known input series.
Table 2.2: The inversion of a z transform using the computation method. Only the rst 5 samples
and the nal value are calculated. The nal value is as calculated using the symbolic manipulator
earlier on page 25.
time (kT) u(k) x(k)
0 1 0
1 0 10
2 0 17.5
3 0 19.375
4 0 19.8438
.
.
.
.
.
.
.
.
.
0 20
MATLAB is well suited for this type of computation. To invert Eqn. 2.15 we can use the discrete
filter command. We rewrite Eqn. 2.15 in the form of a rational polynomial in z
1
,
G(z) =
b
0
+b
1
z
1
+b
2
z
2
1 +a
1
z
1
+a
2
z
2
where the numerator and denominator are entered as row vectors in decreasing powers of z. We
then create an impulse input vector u with say 6 samples and then compute the output of the
system
>> b = [0.0, 10.0, 5.0] % Numerator (10z
1
+ 5z
2
)
>> a = [1.0, -1.25, 0.25] % Denominator (1 1.25z
1
+ 0.25z
2
)
3
>> u = [1, zeros(1,5)] % impulse input
u =
1 0 0 0 0 0
>> x = filter(b,a,u) % compute output
8 x =
10.0000 17.5000 19.3750 19.8438 19.9609 19.9902
which gives the same results as Table 2.2.
2.4. INVERSION OF Z-TRANSFORMS 31
The control toolbox has a special object for linear time invariant (LTI) systems. We can create a
discrete system with the transfer function command, tf, and by specifying a sampling time, we
imply to MATLAB that it is a discrete system.
1 >> sysd = tf([10 5],[1 -1.25 0.25],1) % System of interest (10z + 5)/(z
2
1.25z + 0.25)
Transfer function:
10 z + 5
-------------------
6 z2 - 1.25 z + 0.25
Sampling time: 1
>> y=impulse(sysd) % compute the impulse response
11 y =
0
10.0000
17.5000
19.3750
16 19.8438
19.9609
Finally, the contour integral method can also be used to invert z-transforms, [148, 33], but
Seborg et al maintains it is seldom used in engineering practice, [179, p571] because it is fraught
with numerical implementation difculties. These difculties are also present in the continuous
equivalent; some of which are illustrated in the next section.
2.4.5 Numerically inverting the Laplace transform
Surprisingly, the numerical inversion of continuous transfer functions is considered far less impor-
tant than the computation of the inverse of discrete transfer functions. This is fortunate because
the numerical inversion of Laplace transforms is devilishly tricky. Furthermore, it is unlikely that
you would ever want to numerically invert a Laplace transform in control applications, since
most problems involver little more than a rational polynomial with a possible exponential term.
For these problems we can easily factorise the polynomial and use partial fractions or use the
step orimpulse routines for continuous linear responses.
However in the rare cases where we have a particularly unusual F(s) which we wish to convert
back to the time domain, we might be tempted to use the analytical expression for the inverse
directly
f(t) =
1
2j
_
+j
j
F(s) e
st
ds (2.17)
where is chosen to be larger than the real part of any singularity of F(s). Eqn. 2.17 is sometimes
known as the Bromwich integral or Mellins inverse formula.
The following example illustrates a straight forward application of Eqn. 2.17 to invert a Laplace
transform. However be warned that for all but the most well behaved rational polynomial exam-
ples this strategy is not to be recommended as it results in severe numerical roundoff error due
to poor conditioning.
32 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
Suppose we try to numerically invert a simple Laplace transform,
F(s) =
3
s(s + 5)
f(t) =
3
5
_
1 e
5t
_
with a corresponding simple time solution. We can start by dening an anonymous function of
the Laplace transform to be inverted.
Fs = @(s) 3.0./(s+5)./s; % Laplace function to invert F(s) = 3/(s(s + 5)) . . .
Fsexp = @(s,t) Fs(s).
*
exp(s
*
t) % and associated integrand F(s)e
st
Now since the largest singularity of F(s) is 0, we can choose the contour path safely to be say
= 0.1. We can also approximate the innite integration interval by reasonably large numbers.
It is convenient that the MATLAB routine integral works directly in the complex domain.
c = 0.1; % Value > than any singularities of F(s)
a = c-100j; b = c+200j; % Contour path approx: jto +j
3
t=linspace(0,8); % time range of interest
% Numerically approximate Eqn. 2.17.
ft = 1./(2
*
pi
*
1j)
*
arrayfun(@(t) integral(@(x) Fsexp(x,t),a,b), ti);
plot(t,ft) % Compare results in Fig. 2.10(a).
Due to small numerical roundoff however, the returned solution has a small imaginary compo-
nent, which we can in this instance safely ignore. In this rather benign example, where we know
the analytical solution, we can validate the accuracy as shown in Fig. 2.10(a), which it has to be
admitted, is not that wonderful. We should also note in the simplistic implementation above we
have not adequately validated that our algorithmic choices such as the nite integration limits
are appropriate, so we should treat any subsequent result with caution. In fact if you repeat this
calculation with a larger value of , or a smaller integration range such as say 1 10j to 1 + 10j
then the quality of the solution drops alarmingly. One way to improve the integration accuracy
is to use the waypoints option in the integral routine.
Over the years there have been many attempts to improve the inversion strategy as reviewed
in [1], but nearly all of the proposals run into the problem of precision. For example, Fig. 2.11
shows the problem when attempting to invert F(s) = 1/

s
2
+ 1 using the Gaver-Stehfest ap-
proximation algorithm with a varying number of terms. The Gaver-Stehfest family of schemes
are well known to produce inaccurate results for underdamped systems, but when we increase
the number of terms in an attempt to improve the accuracy, the results deteriorate due to numer-
ical round off. Directly applying the Bromwich integral to this transform as shown in Fig. 2.10(b)
is no better. While the strategy suggested in [1] seemingly circumvents the problem of precision,
it does so by brute-force using multi-precision arithmetic which is hardly elegant.
An alternative numerical algorithm is the inverse Laplace transform function invlap function
contributed by Karl Hollenbeck from the Technical University of Denmark. You can test this
routine using one of the following Laplace transformpairs in Table 2.3. The rst two are standard,
those following are more unusual. A more challenging collection of test transforms is given in
[1].
The numerical solution to L
1
_
1

s
e
1/s
_
is compared with the analytical solution fromTable 2.3
in Fig. 2.12 using a modest tolerance of 10
2
. The routine splits the time axis up into decades,
and inverts each separately which is why we can see some numerical noise starting at t = 10.
All of these numerical inversion strategies, starting from the direct application of the Bromwich
2.4. INVERSION OF Z-TRANSFORMS 33
0 2 4 6 8
0.02
0
0.02
t
e
r
r
o
r
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
L
1

3
s(s+5)

f
(
t
)
(a) Inverting a benign transfer function,
L
1
_
3
s(s+5)
_
0 5 10 15 20
1
0
1
2
t
e
r
r
o
r
1
0.5
0
0.5
1
1.5
2
L
1

s
2
+1

f
(
t
)
(b) Inverting a challenging transfer function,
L
1
_
1

s
2
+1
_
Figure 2.10: Numerically inverting Laplace transforms by direct evaluation of the Bromwich
integral. Since this strategy is suspectable to considerable numerical errors, it is not to be recom-
mended.
0 2 4 6 8 10
0.5
0
0.5
1
No. of terms = 8
0 2 4 6 8 10
0.5
0
0.5
1
No. of terms = 16
0 2 4 6 8 10
0.5
0
0.5
1
No. of terms = 20
0 2 4 6 8 10
1
0
1
No. of terms = 26
t
Figure 2.11: Demonstrating the precision problems
when numerically inverting the Laplace transformusing
the Gaver-Stehfest algorithm with a varying number of
terms. The exact inversion is the red solid line while the
approximate inversion is given by .
34 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
Table 2.3: A collection of Laplace transform pairs suitable for testing numerical inversion strate-
gies.
Description F(s) f(t) Comment
Easy test 1/s
2
t
Control TF
1
(s + 2)(s + 3)
1
2
_
e
t
e
3t
_
Oscillatory
1

s
2
+ 1
J
0
(t) Bessel function, see Fig. 2.10(b) & Fig. 2.11.
Nasty
1

s
e
1/s 1

t
cos(

4t), See Fig. 2.12.


Figure 2.12: Testing the numerical inver-
sion of the Laplace transform e
1/s
/

s us-
ing the invlap routine.
0.5
0
0.5
1
1.5
f
(
t
)
L
1

exp(1/s)

0 5 10 15 20 25 30 35 40
10
6
10
4
10
2
10
0
e
r
r
o
r
time
integral in Eqn. 2.17, the Gaver-Stehfest algorithm and variants and the implementation invlap
require some care to get reasonable results. Unfortunately in practical cases it can be difcult to
choose suitable algorithmic tuning constants, which mean that it is difcult to generate any sort
of error bound on the computed curve.
2.5 Discretising with a sample and hold
In 2.1.1 we saw how the continuous analogue signal must be sampled to be digestible by the
process control computer. To analyse this sampling operation, we can approximate the real sam-
pler with an ideal sampler in cascade with a hold element such as given in Fig. 2.13.
When we sample the continuous function f(t), we get a sampled function f

(t), that is a series


of spikes that exist only at the sampling instant as shown in the middle plot of Fig. 2.13. The
sampled function, f

(t), is undened for the time between the sampling instants which is incon-
venient given that this is the bulk of the time. Obviously one sensible solution is to retain the
last sampled value until a new one is collected. During the sample period, the sampled value
f

(t) is the same as the last sampled value of the continuous function; f(kT + t) = f(kT) where
2.5. DISCRETISING WITH A SAMPLE AND HOLD 35

(t)
f(t)


`

`
`
`
```
analogue signal sampled signal sample & held signal
Hold

f
h
(t)
ideal sampler
Figure 2.13: Ideal sampler and zeroth-order hold
0 t < T shown diagrammatically in the third plot in Fig. 2.13. Since the last value collected is
stored or held, this sampling scheme is referred to as a zeroth-order hold. The zeroth-order refers
to the fact that the interpolating function used between adjacent values is just a horizontal line.
Higher order holds are possible, but the added expense is not typically justied even given the
improved accuracy.
We can nd the Laplace transform of the zeroth-order hold element by noting that the input is an
impulse function, and the output is a rectangular pulse of T duration, and y(t) high,
`

time, t
output
sample time, T
y(t)

0
.
Rectangular pulse
Directly applying the denition of the Laplace transform,
L{zoh} =
_

0
y(t) e
st
dt = y
t
_
T
0
1 e
st
dt
= y
t

1 e
sT
s
. .
zoh
we obtain the transform for the zeroth-order hold. In summary, the transformation of a continu-
ous plant G(s) with zero-order hold is
G(z) = (1 z
1
) Z
_
G(s)
s
_
(2.18)
Note that this is not the same as simply the z-transform of G(s).
36 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
Suppose we wish to discretise the continuous plant
G(s) =
8
s + 3
(2.19)
with a zero-order hold at a sample time of T = 0.1 seconds. We can do this analytically using ta-
bles, or we can trust it to MATLAB. First we try analytically and apply Eqn 2.18 to the continuous
process. The difcult bit is the z-transformation. We note that
Z
_
G(s)
s
_
=
8
3
Z
_
3
s(s + 3)
_
(2.20)
and that this is in the form given in tables of z-transforms such as [148, p50], part of which is
repeated here
X(s) X(z)
a
s(s+a)
(1e
aT
)z
1
(1z
1
)(1e
aT
z
1
)
Inverting using the tables, and substituting in Eqn 2.18 gives
G(z) = (1 z
1
)
_
G(s)
s
_
=
8
3
(1 z
1
) Z
_
3
s(s + 3)
_
=
8
3
(1 z
1
)
(1 e
3T
)z
1
(1 z
1
)(1 e
3T
z
1
)
=
8
3

(1 e
0.3
)z
1
(1 e
0.3
z
1
)
=
0.6912z
1
1 0.7408z
1
, for T = 0.1 (2.21)
We can repeat this conversion numerically using the continuous-to-discrete function, c2d. We
rst dene the continuous system as an LTI object, and then convert to the discrete domain using
a zeroth order hold.
>>sysc = tf(8,[1 3]) % Continuous systemGc(s) = 8/(s + 3)
3 Transfer function:
8
-----
s + 3
8 >> sysd = c2d(sysc,0.1,'zoh') % convert to discrete using a zoh
Transfer function:
0.6912
----------
13 z - 0.7408
Sampling time: 0.1
which once again is Eqn. 2.21. In fact we need not specify the zoh option when constructing a
discrete model using c2d or even in SIMULINK, since a zeroth-order hold is employed by default.
Methods for doing the conversion symbolically are given next in section 2.5.1.
2.5. DISCRETISING WITH A SAMPLE AND HOLD 37
2.5.1 Converting Laplace transforms to z-transforms
In many practical cases we may already have a continuous transfer function of a plant or con-
troller which we wish to discretise. In these circumstances we would like to convert from a con-
tinuous transfer function in s, (such as say a Butterworth lter) to an equivalent discrete transfer
function in z. The two common ways to do this are:
1. Analytically by rst inverting the Laplace transformback to the time domain, and then take
the (forward) z-transform.
G(z)
def
= Z
_
L
1
{G(s)}
_
(2.22)
2. or by using an approximate method known as the bilinear transform.
The bilinear method whilst approximate has the advantage that it just involves a simple algebraic
substitution for s in terms of z. The bilinear transform is further covered in 2.5.2.
The formal method we have already seen previously, but since it is such a common operation, we
can write a symbolic MATLAB script to do it automatically for us for any given transfer function.
However we should be aware whether the transformation includes the sample and hold, or if
that inclusion is left up to the user.
Listing 2.1 converts a Laplace expression to a z-transformexpression without a zeroth-order hold.
Including the zeroth-order hold option is given in Listing 2.2.
Listing 2.1: Symbolic Laplace to z-transform conversion
function Gz = lap2ztran(G)
% Convert symbolically G(s) to G(z)
syms t k T z
Gz = simplify(ztrans(subs(ilaplace(G),t,k
*
T),k,z));
5 return
Listing 2.2: Symbolic Laplace to z-transform conversion with ZOH
function Gz = lap2ztranzoh(G)
% Convert symbolically G(s) to G(z) with a ZOH.
syms s t k T z
Gz = simplify((1-1/z)
*
ztrans(subs(ilaplace(G/s),t,k
*
T),k,z));
5 return
We can test the conversion routines in Listings 2.1 and 2.2 on the trial transfer function G(s) =
1/s
2
.
>> Gz =lap2ztran(1/s2); % Convert G(s) = 1/s
2
to the discrete domain G(z).
>> pretty(Gz)
T z
--------
5 2
(z - 1)
>> Gz = lap2ztranzoh(1/s2);% Do the conversion again, but this time include a ZOH.
>> pretty(Gz)
10 2
38 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
(z + 1) T
1/2 ----------
2
(z - 1)
2.5.2 The bilinear transform
The analytical one step backone step forward procedure while strictly correct, is a little tedious,
so a simpler, albeit approximate, way to transformbetween the Laplace domain and the z-domain
is to use the bilinear transform method, sometimes known as Tustins method. By denition
z
def
= e
sT
or z
1
= e
sT
, (from Eqn. 2.10). If we substituted directly natural logs would appear in
the rational polynomial in z,
s =
ln(z)
T
(2.23)
making the subsequent analysis difcult. For example the resulting expression could not be
transformed into a difference equation which is what we desire.
We can avoid the troublesome logarithmic terms by using a Pad e approximation for the expo-
nential term as
e
sT
= z
1

2 sT
2 +sT
(2.24)
or alternatively
s
2
T
(1 z
1
)
(1 +z
1
)
(2.25)
This allows us to transform a continuous time transfer function G(s) to a discrete time transfer
function G(z),
G(z) = G(s)|
s=
2
T
1z
1
1+z
1
(2.26)
Eqn. 2.26 is called the bilinear transform owing to the linear terms in both the numerator and
denominator and it has the advantage that a stable continuous time lter will be stable in the dis-
crete domain. The disadvantage is that the algebra required soon becomes unwieldy if attempted
manually. Other transforms are possible and are discussed in 4-2 p308 of Ogata [148]. Always
remember that this transformation is approximate, being equivalent to a trapezoidal integration.
Here we wish to approximately discretise the continuous plant
G(s) =
1
(s + 1)(s + 2)
at a sample time of T = 0.1 using the bilinear transform. The discrete approximate transfer
function is obtained by substituting Eqn. 2.25 for s and simplifying.
G(z) =
1
(s + 1)(s + 2)

s=
2
T
1z
1
1+z
1
=
1
_
2
T
1z
1
1+z
1
+ 1
_ _
2
T
1z
1
1+z
1
+ 2
_ =
1
2
T
2
(z + 1)
2
(2T
2
+ 6T + 4)z
2
+ (4T
2
8)z + 2T
2
6T + 4
=
0.0022z
2
+ 0.0043z + 0.0022
z
2
1.723z + 0.74
for T = 0.1
2.5. DISCRETISING WITH A SAMPLE AND HOLD 39
Since this transformation is just an algebraic substitution, it is easy to execute it symbolically in
MATLAB.
1 >> syms s T z
>> G = 1/(s+1)/(s+2);
>> Gd = simplify(subs(G,s,2/T
*
(1-1/z)/(1+1/z)))
Gd =
1/2
*
T2
*
(z+1)2/(2
*
z-2+T
*
z+T)/(z-1+T
*
z+T)
6 >> pretty(Gd)
2 2
T (z + 1)
1/2 -------------------------------------
(2 z - 2 + T z + T) (z - 1 + T z + T)
Alternatively we could use MATLAB to numerically verify our symbolic solution.
>> G = zpk([],[-1 -2],1)
Zero/pole/gain:
1
-----------
5 (s+1) (s+2)
>> T=0.1;
>> Gd = c2d(G,T,'tustin')
10 Zero/pole/gain:
0.0021645 (z+1)2
---------------------
(z-0.9048) (z-0.8182)
15 Sampling time: 0.1
>> tf(Gd)
Transfer function:
0.002165 z2 + 0.004329 z + 0.002165
20 ------------------------------------
z2 - 1.723 z + 0.7403
Sampling time: 0.1
The bilinear command in the SIGNAL PROCESSING toolbox automatically performs this map-
ping from s to z. This is used for example in the design of discrete versions of common analogue
lters such as the Butterworth or Chebyshev lters. These are further described in 5.2.3.
Problem 2.3 1. Use Tustins method (approximate z-transform) to determine the discrete time
response of
G(s) =
4
(s + 4)(s + 2)
to a unit step change in input by long division. The sample time T = 1 and solve for 7 time
steps. Compare with the exact solution.
40 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
The frequency response characteristics of a hold element
The zeroth order hold element modies the transfer function, so consequently inuences the
closed loop stability, and frequency characteristics of the discrete process. We can investigate this
inuence by plotting the discrete Bode and Nyquist plots for a sampled process with and without
a zeroth order hold.
Suppose we have the continuous process
G
p
(s) =
1.57
s(s + 1)
(2.27)
which is sampled at a frequency of = 4 rad/s. (This corresponds to a sample time of T = /2
seconds.) First we will ignore the zeroth order hold and transform Eqn 2.27 to the z domain by
using tables such as say Table 21, p49 #8 in DCS.
G
p
(z) = 1.57
(1 e
aT
)z
1
(1 z
1
)(1 e
aT
z
1
)
(2.28)
=
1.243z
(z 1)(z 0.208)
(2.29)
To get the discrete model with the zeroth order hold, we again use Eqn 2.18, and the tables. Doing
this, in a similar manner to what was done for Eqn 2.21, we get
G
h0
G
p
(z) =
1.2215z + 0.7306
(z 1)(z 0.208)
(2.30)
Now we can plot the discrete frequency responses using MATLAB to duplicate the gure given
in [110, p649] as shown in Fig. 2.14.
In the listing below, I rst construct the symbolic discrete transfer function, substitute the sam-
pling time, then convert to a numeric rational polynomial. This rational polynomial is now in a
suitable form to be fed to the control toolbox routines such as bode.
syms s T z
2 G = 1.57/(s
*
(s+1))
Gd = lap2ztran(G) % convert to a z-transform without ZOH
Gd2 = subs(Gd,T,pi/2)
[num,den] = numden(Gd2) % extract top & bottom lines
7 B= sym2poly(num); A = sym2poly(den); % convert to polynomials
Gd = tf(B,A,pi/2) % construct a transfer function
To generate the discretisation including the zeroth-order hold, we could use the symbolic lap2ztranzoh
routine given in Listing 2.2, or we could use the built-in c2d function.
1 [num,den] = numden(G) % extract numerator & denominator
Bc= sym2poly(num); Ac = sym2poly(den);
Gc = tf(Bc,Ac)
Gdzoh = c2d(Gc,pi/2,'zoh')
6
bode(Gc,Gd,Gdzoh)
legend('Continuous','No ZOH','with ZOH')
2.5. DISCRETISING WITH A SAMPLE AND HOLD 41
In this case I have used vanilla Bode function which will automatically recognise the difference
between discrete and continuous transfer functions. Note that it also automatically selects both
a reasonable frequency spacing, and inserts the Nyquist frequency at f
N
= 1/2T = 1/Hz or

N
= 2 rad/s.
These Bode plots shown in Fig. 2.14, or the equivalent Nyquist plots, show that the zeroth order
hold destabilises the system. The process with the hold has a larger peak resonance, and smaller
gain and phase margins.
100
50
0
50
100
M
a
g
n
i
t
u
d
e

(
d
B
)
10
2
10
1
10
0
10
1
10
2
225
180
135
90
P
h
a
s
e

(
d
e
g
)
Bode Diagram
Frequency (rad/sec)
Continuous
No ZOH
with ZOH
Figure 2.14: The Bode dia-
gram showing the difference
between the continuous plant,
a discretisation with and with-
out the zeroth-order hold.
Of course we should compare the discrete Bode diagrams with that for the original continuous
process. The MATLAB bode function is in this instance the right tool for the job, but I will con-
struct the plot manually just to demonstrate how trivial it is to substitute s = i, and compute
the magnitude and phase of G(i) for all frequencies of interest.
num = 1.57; % Plant of interest G(s) = 1.57/(s
2
+s + 0)
2 den = [1 1 0];
w = logspace(-2,1)'; % Select frequency range of interest 10
2
< < 10
1
rad/s.
iw = 1i
*
w; % s = j
G = polyval(num,iw)./polyval(den,iw); % G(s = j)
loglog(w,abs(G)) % Plot magnitude |G(i)|, see Fig. 2.15.
7 semilogx(w,angle(G)
*
180/pi) % and phase (i)
We can compare this frequency response of the continuous system with the discretised version
in Fig. 2.14.
42 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
Figure 2.15: A frequency response plot of
G(s) where s = j constructed manually
without using the bode command.
10
2
10
1
10
0
10
1
10
5
10
0
10
5
A
R
10
2
10
1
10
0
10
1
200
150
100
50
frequency [rad/s]
P
h
a
s
e

l
a
g


[
d
e
g
]
2.6 Discrete root locus diagrams
The root locus diagram is a classical technique used to study the characteristic response of trans-
fer functions to a single varying parameter such as different controller gains. Traditionally the
construction of root locus diagrams required tedious manual algebra. However now modern
programs such as MATLAB can easily construct reliable root locus diagrams which makes the
design procedure far more attractable.
For many controlled systems, the loop is stable for small values of controller gain K
c
, but unstable
for a gain above some critical value K
u
. It is therefore natural to ask how does the stability (and
response) vary with controller gain? The root locus gives this information in a plot form which
shows how the poles of a closed loop system change as a function of the controller gain K
c
.
Given a process transfer function G and a controller K
c
Q, the closed loop transfer function is the
familiar
G
cl
=
K
c
Q(z)G(z)
1 +K
c
Q(z)G(z)
(2.31)
where the stability is dependent on the denominator (characteristic equation) 1 + K
c
Q(z)G(z),
which is of course itself dependent on the controller gain K
c
. Plotting the roots of
1 +K
c
Q(z)G(z) = 0 (2.32)
as a function of K
c
creates the root locus diagram.
In this section
4
we will plot the discrete root locus diagram for the process
G
p
(z) =
0.5(z + 0.6)
z
2
(z 0.4)
(2.33)
which is a discrete description of a rst order process with dead time. We also add a discrete
integral controller of the form
G
c
(z) = K
c
z
z 1
We wish to investigate the stability of the characteristic equation as a function of controller gain.
4
Adapted from [70, p124]
2.7. MULTIVARIABLE CONTROL AND STATE SPACE ANALYSIS 43
With no additional arguments apart from the transfer function, rlocus will draw the root locus
selecting sensible values for K
c
automatically. For this example, I will constrain the plots to have
a square aspect ratio, and I will overlay a grid of constant shape factor and natural frequency

n
using the zgrid function.
Q = tf([1 0],[1 -1],-1); % controller without gain
G = tf(0.5
*
[1 0.6],[1 -0.4 0 0],-1); % plant
3
Gol = Q
*
G; % open loop
zgrid('new');
xlim([-1.5 1.5]); axis equal %
rlocus(Gol) % plot root locus
8 rlocfind(Gol)
Once the plot such as Fig. 2.16 is on the screen, I can use rlocfind interactively to establish the
values of K
c
at different critical points in Fig. 2.16. Note that the values obtained are approximate.
Pole description Name K
c
border-line stability ultimate gain 0.6
cross the = 0.5 line design gain 0.2
critically damped breakaway gain 0.097
overdamped,
n
= 36

0.09
Once I select the gain that corresponds to the = 0.5 crossing, I can simulate the closed loop step
response.
Gol.Ts = 1; % Set sampling time
2 Kc = 0.2 % A gain where we expect = 0.5
step(Kc
*
Gol/(1 + Kc
*
Gol),50) % Simulate closed loop
A comparison of step responses for various controller gains is given in Fig. 2.17. The curve in
Fig. 2.17 with K
c
= 0.2 where 0.5 exhibits an overshoot of about 17% which agrees well with
the expected value for a second order response with a shape factor of = 0.5. The other curves
do not behave exactly as one would expect since our process is not exactly a second order transfer
function.
2.7 Multivariable control and state space analysis
In the mid 1970s, the western world suffered an oil shock when the petroleum producers and
consumers alike realised that oil was a scarce, nite and therefore valuable commodity. This had
a number of important implications, and one of these in the chemical processing industries was
the increased use of integrated heat plants. This integration physically ties separate parts of the
plant together and demands a corresponding integrated or plant-wide control system. Clas-
sical single-input/single-output (SISO) controller design techniques such as transfer functions,
frequency analysis or root locus were found to be decient, and with the accompanying devel-
opment of affordable computer control systems that could administer hundreds of inputs and
outputs, many of which were interacting, nonlinear and time varying, new tools were required
and the systematic approach offered by state-space analysis became popular.
44 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
1.5 1 0.5 0 0.5 1 1.5
1.5
1
0.5
0
0.5
1
1.5
0.9/T
0.8/T
0.7/T
0.6/T
0.5/T
0.4/T
0.1/T
0.2/T
0.3/T
0.7/T
0.5/T
0.4/T
0.3/T
0.2/T
0.1/T
/T
0.8
0.8/T
0.9
0.6/T
0.1
0.9/T
0.6
/T
0.7
0.2
0.3
0.4
0.5
Root Locus
Real Axis
I
m
a
g
i
n
a
r
y

A
x
i
s
Ultimate
gain
Design gain
breakaway
gain
Figure 2.16: The discrete root locus of Eqn. 2.33 plotted using rlocus. See also Fig. 2.17 for the
resultant step responses for various controller gains.
Figure 2.17: Various discrete closed loop re-
sponses for gains K
c
= 0.6, 0.2 and 0.1. Note that
with K
c
= 0.6 we observe a response on the sta-
bility boundary, while for K
c
= 0.1 we observe
a critically damped response as anticipated from
the root locus diagram given in Fig. 2.16.
0
1
2


0
1
2


0 10 20 30 40 50
0
1
2
time [s]


K
c
=0.1
K
c
=0.2
K
c
=0.6
2.7. MULTIVARIABLE CONTROL AND STATE SPACE ANALYSIS 45
Many physical processes are multivariable. A binary distillation column such as given in Fig. 2.18
typically has four inputs; the feed ow and composition and reux and boil-up rates, and at least
four outputs, the product ow and compositions. To control such an interacting system, mul-
tivariable control such as state space analysis is necessary. The Wood-Berry distillation column
model (Eqn 3.24) and the Newell & Lee evaporator model are other examples of industrial pro-
cess orientated multivariable models.
Distillation
column

distillate rate, D
tray 5 temperature, T
5
Bottoms rate, B
Bottoms comp., x
B
Outputs

Inputs
tray 15 temperature, T
15
_
Feed rate

_
reux rate
reboiler heat
Disturbances
Feed composition

Manpipulated
variables
distillation composition, x
D
Figure 2.18: A binary distillation column with multiple inputs and multiple outputs
State space analysis only considers rst order differential equations. To model higher order sys-
tems, one needs only to build systems of rst order equations. These equations are conveniently
collected, if linear, in one large matrix. The advantage of this approach is a compact represen-
tation, and a wide variety of good mathematical and robust numerical tools to analyse such a
system.
A few words of caution
The state-space analysis is sometimes referred to as the modern control theory, despite the fact
that is has been around since the early 1960s. However by the end of the 1970s, the promise of
the academic advances made in the previous decade were turning out to be ill-founded, and it
was felt that this new theory was ill-equipped to cope with the practical problems of industrial
control. In many industries therefore, Process Control attracted a bad smell. Writing a decade
still later in 1987, Morari in [136] attempts to rationalise why this disillusionment was around at
the time, and whether the subsequent decade of activity alleviated any of the concerns. Morari
summarises that commentators such as [69] considered theory such as linear multivariable con-
trol theory, (i.e. this chapter) which seemed to promise so much, actually delivered very little
and had virtually no impact on industrial practice. There were other major concerns such as
the scarcity of good process models, the increasing importance of operating constraints, operator
acceptance etc, but the poor track record of linear multivariable control theory landed top billing.
Incidentally, Morari writing almost a decade later still in 1994, [139], revisits the same topic giving
the reader a nice linear perspective.
46 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
2.7.1 States and state space
State space equations are just a mathematical equivalent way of writing the original common dif-
ferential equation. While the vector/matrix construction of the state-space approach may initially
appear intimidating compared with high order differential equations, it turns out to be more con-
venient and numerically more robust to manipulate these equations when using programs such
as MATLAB. In addition the state-space form can be readily expanded into multivariable systems
and even nonlinear systems.
The state of a system is the smallest set of values such that knowledge of these values, knowledge
of any future inputs and the governing dynamic equations, it is possible to predict everything
about the future (and past) output of the system. The state variables are often written as a column
vector of length n and denoted x. The state space is the n dimensional coordinate space that all
possible state vectors must lie in.
The input to a dynamic system is the vector of m input variables, u, that affect the state vari-
ables. Historically control engineers further subdivided the input variables into those they could
easily and consciously adjust (known as control or manipulated variable inputs), and those vari-
ables that may change, but are outside the engineers immediate sphere of inuence (like the
weather) known as disturbance variables. The number of input variables need not be the same as
the number of state variables, and indeed m is typically less than n.
Many mathematical control text books follow a standard nomenclature. Vectors are written using
a lower case bold font such as x, and matrices are written in upper case bold such as A.
The state space equations are the n ordinary differential equations that relate the state derivatives
to the state themselves, the inputs if any, and time. We can write these equations as
x = f (x, u, t) (2.34)
where f () is a vector function meaning that both the arguments and the result are vectors. In
control applications, the input is given by a control law which is often itself a function of the
states,
u = h(x) (2.35)
which if we substitute into Eqn. 2.34, we get the closed loop response
x = f (x, h(x), t)
For autonomous closed loop systems there is no explicit dependence on time, so the differential
equation is simply
x = f (x) (2.36)
For the continuous linear time invariant case, Eqn. 2.34 simplies to
x = Ax +Bu (2.37)
or in discrete form at time t = kT
x
k+1
= x
k
+u
k
(2.38)
where the state vector x is an (n 1) vector, or alternatively written as x
n
, the control input
vector has m elements, or u
m
. The model (transition) matrix is (n n) or A,
nn
, and
the control or input matrix is (n m) or B,
nm
.
Block diagrams of both the continuous and discrete formulations of the state-space model are
shown in Fig. 2.19. Such a form is suitable to implement state-space systems in a simulator such
as SIMULINK for example.
2.7. MULTIVARIABLE CONTROL AND STATE SPACE ANALYSIS 47

x
k+1 x(t)
z
1
_

A

Continuous plant

x
B +
`

u(t)
u
k

Discrete plant

x
k
+
`

Figure 2.19: A block diagram of a state-space dynamic system, (a) continuous system: x = Ax +
Bu, and (b) discrete system: x
k+1
= x
k
+u
k
. (See also Fig. 2.20.)
The output or measurement vector, y, are the variables that are directly measured from the operat-
ing plant, since often the true states cannot themselves be directly measured. These outputs are
related to the states by
y = g(x) (2.39)
If the measurement relation is linear, then
y = Cx (2.40)
where the r element measurement vector is
r
, and the measurement matrix is sized C
rn
.
Sometimes the input may directly affect the output bypassing the process, in which case the full
linear system in state space is described by,
x = Ax +Bu
y = Cx +Du
(2.41)
Eqn. 2.41 is the standard starting point for the analysis of continuous linear dynamic systems, and
are shown in block diagram form in Fig. 2.20. Note that in the diagram, the internal state vector
(bold lines), has typically more elements than either the input or output vectors (thin lines). The
diagram also highlights the fact that as an observer to the plant, we can relatively easily measure
our outputs (or appropriately called measurements), we presumably know our inputs to the
plant, but we do not necessarily have access to the internal state variables since they are always
contained inside the dashed box in Fig. 2.20. Strategies to estimate these hidden internal states is
known as state estimation and are described in section 9.5.
2.7.2 Converting differential equations to state-space form
If we have a collection or system of interlinked differential equations, it is often convenient and
succinct to group them together in a vector/matrix collection. Alternatively if we start with an
nth order differential equation, for the same reasons it is advisable to rewrite this as a collection
of n rst order differential equations known as Cauchy form.
Given a general linear nth order differential equation
y
(n)
+a
1
y
(n1)
+a
2
y
(n2)
+ +a
n1
y +a
n
y = b
0
u
(n)
+b
1
u
(n1)
+ +b
n1
u +b
n
u (2.42)
48 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
+

x(t)

_
-
y(t)
A

C
-

x
B

6
+
-
u(t)

Figure 2.20: A complete block diagram of a state-space dynamic system with output and direct
measurement feed-through, Eqn. 2.41.
by inspection, we can create the equivalent transfer function as
Y (s)
U(s)
=
b
0
s
n
+b
1
s
n1
+ +b
n1
s +b
n
s
n
+a
1
s
n1
+ +a
n1
s +a
n
s
(2.43)
We can cast this transfer function (or alternatively the original differential equation) into state
space in a number of equivalent forms. They are equivalent in the sense that the input/output
behaviour is identical, but not necessarily the internal state behaviour.
The controllable canonical form is
_

_
x
1
x
2
.
.
.
x
n1
x
n
_

_
=
_

_
0 1 0 0
0 0 1 0
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
0 0 0 1
a
0
a
1
a
2
a
n1
_

_
_

_
x
1
x
2
.
.
.
x
n1
x
n
_

_
+
_

_
0
0
.
.
.
0
1
_

_
u (2.44)
y =
_
b
n
a
n
b
0
.
.
. b
n1
a
n1
b
0
.
.
.
.
.
. b
1
a
1
b
0
_
_

_
x
1
x
2
.
.
.
x
n1
x
n
_

_
+b
0
u (2.45)
which is useful when designing pole-placement controllers. The observable canonical form is
_

_
x
1
x
2
.
.
.
x
n
_

_
=
_

_
0 0 0 a
n
1 0 0 a
n1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
0 0 1 a
1
_

_
_

_
x
1
x
2
.
.
.
x
n
_

_
+
_

_
b
n
a
n
b
0
b
n1
a
n1
b
0
.
.
.
b
1
a
1
b
0
_

_
u (2.46)
y =
_
0 0 0 1

_
x
1
x
2
.
.
.
x
n1
x
n
_

_
+b
0
u (2.47)
and is useful when designing observers.
2.7. MULTIVARIABLE CONTROL AND STATE SPACE ANALYSIS 49
If the transfer function dened by Eqn. 2.43 has real and distinct factors,
Y (s)
U(s)
=
b
0
s
n
+b
1
s
n1
+ +b
n1
s +b
n
(s +p
1
)(s +p
2
) (s +p
n
)
= b
0
+
c
1
s +p
1
+
c
2
s +p
2
+ +
c
n
s +p
n
we can derive an especially elegant state-space form
_

_
x
1
x
2
.
.
.
x
n
_

_
=
_

_
p
1
0
p
2
.
.
.
0 p
n
_

_
_

_
x
1
x
2
.
.
.
x
n
_

_
+
_

_
1
1
.
.
.
1
_

_
u (2.48)
y =
_
c
1
c
2
c
n

_
x
1
x
2
.
.
.
x
n
_

_
+b
0
u (2.49)
that is purely diagonal. As evident from the diagonal system matrix, this system is totally decou-
pled and possess the best numerical properties for simulation. For systems with repeated roots,
or complex roots, or both, the closest we can come to a diagonal form is the block Jordan form.
We can interconvert between all these above forms using the MATLAB canon command.
>> G = tf([5 6],[1 2 3 4]); % Dene transfer function G = (5s
2
+ 6s)/(s
3
+ 2s
2
+ 3s + 4)
2
>> canon(ss(G),'compan') % Convert TF to the companion or observable canonical form
a =
x1 x2 x3
7 x1 0 0 -4
x2 1 0 -3
x3 0 1 -2
b =
12 u1
x1 1
x2 0
x3 0
17 c =
x1 x2 x3
y1 0 5 -4
d =
22 u1
y1 0
These transformations are discussed further in [148, p515]. MATLAB uses a variation of this form
when converting from a transfer function to state-space in the tf2ss function.
50 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
2.7.3 Interconverting between state space and transfer functions
The transfer function form and the state-space form are, by in large, equivalent, and we can con-
vert from one representation to the other. Starting with our generic state-space model, Eqn. 2.37,
x = Ax +Bu (2.50)
with initial condition x(0) = 0 and taking Laplace transforms gives
sx(s) = Ax(s) +Bu(s)
x(s) (sI A) = Bu(s)
x(s) = (sI A)
1
B
. .
Gp(s)
u(s) (2.51)
where G
p
(s) is a matrix of expressions in s and is referred to as the transfer function matrix. The
MATLAB command ss2tf (state-space to transfer function) performs this conversion.
State-space to transfer function conversion
Suppose we wish to convert the following state-space description to transfer function form.
x =
_
7 10
3 4
_
x +
_
4 1
2 3
_
u (2.52)
From Eqn. 2.51, the transfer function matrix is dened as
G
p
(s) = (sI A)
1
B
=
_
s
_
1 0
0 1
_

_
7 10
3 4
__
1
_
4 1
2 3
_
=
_
(s + 7) 10
3 (s 4)
_
1
_
4 1
2 3
_
(2.53)
Now at this point, the matrix inversion in Eqn. 2.53 becomes involved because of the presence of
the symbolic s in the matrix. Inverting the symbolic matrix expression gives the transfer function
matrix.
G
p
(s) =
1
(s + 2)(s + 1)
_
s 4 10
3 s + 7
_ _
4 1
2 3
_
=
_

_
4
s + 2

s + 26
s
2
+ 3s + 2
2
s + 2

3(6 +s)
s
2
+ 3s + 2
_

_
We can directly apply Eqn. 2.51 using the symbolic toolbox in MATLAB.
>> syms s
2 >> A = [-7 10; -3 4]; B = [4 -1; 2 -3];
>> G = (s
*
eye(2)-A)\B % Pulse transfer function Gp(s) = (sI A)
1
B.
G =
[ 4/(s+2), -(s+26)/(2+s2+3
*
s)]
[ 2/(s+2), -3
*
(s+6)/(2+s2+3
*
s)]
2.7. MULTIVARIABLE CONTROL AND STATE SPACE ANALYSIS 51
The method for converting from a state space description to a transfer function matrix described
by Eqn. 2.51 is not very suitable for numerical computation owing to the symbolic matrix in-
version required. However [174, p35] describes a method due to Faddeeva that is suitable for
numerical computation in MATLAB.
Faddeevas algorithm to convert a state-space description, x = Ax + Bu into transfer function
form, G
p
(s).
1. Compute a, the characteristic equation of the n n matrix A. (Use poly in MATLAB.)
2. Set E
n1
= I.
3. Compute recursively the following n 1 matrices
E
n1k
= AE
nk
+a
nk
I, k = 1, 2, , n 1
4. The transfer function matrix is then given by
G
p
(s) =
s
n1
E
n1
+s
n2
E
n2
+ +E
0
a
n
s
n
+a
n1
s
n1
+ +a
1
s +a
0
B (2.54)
Expressed in MATLAB notation, an (incomplete) version of the algorithm is
a = poly(A); % characteristic polynomial
n = length(a); % dimension of system
I = eye(n-1); E=I;
4 for i=n-2:-1:1
E = A
*
E + a(i+1)
*
I % collect & printout
end % for
Note however that it is also possible to use ss2tf, although since MATLAB (version 4) cannot use
3D matrices, we need to call this routine n times to build up the entire transfer function matrix.
We can repeat the state-space to transfer function example, Eqn. 2.52, given on page 50 using
Faddeevas algorithm.
_
x
1
x
2
_
=
_
7 10
3 4
_
x +
_
4 1
2 3
_
u
We start by computing the characteristic polynomial of A
a(s) = s
2
+ 3s + 2 = (s + 1)(s + 2)
and with n = 2 we can compute
E
1
=
_
1 0
0 1
_
, E
0
=
_
5 1
2 2
_
Following Eqn. 2.54 gives a matrix of polynomials in s,
(sI A)
1
=
1
s
2
+ 3s + 2
_
s
_
1 0
0 1
_
+
_
4 10
3 7
__
=
1
(s + 1)(s + 2)
_
s 4 10
3 s + 7
_
52 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
which we can recognise as the same expression as we found using the symbolic matrix inverse
on page 50. All that remains is to post multiply by Bto obtain the pulse transfer function matrix.
Finally, we can also use the control toolbox for the conversion from state-space to transfer func-
tion form. First we construct the state-space form,
A = [-7 10; -3,4]; B = [4 -1; 2 -3]; % Continuous state-space example fromEqn. 2.52.
C = eye(size(A));
sys = ss(A,B,C,[]) % construct system object
where in this case if leave out the D matrix, MATLAB assumes no direct feed though path. We
now can convert to the transfer function form:
>> sys_tf = minreal(tf(sys)) % Convert to transfer function & remember to cancel common
factors
2
Transfer function from input 1 to output...
4
#1: -----
s + 2
7
2
#2: -----
s + 2
12 Transfer function from input 2 to output...
-s - 26
#1: -------------
s2 + 3 s + 2
17 -3 s - 18
#2: -------------
s2 + 3 s + 2
Once again we get the same pulse transfer function matrix.
Transfer function to state space
To convert in the reverse direction, we can use the MATLAB function tf2ss (transfer function to
state space) thus converting an arbitrary transfer function description to the state space format of
Eqn 2.37. For example starting with the transfer function
G(s) =
(s + 3)(s + 4)
(s + 1)(s + 2)(s + 5)
=
s
2
+ 7s + 12
s
3
+ 8s + 17s + 10
we can convert to state-space form using tf2ss.
1 >>num = [1 7 12]; % Numerator: s
2
+ 7s + 12
>>den = [1 8 17 10]; % Denominator: s
3
+ 8s + 17s + 10
>>[A,B,C,D] = tf2ss(num,den) % convert to state-space
2.7. MULTIVARIABLE CONTROL AND STATE SPACE ANALYSIS 53
which returns the following four matrices
A =
_
_
8 17 10
1 0 0
0 1 0
_
_
, B =
_
_
1
0
0
_
_
C =
_
1 7 12

, D = 0
This form is a variation of the controllable canonical form described previously in 2.7.2. This
is not the only state-space realisation possible however as the CONTROL TOOLBOX will return a
slightly different ABCD package
>> Gc = tf([1 7 12],[1 8 17 10]) % Transfer function in polynomial form
2 Transfer function:
s2 + 7 s + 12
-----------------------
s3 + 8 s2 + 17 s + 10
7 >>[A,B,C,D] = ssdata(Gc) % extract state-space matrices
A =
-8.0000 -4.2500 -1.2500
4.0000 0 0
0 2.0000 0
12 B =
2
0
0
C =
17 0.5000 0.8750 0.7500
D =
0
Alternatively we could start with zero-pole-gain form and obtain yet another equivalent state-
space form.
1 G = zpk([-3 -4],[-1 -2 -5],1) % Transfer function model in factored format
Gss = ss(G)
A later section, (2.7.4) shows how we can convert between equivalent dynamic forms. The four
matrices in the above description form the linear dynamic system as given in Eqn. 2.41. We can
concatenate these four matrices into one large block thus obtaining a shorthand way of storing
these equations

G =
A
(n n)

B
(n m)
C
(p n)

p
D
(p m)
`
n
m
# of states
# of measurements
# of inputs
`
54 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
which is often called a packed matrix notation of the quadruplet (A,B,C,D). If you get confused
about the appropriate dimensions of A, B etc, then this is a handy check, or alternatively you
can use the diagnostic routine abcdchk. Note that in practice, the D matrix is normally the
zero matrix since the input does not generally effect the output immediately without rst passing
through the system dynamics.
2.7.4 Similarity transformations
The state space description of a differential equation is not unique. We can transform from one
description to another by using a linear invertible transformation such as x = Tz. Geometrically
in 2 dimensions, this is equivalent to rotating the axes or plane. When one rotates the axes, the
inter-relationship between the states do not change, so the transformation preserves the dynamic
model.
Suppose we have the dynamic system
x = Ax +Bu (2.55)
which we wish to transform in some manner using the non-singular transformation matrix, T,
where x = Tz. Naturally the reverse transformation z = T
1
x exists because we have restricted
ourselves to consider only the cases when the inverse of T exists. Writing Eqn. 2.55 in terms of
our new variable z we get
d(Tz)
dt
= ATz +Bu
z = T
1
ATz +T
1
Bu (2.56)
Eqn 2.56 and Eqn 2.55 represent the same dynamic system. They have the same eigenvalues
hence the similarity transform, but just a different viewpoint. The mapping from A to T
1
AT
is called a similarity transform and preserves the eigenvalues. These two matrices are said to be
similar. The proof of this is detailed in [86, p300] and [148, p513514].
The usefulness of these types of transformations is that the dynamics of the states are preserved
(since the eigenvalues are the same), but the shape and structure of the system has changed.
The motivation is that for certain operations (control, estimation, modelling), different shapes
are more convenient. A pure, (or nearly), diagonal shape of the A matrix for example has much
better numerical properties than a full matrix. This also has the advantage that less computer
storage and fewer operations are needed.
To convert a system to a diagonal form, we use the transformation matrix T, where the columns
of T are the eigenvectors of A. Systems where the model (A) matrix is diagonal are especially
easy to manipulate. We can nd the eigenvectors T and the eigenvalues e of a matrix A using
the eig command, and construct the new transformed, and hopefully diagonal system matrix,
[T,e] = eig(A) % nd eigenvectors & eigenvalues of A
V = T\A
*
T % New system matrix, T
1
AT, or use canon
Another use is when testing new control or estimation algorithms, it is sometimes instructive to
devise non-trivial systems with specied properties. For example you may wish to use as an
example a 3 3 system that is stable and interacting, and has one over-damped mode and two
oscillatory modes. That is we wish to construct a full A matrix with specied eigenvalues. We
can use the similarity transformations to obtain these models.
2.7. MULTIVARIABLE CONTROL AND STATE SPACE ANALYSIS 55
Other useful transformations such as the controllable and observable canonical forms are covered
in [148, 64 p646 ]. The MATLAB function canon can convert state-space models to diagonal
or observable canonical form (sometimes known as the companion form). Note however the
help le for this routine discourages the use of the companion form due to its numerical ill-
conditioning.
MATLAB comes with some utility functions to generate test models such as ord2 which gener-
ates stable second order models of a specied damping and natural frequency, and rmodel is a
exible general stable random model builder or arbitrary order.
2.7.5 Interconverting between transfer functions forms
The previous section described how to convert between different representations of linear dy-
namic systems such as differential equations, transfer functions and state-space descriptions.
This section describes the much simpler task of converting between the different ways we can
write transfer functions.
Modellers tend to think in continuous time systems, G(s), and in terms of process gain and time
constants, so will naturally construct transfer functions of the form
K
i
(
i
s + 1)

j
(
j
s + 1)
(2.57)
where the all the variables of interest such as time constants
j
are immediately apparent. On
the other hand, system engineers tend to think in terms of poles and zeros, so naturally construct
transfer functions in the form
K

i
(s +z
i
)

j
(s +p
i
)
(2.58)
where once again the poles, p
j
, and zeros z
i
are immediately apparent. This is the form that
MATLAB uses in the zeros-pole-gain format, zpk.
Finally the hardware engineer would prefer to operate in the expanded polynomial form, (par-
ticularly in discrete cases), where the transfer function is of the form
b
m
s
m
+b
m1
s
m1
+ +b
0
s
n
+a
n1
s
n1
+ +a
0
(2.59)
This is the form that MATLAB uses in the transfer-function format, tf. Note that the leading
coefcient in the denominator is set to 1. As a MATLAB user, you can dene a transfer function
that does not follow this convention, but MATLAB will quietly convert to this normalised form if
you type something like G = tf(zpk(G)).
The inter-conversions between the forms is not difcult; between expressions Eqn. 2.57 and
Eqn. 2.58 simply require some adjusting of the gains and factors, while to convert from Eqn. 2.59
requires one to factorise polynomials.
For example, the following three transfer function descriptions are all equivalent
2 (10s + 1)(3s + 1)
(20s + 1)(2s + 1)(s + 1)
. .
time constant
=
1.5 (s 0.3333)(s + 0.1)
(s + 1)(s + 0.5)(s + 0.05)
. .
zero-pole-gain
=
60s
2
+ 14s + 2
40s
3
+ 62s
2
+ 23s + 1
. .
expanded polynomial
It is trivial to interconvert between the zero-pole-gain, Eqn. 2.58, and the transfer function for-
mats, Eqn. 2.59, in MATLAB, but it is less easy to convert to the time constant description. List-
ing 2.3 extracts from an arbitrary transfer function form the time constants, , the numerator time
constants, , and the plant gain K.
56 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
Listing 2.3: Extracting the gain, time constants and numerator time constants from an arbitrary
transfer function format
Gplant = tf(2
*
mconv([10 1],[-3 1]),mconv([20 1],[2 1],[1 1])) % TF of interest
G = zpk(Gplant); % Convert TF description to zero-pole-gain
3
Kp = G.k;
p = cell2mat(G.p); z = cell2mat(G.z); % Extract poles & zeros
delay0 = G.iodelay ; % Extract deadtime (if any)
8 tau = sort(-1./p,'descend'); % Convert (& sort) to time constants, 1/(js + 1)
ntau = sort(-1./z,'descend'); % Convert to numerator time constants, (is + 1)
K = Kp
*
prod(tau)/prod(ntau); % Adjust plant gain
We could of course use the control toolbox functions pole and zero to extract the poles and
zeros from an arbitrary LTI model.
2.7.6 The steady state
The steady-state, x
ss
, of a general nonlinear system x = f (x, u) is the point in state space such
that all the derivatives are zero, or the solution of
0 = f (x
ss
, u) (2.60)
If the system is linear, x = Ax+Bu, then the steady state can be evaluated algebraically in closed
form
x
ss
= A
1
Bu (2.61)
Consequently to solve for the steady-state one could invert the model matrix Abut which may be
illconditioned or computationally time consuming. Using MATLAB one should use xss = -A\B
*
u.
If Ahas no inverse, then no (or alternatively innite) steady states exist. An example of a process
that has no steady state could be a tank-ow system that has a pump withdrawing uid from
the outlet at a constant rate independent of liquid height say just exactly balancing an input ow
shown in the left hand schematic in Fig. 2.21. If the input ow suddenly increased, then the level
will rise until the tank eventually overows. If instead the tank was drained by a valve partially
open at a constant value, then as the level rises, the increased pressure (head) will force more
material out through the valve, (right-hand side of Fig. 2.21.) Eventually the system will rise to a
new steady state. It may however overow before the new steady state is reached, but that is a
constraint on the physical system that is outside the scope of the simple mathematical description
used at this time.
If the system is nonlinear, there is the possibility that multiple steady states may exist. To solve
for the steady state of a nonlinear system, one must use a nonlinear algebraic solver such as
described in chapter 3.
Example The steady state of the differential equation
d
2
y
dt
2
+ 7
dy
dt
+ 12y = 3u
where
dy
dt
= y = 0 at t = 0 and u = 1 , t 0 can be evaluated using Laplace transforms and the
2.7. MULTIVARIABLE CONTROL AND STATE SPACE ANALYSIS 57

ow in

constant ow pump
restriction
ow = f(height)
ow = constant
`
h

`
Figure 2.21: Unsteady and steady states for level systems
nal value theorem. Transforming to Laplace transforms we get
s
2
Y (s) + 7sY (s) + 12Y (s) = 3U(s)
Y (s)
U(s)
=
3
s
2
+ 7s + 12
=
3
(s + 3)(s + 4)
while for a step input
Y (s) =
1
s

3
s
2
+ 7s + 12
The nal value theorem is only applicable if the system is stable. To check, we require that the
roots of the denominator, s
2
+ 7s + 12, lie in the left hand plane,
s =
6

7
2
4 12
2
= 4 and 3
Given that both roots have negative real parts, we have veried that our system is stable and we
are allowed to apply the nal value theorem to solve for the steady-state, y(),
lim
t
y(t) = lim
s0
sY (s) = lim
s0
3
s
2
+ 7s + 12
=
3
12
= 0.25
Using the state space approach to replicate the above, we rst cast the second order differential
equation into two rst order differential equations using the controllable canonical form given in
Eqn. 2.45. Let z
1
= y and z
2
=
dy
dt
, then
z =
_
0 1
12 7
_
z +
_
0
3
_
u
and the steady state is now
z
ss
= A
1
Bu =
_
7/12 1/12
1 0
_ _
0
3
_
1 =
_
0.25
0
_
Noting that z
1
= y, we see that the steady state is also at 0.25. Furthermore, the derivative term
(z
2
) is zero, which is as expected at steady state.
58 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
2.8 Solving the vector differential equation
Since we can solve differential equations by inverting Laplace transforms, we would expect to be
able to solve state-space differential equations such as Eqn. 2.37 in a similar manner. If we look
at the Laplace transform of a simple linear scalar differential equation, x = ax + bu we nd two
terms,
sX(s) x
0
= aX(s) +bU(s)
X(s) =
x
0
s a
+
b
s a
U(s) (2.62)
One of these terms is the response of the system owing to the initial condition, x
0
e
at
, and is
called the homogeneous solution, and the other term is due to the particular input we happen
to be using. This is called the particular integral, and we must know the form of the input, u(t),
before we solve this part of the problem. The total solution is the sum of the homogeneous and
particular components.
The homogeneous solution
For the moment we will consider just the homogeneous solution to our vector differential equa-
tion. That is, we will assume no driving input, or u(t) = 0. (In the following section we will add
in the particular integral due to a non-zero input.)
Our vector differential equation, ignoring any input, is simply
x = Ax, x(t = 0) = x
0
(2.63)
Taking Laplace transforms, and not forgetting the initial conditions, we have
sx(s) x
0
= Ax(s)
x(s) (sI A) = x
0
(s)
x(s) = (sI A)
1
x
0
Finally inverting the Laplace transform back to the time domain gives
x(t) = L
1
_
(sI A)
1
_
x
0
(2.64)
Alternatively we can solve Eqn. 2.63 by separating the variables and integrating obtaining
x(t) = e
At
x
0
(2.65)
where the exponent of a matrix, e
At
, is itself a matrix of the same size as A. We call this matrix
exponential the transition matrix because it transforms the state vector at some initial time x
0
to
some point in the future, x
t
. We will give it the symbol (t).
The matrix exponential is dened just as in the scalar case as a Taylor series expansion,
e
At
or (t)
def
= I +At +
A
2
t
2
2!
+
A
3
t
3
3!
+
=

k=0
A
k
t
k
k!
(2.66)
2.8. SOLVING THE VECTOR DIFFERENTIAL EQUATION 59
although this series expansion method is not recommended as a reliable computational strategy.
Better strategies are outlined on page 62.
Comparing Eqn. 2.64 with Eqn. 2.65 we can see that the matrix e
At
= L
1
_
(sI A)
1
_
.
So to compute the solution, x(t), we need to know the initial condition and a strategy to numeri-
cally compute a matrix exponential.
The particular solution
Now we consider the full differential equation with nonzero input x = Ax + Bu. Building on
the solution to the homogeneous part in Eqn. 2.65, we get
x(t) =
t
x
0
+
_
t
0

t
Bu

d (2.67)
where now the second term accounts for the particular input vector u.
Eqn. 2.67 is not particularly useful as written as both terms are time varying. However the con-
tinuous time differential equation can be converted to a discrete time differential equation that
is suitable for computer control implementation provided the sampling rate is xed, and the in-
put is held constant between the sampling intervals. We would like to convert Eqn. 2.37 to the
discrete time equivalent, Eqn. 2.38, repeated here
x
k+1
= x
k
+u
k
(2.68)
where x
k
is the state vector x at time t = kT where T is the sample period. Once the sample pe-
riod is xed, then and are also constant matrices. We have also assumed here that the input
vector u is constant, or held, over the sample interval, which is the norm for control applications.
So starting with a known x
k
at time t = kT, we desire the state vector at the next sample time,
x
k+1
, or
x
k+1
= e
AT
x
k
+e
A(k+1)T
_
(k+1)T
kT
e
A
Bu

dt (2.69)
But as we have assumed that the input u is constant using a zeroth-order hold between the
sampling intervals kT and (k + 1)T, Eqn. 2.69 simplies to
x
k+1
= e
AT
x
k
+
_
T
0
e
A
Bu
k
d (2.70)
where = T t. For convenience, we can dene two new matrices as

def
= e
AT
(2.71)

def
=
_
_
T
0
e
A
d
_
B (2.72)
which gives us our desired transformation in the form of Eqn. 2.68. In summary, to discretise
x = Ax + Bu at sample interval T, we must compute a matrix exponential, Eqn. 2.71, and
integrate a matrix exponential, Eqn. 2.72.
Note that Eqn. 2.70 involves no approximation to the continuous differential equation provided
the input is constant over the sampling interval. Also note that as the sample time tends to zero,
the state transition matrix tends to the identity, I.
60 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
If the matrix Ais non-singular, then
=
_
e
AT
I
_
A
1
B (2.73)
is a simpler expression than the more general Eqn. 2.72.
Double integrator example. The single-input/single output double integrator system, G(s) =
1/s
2
, can be represented in continuous state space using two states as
x =
_
0 0
1 0
_
x +
_
1
0
_
u (2.74)
y =
_
0 1

x (2.75)
At sample time T, the state transition matrix is from Eqn. 2.71,
= e
AT
= exp
__
0 0
T 0
__
=
_
1 0
T 1
_
and the control matrix is given by Eqn. 2.72
=
_
_
T
0
e
A
d
_
B
=
_
_
T
0
_
1 0
1
_
d
_
_
1
0
_
=
_
_
T 0
T
2
2
T
_
_
_
1
0
_
=
_
_
T
T
2
2
_
_
For small problems such as this, the symbolic toolbox helps do the computation.
>> A = [0 0; 1 0]; B = [1; 0];
>> syms T lambda % Symbolic sample time T and
>> Phi = expm(A
*
T) % (T)
Phi =
5 [ 1, 0]
[ T, 1]
>> Delta = int(expm(A
*
lambda),lambda,0,T)
*
B % (T)
Delta =
[ T]
10 [ 1/2
*
T2]
Symbolic example with invertible Amatrix. We can discretise the continuous state-space sys-
tem
x =
_
1.5 0.5
1 0
_
x +
_
1
0
_
u
analytically at a sample time T by computing matrix exponentials symbolically.
>> A = [-3/2, -1/2; 1, 0]; B = [1;0];
>> syms T
>> Phi = expm(A
*
T)
5 Phi =
[ -exp(-1/2
*
T)+2
*
exp(-T), exp(-T)-exp(-1/2
*
T)]
[ -2
*
exp(-T)+2
*
exp(-1/2
*
T), 2
*
exp(-1/2
*
T)-exp(-T)]
2.8. SOLVING THE VECTOR DIFFERENTIAL EQUATION 61
Since Ais invertible in this example, we can use the simpler Eqn. 2.73
>> Delta = (Phi - eye(2))
*
A\B % =
_
e
AT
I
_
A
1
B
Delta =
3 [ 2/(exp(-1/2
*
T)
*
exp(-T)-exp(-T)-exp(-1/2
*
T)+1)
*
(exp(-T)-exp(-1/2
*
T))]
[ -2
*
(-exp(-1/2
*
T)+2
*
exp(-T)-1)/(exp(-1/2
*
T)
*
exp(-T)-exp(-T)-exp(-1/2
*
T)+1)]
>> simplify(Delta)
ans =
[ 2
*
exp(-1/2
*
T)/(exp(-T)-1)]
8 [ -2
*
(2
*
exp(-1/2
*
T)+1)/(exp(-T)-1)]
Of course it is evident from the above example that the symbolic expressions for (T) and (T)
rapidly become unwieldy for dimensions much larger than about 2. For this reason, analytical
expressions are of limited practical worth. The alternative numerical schemes are discussed in
the following section.
2.8.1 Numerically computing the discrete transformation
Calculating numerical values for the matrices and can be done by hand for small dimensions
by converting to a diagonal or Jordan form, or numerically using the exponential of a matrix.
Manual calculations are neither advisable nor enjoyable, but [19, p35] mention that if you rst
compute
=
_
T
0
e
A
d = IT +
AT
2
2!
+
A
2
T
3
3!
+ +
A
k1
T
k
k!
+
then
= I +A and = B (2.76)
A better approach, at least when using MATLAB, follows from Eqn. 2.71 and Eqn. 2.72 where
d
dt
= A = A (2.77)
d
dt
= B (2.78)
These two equations can be concatenated to give
d
dt
_

0 I
_
=
_

0 I
_ _
A B
0 0
_
(2.79)
which is in the same formas da/dt = ab. Rearranging this to
_
da/a =
_
b dt leads to the analytical
solution
_

0 I
_
= exp
__
A B
0 0
_
T
_
(2.80)
enabling us to extract the required and matrices provided we can reliably compute the
exponential of a matrix. The MATLAB CONTROL TOOLBOX routine to convert from continuous
to discrete systems, c2d, essentially follows this algorithm.
We could try the augmented version of Eqn. 2.80 to compute both and with one call to the
matrix exponential function for the example started on page 60.
>> A = [-3/2, -1/2; 1, 0]; B = [1;0];
2 >> syms T
62 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
>> [n,m] = size(B); % extract dimensions
>> Aa = [A,B;zeros(m,n+m)] % Augmented Amatrix,

A =
_
A B
0 0
_
Aa =
7 -1.5 -0.5 1.0
1.0 0.0 0.0
0.0 0.0 0.0
>> Phi_a = expm(Aa
*
T) compute exponential,

= exp(

AT)
Phi_a =
12 [ -exp(-1/2
*
T)+2
*
exp(-T), exp(-T)-exp(-1/2
*
T), -2
*
exp(-T)+2
*
exp(-1/2
*
T)]
[-2
*
exp(-T)+2
*
exp(-1/2
*
T), 2
*
exp(-1/2
*
T)-exp(-T),2
*
exp(-T)-4
*
exp(-1/2
*
T)+2]
[ 0, 0, 1]
>> Phi = Phi_a(1:n,1:n)
Phi =
17 [ -exp(-1/2
*
T)+2
*
exp(-T), exp(-T)-exp(-1/2
*
T)]
[ -2
*
exp(-T)+2
*
exp(-1/2
*
T), 2
*
exp(-1/2
*
T)-exp(-T)]
>> Delta = Phi_a(1:n,n+1:end)
Delta =
[ -2
*
exp(-T)+2
*
exp(-1/2
*
T)]
22 [ 2
*
exp(-T)-4
*
exp(-1/2
*
T)+2]
Reliably computing matrix exponentials
There are in fact several ways to numerically compute a matrix exponential. Ogata gives three
computational techniques, [148, pp526533], and a paper by Cleve Moler (one of the original
MATLAB authors) and Charles Van Loan is titled Nineteen dubious ways to compute the exponential
of a matrix
5
, and contrasts methods involving approximation theory, differential equations, matrix
eigenvalues and others. Of these 19 methods, two found their way into MATLAB, namely expm,
which is the recommended default strategy, and expm1 intended to compute e
x
1 for small x .
The one time when matrix exponentials are trivial to compute is when the matrix is diagonal.
Physically this implies that the system is totally decoupled since the matrix A is comprised of
only diagonal elements and the corresponding exponential matrix is simply the exponent of the
individual elements. So given the diagonal matrix
D =
_
_

1
0 0
0
2
0
0 0
3
_
_
, then the matrix exponential is exp (D) =
_
_
e

1
0 0
0 e

2
0
0 0 e

3
_
_
which is trivial and reliable to compute. So one strategy then is to transform our system to a
diagonal form(if possible), and then simply nd the standard scalar exponential of the individual
elements. However some matrices, such as those with multiple eigenvalues, is is impossible to
convert to diagonal form, so in those cases the best we can do is convert the matrix to a Jordan
block form as described in [148, p527], perhaps using the jordan command from the Symbolic
toolbox.
However this transformation is very sensitive to numerical roundoff and for that reason is not
used for serious computation. For example the matrix
A =
_
1 1
1
_
5
SIAM Review, vol. 20, A 1978, pp802836 and reprinted in [157, pp649680]. In fact 25 years later, an update was
published with some recent developments.
2.8. SOLVING THE VECTOR DIFFERENTIAL EQUATION 63
with = 0 has a Jordan form of
_
1 1
0 1
_
but for = 0, then the Jordan form drastically changes to the diagonal matrix
_
1 +

0
0 1

_
In summary, for serious numerical calculation we should use the matrix exponential function
expm. Remember not to confuse nding the exponent of a matrix, expm, with the MATLAB func-
tion exp which simply nds the exponent of all individual elements in the matrix.
2.8.2 Using MATLAB to discretise systems
All of the complications of discretising continuous systems to their discrete equivalent can be
circumvented by using the MATLAB command c2d which is short for continuous to discrete.
Here we need only to pass the continuous system of interest, and the sampling time. As an
example we can verify the conversion of the double integrator system shown on page 2.8.
G = tf(1,[1 0 0]) % Continuous system G(s) = 1/s
2
in transfer function form
Gc = ss(G) % Convert to continuous state-space
3 Gd = c2d(Gc,2) % Convert to discrete state-space with a sample time of T = 2
a =
x1 x2
x1 1 0
8 x2 2 1
b =
u1
x1 2
13 x2 2
c =
x1 x2
y1 0 1
18
d =
u1
y1 0
23 Sampling time (seconds): 2
Discrete-time state-space model.
Unlike in the analytical case presented previously, here we must specify a numerical value for
the sample time, T.
Example: Discretising an underdamped second order system with a sample time of T = 3
following Eqn. 2.80 using MATLAB to compute the matrix exponential of the augmented system.
1 [A,B,C,D] = ord2(3, 0.5); % generate a second order system
Ts = 3.0; % sample time
64 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
[na,nb] = size(B);
X = expm([A,B; zeros(nb,na+nb)]
*
Ts); % matrix exponential
6 Phi = X(1:na,1:na); % Pull off blocks to obtain & .
Del = X(1:na,na+1:end);
We can use MATLAB to numerically verify the expression found for the discretised double inte-
grator on page 60 at a specic sample time, say T = 4.
The double integrator in input/output
form is
G(s) =
1
s
2
which in packed state space notation is
_
A B
C D
_
=
_
_
0 0 1
1 0 0
0 1 0
_
_
Using a sample time of T = 4, we can com-
pute
=
_
1 0
T 1
_
=
_
1 0
4 1
_
=
_
T
T
2
2
_
=
_
4
16
2
_
We can verify this using c2d in MATLAB as
demonstrated opposite.
>>Gc = tf(1,[1,0,0])% G(s) = 1/s
2
>>Gc_ss = ss(Gc);% state space
3 >>dt = 4; % sample time
>>Gd_ss = c2d(Gc_ss,dt)
a =
x1 x2
8 x1 1.000 0
x2 4.000 1.000
b =
u1
13 x1 4.000
x2 8.000
c =
x1 x2
18 y1 0 1.000
d =
u1
y1 0
Once the two system matrices and are known, solving the difference equation for further
values of k just requires the repeated application of Eqn. 2.38. Starting from known initial condi-
tions x
0
, the state vector x at each sample instant is calculated thus
x
1
= x
0
+u
0
x
2
= x
1
+u
1
=
2
x
0
+u
0
+u
1
x
3
= x
2
+u
2
=
3
x
0
+
2
u
0
+u
1
+u
2
.
.
.
.
.
.
x
n
=
n
x
0
+
n1

k=0

n1k
u
k
(2.81)
The MATLAB function ltitr which stands for linear time invariant time response or the more
general dlsim will solve the general linear discrete time model as in 2.81. In special cases such
as step or impulse tests, you can use dstep, or dimpulse.
Problem 2.4 1. Evaluate A
n
where
A =
_
1 1
1 0
_
2.8. SOLVING THE VECTOR DIFFERENTIAL EQUATION 65
for different values of n. What is so special about the elements of A
n
? (Hint: nd the
eigenvalues of A.)
2. What is the determinant of A
n
?
3. Write a couple of MATLAB m-functions to convert between the A, B, C and Dform and the
packed matrix form.
4. Complete the state-space to transfer function conversion analytically started in 2.7.3,
Eqn. 2.53. Compare your answer with using ss2tf.
A submarine example A third-order model of a submarine from [62, p416 Ex9.17] is
x =
_
_
0 1 0
0.0071 0.111 0.12
0 0.07 0.3
_
_
x +
_
_
0
0.095
0.072
_
_
u (2.82)
where the state vector x is dened as
x

=
_

d
dt

The state is the inclination of the submarine and is the angle of attack above the horizontal.
The scalar manipulated variable u is the deection of the stern plane. We will assume that of the
three states, we can only actually measure two of them, and , thus
C =
_
1 0 0
0 0 1
_
In this example, we consider just three states x, one manipulated variable u, and two outputs, y.
The stability of the open-loop system is given by the eigenvalues of A. In MATLAB, the command
eig(A) returns
eig(A) =
_
_
0.0383 + 0.07i
0.0383 0.07i
0.3343
_
_
showing that all eigenvalues have negative real parts, indicating that the submarine is oscillatory,
though stable. In addition, the complex conjugate pair indicates that there will be some oscillation
to the response of a step change in stern plane.
We can simulate the response of our submarine system (Eqn 2.82) to a step change in stern plane
movement, u, using the step command. The smooth plot in Fig. 2.22 shows the result of this
continuous simulation, while the staired plot shows the result of the discrete simulation using
a sample time of T = 5. We see two curves corresponding to the two outputs.
Listing 2.4: Submarine simulation
A = [0,1,0;-0.0071,-0.111,0.12;0,0.07,-0.3]; B = [0,-0.095,0.072]';
C = [1 0 0;0 0 1];
3
Gc = ss(A,B,C,0) % Continuous plant, Gc(s)
dt = 5; % sample time T = 5 (rather coarse)
Gd = c2d(Gc,dt) % Create discrete model
8
step(Gc,Gd); % Do step response and see Fig. 2.22.
66 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
Figure 2.22: Comparing the continuous
and discrete step responses of the subma-
rine model.
15
10
5
0
x
1


0 20 40 60 80
0
0.1
0.2
0.3
0.4
time
x
2
G
c
G
d
Fig. 2.22 afrms that the openloop process response is stable, supporting the eigenvalue analysis.
Notice how the step command automatically selected appropriate time scales for the simulation.
How did it do this?
The steady state of the system given that u = 1 is, using Eqn 2.61,
1 >> u = 1;
>>xss = -A\B
*
u; % Steady-states given by xss = ABu.
>>yss = C
*
xss
yss = % See steady-state outputs in Fig. 2.22.
-9.3239
6 0.2400
which corresponds to the nal values given in Fig. 2.22.
We can verify the results from the c2d routine using Eqns 2.71 and 2.72, or in this case since Ais
invertible, Eqn. 2.73.
>> Phi = expm(A
*
5.0); % Dont forget the m in expmatrix()
>> Delta = (Phi-eye(size(A)))
*
(A\B) % =
_
e
AT
I
_
A
1
B
This script should give the same and matrices as the c2d function since Ais non-singular.
Given a discrete or continuous model, we can compute the response to an arbitrary input se-
quence using lsim:
t = [0:dt:100]'; % time vector
U = sin(t/20); % Arbitrary input U(t)
3
lsim(Gc,U,t) % continuous system simulation
lsim(Gd,U) % discrete system simulation
2.8. SOLVING THE VECTOR DIFFERENTIAL EQUATION 67
We could explicitly demand a rst-order-hold as opposed to the default zeroth order by setting
the options for c2d.
optn = c2dOptions('Method','foh') % Ask for a rst-order hold
Gd2 = c2d(Gc,5,optn) % Compare the step response of this with a zeroth-order hold
Problem 2.5 By using a suitable state transformation, convert the following openloop system
x
1
= x
2
x
2
= 10 2x
2
+ u
where the input u is the following function of the reference r,
u = 10 + 9r
_
9 4

x
into a closed loop form suitable for simulation in MATLAB using the lsim function. (ie: x =
Ax + Br) Write down the relevant MATLAB code segment. (Note: In practice, it is advisable to
use lsim whenever possible for speed reasons.)
Problem 2.6 1. Write an m-le that returns the state space system in packed matrix form that
connects the two dynamic systems G
1
and G
2
together,
G
all
= G
1
G
2
Assume that G
1
and G
2
are already given in packed matrix form.
2. (Problem from [182, p126]) Show that the packed matrix form of the inverse of Eqn. 2.41,
u = G
1
y, is
G
1
=
_
ABD
1
C BD
1
D
1
C D
1
_
(2.83)
assuming D is invertible, and we have the same number of inputs as outputs.
2.8.3 The discrete state space equation with time delay
The discrete state space equation, Eqn. 2.37, does not account for any time delay or dead time
between the input u and the output x. This makes it difcult to model systems with delay.
However, by introducing newvariables we can accommodate dead time or time delays. Consider
the continuous differential equation,
x
t
= Ax
t
+Bu
t
(2.84)
where is the dead time and in this particular case, is exactly equal to 2 sample times ( = 2T).
The discrete time equivalent to Eqn 2.84 for a two sample time delay is
x
k+3
= x
k+2
+u
k
(2.85)
which is not quite in our standard state-space form of Eqn. 2.38 owing to the difference in time
subscripts between u and x.
Now let us introduce a new vector of state variables, z where
z
k
def
=
_
_
x
k
x
k+1
x
k+2
_
_
(2.86)
68 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
is sometimes known as a shift register or tapped delay line of states. Using this new state vector,
we can write the dynamic system, Eqn. 2.85 compactly as
z
k+1
=
_
_
x
k+1
x
k+2
x
k+3
_
_
=
_
_
Ix
k+1
Ix
k+2
x
k+2
+ u
k
_
_
(2.87)
or in standard state-space form as
z
k+1
=
_
_
0 I 0
0 0 I
0 0
_
_
z
k
+
_
_
0
0

_
_
u
k
(2.88)
This augmented system, Eqn. 2.88 (with 2 units of dead time) is now larger than the original
Eqn. 2.85 given that we have 2n extra states. Furthermore, note that the new augmented transi-
tion matrix in Eqn. 2.88 is now no longer of full rank (provided it was in the rst place). If we
wish to incorporate a delay , of sample times ( = T), then we must introduce dummy
state vectors into the system creating a new state vector z with dimensions (n 1);
z
k
=
_
x
k
x
k+1
x
k+2
x
k+

The augmented state transition matrix and augmented control matrix are of the form
=
_

_
0 I 0 0
0 0 I 0
0 0 0 0
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
0 0 0 I
0 0 0
_

_
, and =
_

_
0
0
0
0
.
.
.

_
(2.89)
Now the discrete time equation is
z
k+1
= z
k
+u
k
(2.90)
Since all the introduced states are unobservable, we have
x
k
=
_
I 0 0 0

z
k
(2.91)
and that the output equation is amended to
y
k
= C
_
I 0 0 0

z
k
(2.92)
If the dead time is not an exact multiple of the sample time, then more sophisticated analysis is
required. See [70, p174]. Systems with a large value of dead time become very unwieldy as a
dummy vector is required for each multiple of the sample time. This creates large systems with
many states that possibly become numerically ill-conditioned and difcult to manipulate.
Problem 2.7 1. Simulate the submarine example (Eqn 2.82) but now introducing a dead time
of 2 sample time units.
2. Explain how the functions step and dstep manage to guess appropriate sampling rates,
and simulation horizons. Under what circumstances will the heuristics fail?
2.9. STABILITY 69
System Stability
Transfer function Nonlinear
Lyapunov
Nonlinear
Linearise
Marginal
non-poly
yes/no
.
-

-

.
eigenvalues
roots of denominator
poles

Routh array
Jury test
Pade approx.
simulate
Figure 2.23: Issues in assessing system stability
2.9 Stability
Stability is a most desirable characteristic of a control system. As a control designer, you should
only design control systems that are stable. For this reason, one must at least be able to analyse
a potential control system in order to see if it is indeed theoretically stable at least. Once the
controller has been implemented, it may be too late and costly to discover that the system was
actually unstable.
One denition of stability is as follows:
A system of differential equations is stable if the output is bounded for all
time for any given bounded input, otherwise it is unstable. This is referred to
as bounded input bounded output (BIBO) stability.
While for linear systems, the concept of stability is well dened and relatively straight forward
to evaluate
6
, this is not the case for nonlinear systems which can exhibit complex behaviour. The
next two sections discuss the stability for linear systems. Section 2.9.4 discusses briey techniques
that can be used for nonlinear systems.
Before any type of stability analysis can be carried out, it is important to dene clearly what sort
of analysis is desired. For example is a Yes/No result acceptable, or do you want to quantify
how close to instability the current operating point is? Is the system linear? Are the nonlinearities
hard or soft? Fig. 2.23 highlights some of these concerns.
6
Actually, the stability criterion can be divided into 3 categories; Stable, unstable and critically (un)stable. Physically
critical stability never really occurs in practice.
70 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
2.9.1 Stability in the continuous domain
The most important requirement for any controller is that the controller is stable. Here we de-
scribe how one can analyse a continuous transfer function to determine whether it is stable or
not.
First recall the conditions for BIBO stability. In the Laplace domain, the transfer function system
is stable if all the poles (roots of the denominator) have negative real parts. Thus if the roots of the
denominator are plotted on the complex plane, then they must all lie to the left of the imaginary
axis or in the Left Hand Plane (LHP). In other words, the time domain solution of the differential
equation must contain only e
at
terms and no terms of the form e
+at
, assuming a is positive.
Why is the stability only determined by the denominator of the transfer function and not by the
numerator or the input?
1. First the input is assumed bounded and stable (by BIBO denition).
2. If the transfer function is expanded as a sum of partial fractions, then the time solution
terms will be comprised of elements that are summed together. For the system to be un-
stable, at least one of these individual terms must be unstable. Conversely if all the terms
are stable themselves, then the summation of these terms will also be stable. The input will
also contribute separate fractions that are summed, but these are assumed to be stable by
denition, (part 1).
Note that it is assumed for the purposes for this analysis, that the transfer function is written in
its simplest form, that it is physically realisable, and that any time delays are expanded as a Pad e
approximation.
In summary to establish the stability of a transfer function, we could factorise the denomina-
tor polynomial using a computer program to compute numerically the roots such as MATLABs
roots routine. Alternatively, we can just hunt for the signs of the real part of the roots, a much
simpler operation, and this is the approach taken by the Routh and Jury tests described next.
Routh stability criterion
The easiest way to establish the absolute stability of a transfer function is simply to extract the
roots of the denominator perhaps using MATLABS root command. In fact this is an overkill
since to establish absolute stability we need only to know the presence of any roots with positive
real parts, not the actual value.
Aside from efciency, there are two cases where this strategy falls down. One is where we do not
have access to MATLAB or the polynomial is particularly ill-conditioned such that simple root
extraction techniques fail for numerical reasons, and the other case is where we may have a free
parameter such as a controller gain in the transfer function. This has prompted the development
of simpler exact algebraic methods such as the Routh array or Lyapunovs method to assess
stability.
The Routh criterion states that all the roots of the polynomial characteristic equation,
a
n
s
n
+a
n1
s
n1
+ +a
1
s +a
0
= 0 (2.93)
have negative real parts if and only if the rst column of the Routh table have the same sign.
Otherwise the number of sign changes is equal to the number of right-hand plane roots.
2.9. STABILITY 71
The Routh table is dened starting with the coefcients of the characteristic polynomial, Eqn. 2.93,
s
n
a
n
a
n2
a
n4

s
n1
a
n1
a
n3
a
n5

s
n2
b
1
b
2
b
3

s
n3
c
1
c
2
c
3

.
.
.
.
.
.
.
.
.
and where the new entries b and c are dened as
b
1
=
a
n1
a
n2
a
n
a
n3
a
n1
, b
2
=
a
n1
a
n4
a
n
a
n5
a
n1
, etc.
c
1
=
b
1
a
n3
a
n1
b
2
b
1
, c
2
=
b
1
a
n5
a
n1
b
3
b
1
, etc.
The Routh table is continued until only zeros remain.
The Routh array is only applicable for continuous time systems, but for discrete time systems,
the Jury test can be used in a manner similar to the Routh table for continuous systems. The
construction of the Jury table is slightly more complicated than the Routh table, and is described
in [60, 117118].
The Routh array is most useful when investigating the stability as a function of a variable such as
controller gain. Rivera-Santos has written a MATLAB routine to generate the Routh Array with
the possibility of including symbolic variables.
7
Suppose we wish to determine the range of stability for a closed loop transfer function with
characteristic equation
s
4
+ 3s
3
+ 3s
2
+ 2s +K = 0
as a function of gain K.
8
Listing 2.5: Example of the Routh array using the symbolic toolbox
>> syms K % Dene symbolic gain K
>> ra = routh([1 3 3 2 K],K) % Build Routh array for s
4
+ 3s
3
+ 3s
2
+ 2s +K
3 ra =
[ 1, 3, K]
[ 3, 2, 0]
[ 7/3, K, 0]
[ -9/7
*
K+2, 0, 0]
8 [ K, 0, 0]
Since all the elements in the rst column of the table must be positive, we know that for stability
(9/7)K + 2 > 0 and that K > 0, or
0 < K < 14/7
Stability and time delays
Time delay or dead time does not affect the stability of the open loop response since it does not
change the shape of the output curve, but only shifts it to the right. This is due to the non-
polynomial term e
s
in the numerator of the transfer function. Hence dead time can be ignored
7
The routine, routh.m, is available from the MathWorks users group collection at
www.mathworks.com/matlabcentral/fileexchange/.
8
Problem adapted from [150, p288]
72 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
for stability considerations for the open loop. However in the closed loop the dead time term ap-
pears in both the numerator and the denominator and now does affect the stability characteristics
and can now no longer be ignored. Since dead time is a nonpolynomial term, we cannot simply
nd the roots of the denominator, since now there are an innite number of them, but instead we
must approximate the exponential term with a truncated polynomial such as a Pad e approxima-
tion and then apply either a Routh array in the continuous time case, or a Jury test in the discrete
time case.
Note however that the Nyquist stability criteria yields exact results, even for those systems with
time delays. The drawback is that the computation is tedious without a computer.
Problem 2.8 Given
G(s) =
15(4s + 1)e
s
(3s + 1)(7s + 1)
Find the value of deadtime such that the closed-loop is just stable using both a Pad e approxi-
mation and a Bode or Nyquist diagram.
A rst order Pad e approximation is
e
s
=
1

2
s
1 +

2
s
2.9.2 Stability of the closed loop
Prior to the days of cheap computers that can readily manipulate polynomial expressions and
extract the roots of polynomials, one could infer the stability of the closed loop from a Bode or
Nyquist diagram of the open loop.
The openloop system
G(s) =
100(s + 2)
(s + 5)(s + 4)(s + 3)
e
0.2s
(2.94)
is clearly stable, but the closed loop system, G/(1 +G) may, or may not be stable. If we substitute
s = i, and compute the complex quantity G(i) as a function of , we can apply either the Bode
stability criteria, or the equivalent Nyquist stability criteria to establish the stability of the closed
loop without deriving an expression for the closed loop, and subsequently solving for the closed
loop poles.
The Bode diagram consists of two plots; the magnitude of G(i) versus , and the phase of
G(i) versus . Alternatively we could plot the real and imaginary parts of G(i) as a function
of frequency, but this results in a three dimensional plot. Such a plot for the system given in
Eqn. 2.94 is given in Fig. 2.24(a).
However three dimensional plots are difcult to manipulate, so we normally ignore the fre-
quency component, and just view the shadow of the plot on the real/imaginary plane. The
two dimensional Nyquist curve corresponding to Fig. 2.24(a) is given in Fig. 2.24(b). It is evident
from either plot that the curve does encircle the critical (0, 1i) point, so the closed loop system
will be unstable.
Establishing the closed loop stability using the Nyquist criteria is slightly more general than when
using the Bode criteria. This is because for systems that exhibit a non-monotonically decreasing
curves may cross the critical lines more than once leading to misleading results. An interesting
example from [80] is use to illustrate this potential problem.
2.9. STABILITY 73
2
0
2
4
4
2
0
2
10
2
10
0
10
2
10
4
(Gi )
3D Nyquist plot
(Gi )


[
r
a
d
/
s
]
(a) The Nyquist diagram with frequency information
presented in the third dimension. A agpole is
drawn at (1, 0i). Since the curve encircles the ag-
pole, the closed loop is unstable.
Nyquist Diagram
Real Axis
I
m
a
g
i
n
a
r
y

A
x
i
s
1 0 1 2 3
3
2
1
0
1
2
3
(b) A 2D Nyquist diagram which shows the closed
loop is unstable since it encircles the (1, 0i) point.
In this case both positive and negative frequencies are
plotted.
Figure 2.24: Nyquist diagram of Eqn. 2.94 in (a) three dimensions and (b) as typically presented
in two dimensions.
2.9.3 Stability of discrete time systems
The denition of stability for a discrete time system is similar to that of the continuous time
system except that the denition is only concerned with the values of the output and input at the
sample times. Thus it is possible for a system to be stable at the sample points, but be unstable
between the sample points. This is called a hidden oscillation, although rarely occurs in practice.
Also note that the stability of a discrete time system is dependent on the sample time, T.
Recall that at sample time T, by denition z = exp(sT), the poles of the continuous transfer
function p
i
map to exp(p
i
T) in discrete space. If p
i
is negative, then exp(p
i
T) will be less than
1.0. If p
i
is positive, then the corresponding discrete pole z
i
will be larger than 1.0. Strictly if p
i
is complex, then it is the magnitude of z
i
that must be less than 1.0 for the system to be stable.
If the discrete poles z
i
, are plotted on the complex plane, then if they lie within a circle centered
about the origin with a radius of 1, then the system is stable. This circle of radius 1 is called the
unit circle.
The discrete time transfer function G(z) is stable if G(z) has no discrete poles
on, or outside, the unit circle.
Now the evaluation of stability procedure is the same as that for the continuous case. One simply
factorises the characteristic equation of the transfer function and inspects the roots. If any of the
roots z
i
lie outside the unit circle, the system will be unstable. If any of the poles lie exactly on
the unit circle, there can be some ambiguity about the stability, see [119, p120]. For example the
transfer function which has poles on the unit circle,
G(z) =
1
z
2
+ 1
74 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
given a bounded input such as a step, u(k) = {1, 1, 1, 1 . . .} produces
y(k) = {0, 0, 1, 1, 0, 0, 1, 1, 0, 0, . . .}
which is bounded and stable. However if we try a different bounded input such as a cycle u(k) =
{1, 0, 1, 0, 1, 0, 1, . . .} we observe
y(k) = {0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, . . .}
which is unbounded.
Just as in the continuous case, we can establish the absolute stability of a discrete transfer function
without explicitly solving for the roots of the denominator D(z) = 0, which, in the days before
computers was a main consideration. The main methods for discrete systems are the Jury test,
the bilinear transform coupled with the Routh array, and Lyapunovs method. All these methods
are analytical and hence exact. The Jury test is the discrete equivalent to the Routh array and
is covered in Ogata [148, p242]. Lyapunovs method has the special distinction that it is also
applicable to nonlinear ODEs and is covered in 2.9.4.
Suppose we wish to establish the stability of the discretised version of
G(s) =
1
6s
2
+ 5s + 1
at a sampling period of T = 2 and a rst-order hold.
The discrete transfer function is
G(z) =
0.0746 + 0.2005z
1
+ 0.0324z
2
1 0.8813z
1
+ 0.1889z
2
with discrete poles given by the solution of
1 0.8813z
1
+ 0.1889z
2
= 0
or
z =
_
0.5134
0.3679
>> G = tf(1,[6 5 1]);
2 >> Gd = c2d(G,2,'foh')
>> pole(Gd)
ans =
0.5134
0.3679
7 >> pzmap(Gd); axis('equal');
Since both discrete poles lie inside the unit circle, the discretised transfer function with a rst-
order hold is still stable.
If you are using the state space description, then simply check the eigenvalues of the homoge-
neous part of the equation (the A or matrix).
2.9.4 Stability of nonlinear differential equations
Despite the fact that nonlinear differential equations are in general very difcult, if not impossible
to solve, one can attempt to establish the stability without needing to nd the solution. Studies of
this sort fall into the realm of nonlinear systems analysis which demands a high degree of math-
ematical insight and competence. [187] is a good introductory text for this subject that avoids
much of the sophisticated mathematics.
Two methods due to the Russian mathematician Lyapunov
9
address this nonlinear system sta-
bility problem. The indirect or linearisation method is based on the fact that the stability near
9
Some authors, e.g. Ogata, tend to it spell as Liapunov. Note however that MATLAB uses the lyap spelling.
2.9. STABILITY 75
the equilibrium point will be closely approximated to the linearised approximation at the point.
However it is the second method, or direct method that being exact is a far more interesting and
powerful analysis. Since the Lyapunov stability method is applicable for the general nonlinear
differential equation, it is of course applicable for linear systems as well.
Figure 2.25: Alexander Mikhailovich Liapunov (18571918) was a Russian
mathematician and mechanical engineer. He had the very rare merit of pro-
ducing a doctoral dissertation of lasting value. This classic work was originally
published in 1892 in Russian but is now available in an English translation Sta-
bility of Motion, Academic Press, NY, 1966. Liapunov died by violence in Odessa,
which cannot be considered a surprising fate for a middle class intellectual in the
chaotic aftermath of the Russian revolution.
Excerpt from Differential Equations and historical applications, Simmons, p465.
The Lyapunov stability theorem says that if such a differential system exists
x = f (x, t) (2.95)
where f (0, t) = 0 for all t, and if there exists a scalar function V (x) having continuous rst partial
derivatives satisfying V (x) is positive denite and the time derivative,

V (x), is negative denite,
then the equilibrium position at the origin is uniformly asymptotically stable. If V (x, t) as
x , then it is stable in the large. V (x) is called a Lyapunov function of the system.
If the Lyapunov function is thought of as the total energy of the system, then we know that the
total energy must both always be positive, hence the restriction that V (x) is positive denite, and
also for the system to be asymptotically stable, this energy must slowly with time die away, hence
the requirement that

V (x) < 0. The hard part about this method is nding a suitable Lyapunov
function in the rst place. Testing the conditions is easy, but note that if your particular candidate
V (x) function failed the requirements for stability, this either means that your system is actually
unstable, or that you just have not found the right Lyapunov function yet. The problem is that
you dont know which. In some cases, particularly vibrating mechanical ones, good candidate
Lyapunov functions can be found by using the energy analogy, however in other cases this may
not be productive.
Algorithm 2.2 Lyapunov stability analysis of nonlinear continuous and discrete systems.
The second method of Lyapunov is applicable for both continuous and discrete systems, [187,
p65], [148, p557].
76 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
Continuous differential equations
Given a nonlinear differential equation,
x = f (x, t)
and a scalar function V (x), then if
1. V (x) is positive denite, and
2.

V (x), the derivative of V (x), is negative
denite, and
3. V (x) as x
then the system x = f (x, t) is globally asymptoti-
cally stable.
Discrete difference equations,
Given a nonlinear difference equation,
x
k+1
= f(x
k
), f (0) = 0
and a scalar function V (x), continuous in x, then
if
1. V (x) > 0 for x = 0 (or V (x) is positive def-
inite), and
2. V (x), the difference of V (x), is negative
denite, where
V (x
k
) = V (x
k+1
) V (x
k
)
= V (f(x
k
)) V (x
k
)
and
3. V (x) as x
then the system x
k+1
= f (x
k
) is globally asymp-
totically stable.
Example of assessing the stability of a discrete nonlinear system using Lyapunovs second
method.
Consider the dynamic equation from Ogata [150, Ex 9-18, p729]
x
1
= x
2
x
1
_
x
2
1
+x
2
2
_
x
2
= x
2
x
2
_
x
2
1
+x
2
2
_
and we want to establish if it is stable or not. The system is nonlinear and the origin is the only
equilibrium state. We can propose a trial Lyapunov function V (x) = x
2
1
+ x
2
2
which is positive
denite. (Note that that was the hard bit!) Now differentiating gives

V (x) = 2x
1
dx
1
dt
+ 2x
2
dx
2
dt
= 2
_
x
2
1
+x
2
2
_
which is negative denite. Since V (x) as x , then the system is stable in the large.
Relevant problems in [150, p771] include B-9-15, B-9-16 and B-9-17.
The problem with assessing the stability of nonlinear systems is that the stability can change
depending on the values of the states and/or inputs. This is not the case for linear systems,
where the stability is a function of the system, not the operating point. An important and relevant
chemical engineering example of a nonlinear system that can either be stable or unstable is a
continuously stirred tank reactor. The reactor can either be operated in the stable or unstable
regime depending on the heat transfer characteristics. The stability of such reactors is important
for exothermic reactions, since the thermal run-away is potentially very hazardous.
Stability of linear time invariant systems using Lyapunov
Sections 2.9.1 and 2.9.3 established stability criteria for linear systems. In addition to these meth-
ods, the second method of Lyapunov can be used since the linear system is simply a special case
of the general nonlinear system. The advantages of using the method of Lyapunov are:
2.9. STABILITY 77
1. The Lyapunov method is analytical even for nonlinear systems and so the criteria is, in
principle, exact.
2. It is computationally simple and robust and does not require the solution to the differential
equation.
3. We do not need to extract eigenvalues of an n n matrix which is an expensive numerical
computation, (although we may need to check the deniteness of a matrix which does
require at least a Cholesky decomposition).
Of course similar advantages apply to the Routh array procedure, but unlike the Routh array,
this approach can be extended to nonlinear problems.
To derive the necessary condition for stability of x = Ax using the method of Lyapunov, we
follow the procedure outlined in Algorithm 2.2 where we choose a possible Lyapunov function
in quadratic form,
V (x) = x
T
Px
The Lyapunov function will be positive denite if the matrix P is positive denite. The time
derivative is given by

V (x) = x
T
Px +x
T
P x
= (Ax)
T
Px + x
T
P(Ax)
= x
T
_
A
T
P+PA
_
. .
Q
x
So if Q is negative denite or alternatively Q is positive denite, Q 0, then the system is
stable at the origin and hence asymptotically stable in the large. Note that this solution procedure
is analytical.
Unfortunately there is no cheap and easy computational way to establish if a matrix is positive
denite or not, but using MATLAB we would usually attempt a Cholesky factorisation. Apart
from the difculty in deciding if a matrix is positive denite or not, we also have the problem
that a failure of Q being positive denite does not necessarily imply that the original system is
unstable. All it means is that if the original system does turn out to be stable, then the postulated
P was actually not a Lyapunov function.
A solution procedure that avoids us testing many different Lyapunov candidates is to proceed in
reverse; namely choose an arbitrary symmetric positive denite Q (say the identity matrix), and
then solve
A
T
P+PA = Q (2.96)
for the matrix P. Eqn. 2.96 is known as the matrix Lyapunov equation or the more general form,
AP+PB = Q, is known as Sylvesters equation.
One obvious way to solve for the symmetric matrix P in Eqn. 2.96 is by equating the coefcients
which results in a n(n + 1)/2 system of linear algebraic equations. It is convenient in MATLAB
to use the Kronecker tensor product to set up the equations and then use MATLABs backslash
operator to solve them. This has the advantage that it is expressed succinctly in MATLAB, but it
has poor storage and algorithmic characteristics and is recommended only for small dimensioned
problems. Section 2.9.5 explains Kronecker tensor products and this analytical solution strategy
in further detail.
Listing 2.6: Solve the continuous matrix Lyapunov equation using Kronecker products
78 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
n= size(Q,1); % Solve A
T
P+PA = Q, Q = Q
T
I= eye(n); % Identity In, the same size as A
3 P=reshape(-(kron(I,A')+kron(A',I))\Q(:),n,n);% vec(IA
T
+A
T
I)vec(P) = vec(Q)
P= (P+P')/2; % force symmetric (hopefully unnecessary)
The nal line, while strictly unnecessary, simply forces the computed result to be symmetric,
which of course it should be in the rst case.
Less restrictive conditions on the form of Q exist that could make the solution procedure easier
to do manually and are discussed in problem 918 Ogata [150, p766], and [148, p554]. Note
however, using MATLAB, we would not normally bother with these modications.
The CONTROL TOOLBOX for MATLAB includes the function lyap that solves the matrix Lya-
punov equation which is more numerically robust and efcient that equating the coefcients or
using the Kronecker tensor product method given on page 77. However note that the denition
of the Lyapunov matrix equation used by MATLAB,
AP+PA
T
= Q (2.97)
is not exactly the same as that dened by Ogata and used previously in Eqn. 2.96. (See the MAT-
LAB help le for clarication of this and compare with example 920 in [150, p734].)
Suppose we wish to establish the stability of the continuous system
x = Ax
=
_
0 1
1 0.5
_
x
using lyap, as opposed to say extracting eigenvalues.
Now we wish to solve A

P+PA = Q for P where Q is some conveniently chosen positive


denite matrix such as say Q = I. Since MATLABs lyap function solves the equivalent matrix
equation given by Eqn. 2.97, we must pass A

rather than A as the rst argument to lyap.


Listing 2.7: Solve the matrix Lyapunov equation using the lyap routine
1 >> A = [0,1;-1,-0.4];
>> P = lyap(A',eye(size(A))) % Use A
T
instead of A
P =
2.7000 0.5000
0.5000 2.5000
6 >> A'
*
P + P
*
A + eye(size(A)) % Does this equal zero ?
ans =
1.0e-015
*
0 -0.4441
-0.4441 0.2220
11
>> Q = eye(size(A)); % alternative method
>> n = max(size(Q)); % solve A
T
X+XA = C where C 0
>> I = eye(n);
>> P=reshape(-(kron(I,A')+ kron(A',I))\Q(:),n,n)
16 P =
2.7000 0.5000
0.5000 2.5000
2.9. STABILITY 79
Both methods return the same matrix P,
P =
_
2.7 0.5
0.5 2.5
_
which has minor determinants of 2.7 and 6.5. Since both are positive, following Sylvesters crite-
ria, P is positive denite and so the system is stable.
We can use Sylvesters criteria to establish if P is positive denite or not, and hence the sys-
tems stability. To establish if a symmetric matrix is positive denite, the easiest way is to look
at the eigenvalues. If they are all positive, the matrix is positive denite. Unfortunately we were
originally trying to avoid to solve for the eigenvalues, so this defeats the original purpose some-
what. Another efcient strategy to check for positive deniteness with MATLAB is to attempt
a Cholesky decomposition using the [R,p]=chol(A) command. The decomposition will be
successful if A is positive denite, and will terminate early with a suitable error message if not.
Refer to the help le for further details.
As a nal check, we could evaluate the eigenvalues of Ain MATLAB by typing eig(A).
Discrete time systems
For linear discrete time systems, the establishment of stability is similar to the continuous case
given previously. Given the discrete time system x
k+1
= x
k
, we will again choose a positive
denite quadratic function for the trial Lyapunov function, V (x) = x
T
Px where the matrix P is
positive denite, and compute the forward difference
V (x) = V (x
k+1
) V (x
k
)
= x
T
k+1
Px
k+1
x
T
k
Px
k
= (x
k
)
T
Px
k
x
T
k
Px
k
= x
T
k
_

T
PP
_
. .
Q
x
k
If the matrix Q
Q =
_

T
PP
_
(2.98)
is positive denite, then the system is stable.
The reverse solution procedure for P given Q and is analogous to the continuous time case
given in Listing 2.6 using the Kronecker tensor product.
Listing 2.8: Solve the discrete matrix Lyapunov equation using Kronecker products
n = max(size(Q)); % Solve A
T
PAP = Q, with Q 0
2 I = eye(n); % identity
P = reshape((kron(I,I)-kron(Phi',Phi'))\Q(:),n,n)
P = (P+P')/2; % force symmetric (hopefully unnecessary)
Once again, the more efcient dlyap routine from the CONTROL TOOLBOX can also be used. In
fact dlyap simply calls lyap after some minor pre-processing.
We can demonstrate this establishing the stability of
x
k+1
=
_
3 0.5
0 0.8
_
x
k
80 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
In this case since is upper triangular, we can read the eigenvalues by inspection, (they are the
diagonal elements, 3 and 0.8). Since one of the eigenvalues is outside the unit circle we know
immediately that the process is unstable. However following the method of Lyapunov,
1 >> Phi = [3, -0.5; 0, 0.8]
>> Q = eye(size(Phi)); % Ensure Q 0
>> P = dlyap(Phi',Q) % Note is transposed.
P =
-0.1250 -0.1339
6 -0.1339 2.9886
>> [R,rc] = chol(P) % Is P +ve denite?
R =
[]
rc =
11 1 % No it isnt, unstable!
we verify that result.
We can both check the deniteness of P using Sylvesters criteria [150, pp924-926], or by using
the chol function as in the above example, or even by nding the eigenvalues of P. We then can
compare the stability criteria thus established with that obtained by solving for the eigenvalues
of .
Algorithm 2.3 Stability of linear systems using Lyapunov
We wish to establish the absolute stability of the dynamic linear continuous system, x = Ax or
the discrete counterpart, x
k+1
= x
k
1. Choose a convenient positive denite n n matrix Q, say the identity, I
nn
, then
2. Solve either
A
T
P+PA = Q
in the case of a continuous system, or

T
PP = Q
in the case of a discrete system for P by either equating the coefcients or using lyap or
dlyap.
3. The Lyapunov function is V (x) = x
T
Px, so check the deniteness of P. The system is
stable if and only if P is positive denite. Check using Sylvesters criteria or attempt a
Cholesky factorisation.
2.9.5 Expressing matrix equations succinctly using Kronecker products
The strategy employed in Listings 2.6 and 2.8 to solve the Lyapunov equation used Kronecker
products and vectorisation or stacking to express the matrix equation succinctly. This made it easy
to solve since the resulting expression was now reformulated into a system of linear equations
which can be solved using standard linear algebra techniques. Further details on the uses and
properties of Kronecker products (or tensor products) are given in [88, p256], [115, Chpt 13]
and [128]. The review in [34] concentrates specically on Kronecker products used in control
applications.
2.9. STABILITY 81
The Kronecker product, given the symbol , of two arbitrarily sized matrices, A
mn
and
B
pq
, results in a new (large) matrix
AB =
_

_
a
11
B a
1n
B
.
.
.
.
.
.
.
.
.
a
m1
B a
mn
B
_

_
mpnq
(2.99)
of size (mp nq). In MATLAB we would write kron(A,B). Note in general AB = BA.
The vectorisation of a matrix A is an operation that converts a rectangular matrix into a single
column by stacking the columns of A on top of each other. In other words, if A is an (n
m) matrix, then vec(A) is the resulting (nm 1) column vector. In MATLAB we convert block
matrices or row vectors to columns simply using the colon operator, or A(:).
We can combine this vectorisation operation with Kronecker products to express matrix multi-
plication as a linear transformation. For example, for the two matrices A and B of compatible
dimensions, then
vec (AB) = (I A) vec(B)
=
_
B
T
I
_
vec(A)
(2.100)
and for the three matrices A, B and C of compatible dimensions, then
vec (ABC) =
_
C
T
A
_
vec(B)
= (I AB) vec(C)
=
_
C
T
B
T
I
_
vec(A)
(2.101)
Table II in [34] summarises these and many other properties of the algebra of Kronecker products
and sums.
This gives us an alternative way to express matrix expressions such as the Sylvester equation
AX XA = Q where we wish to solve for the matrix X given matrix A. In this case, using
Eqn. 2.100, we can write
vec(AXXA) =
_
I AA
T
I
_
vec(X) = vec(Q)
which is in the form of a system of linear equations Gx = q where the vectors x and q are simply
the stacked columns of the matrices X, and Q, and the matrix G is given by
_
I A A
T
I
_
.
We rst solve for the unknown vector x using say x = G
1
q or some numerically sound equiv-
alent, and then we reassemble the matrix X by un-stacking the columns from x. Of course this
strategy is memory intensive because the size of the matrix Gis (n
2
n
2
). However [34] describes
some modications to this approach to reduce the dimensionality of the problem.
Using fsolve to solve matrix equations
The general nonlinear algebraic equation solver fsolve within the OPTIMISATION TOOLBOX has
the nice feature that it can solve matrix equations such as the continuous time Lyapunov equation
directly. Here we wish to nd the square matrix Xsuch that
AX+XA
T
+Q = 0
given an arbitrary square matrix Aand a positive denite matrix Q. For an initial estimate for X
we should start with a positive denite matrix such as I. We can compare this solution with the
one generated by the dedicated lyap routine.
82 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

`


Continuous s-plane Discrete z-plane
0
stable
,
unstable
stable
Stability boundary
unstable

+1
+1
1 unit circle

imaginary axis
Figure 2.26: Regions of stability for the poles of continuous (left) and discrete (right) systems
>> n = 4;
>> A = rand(n); % Create a random matrix Aof dimensions (n n)
>> Q1 = randn(n); Q = Q1'
*
Q1; % Create a random positive denite matrix Q
4
>> LyEqn = @(X) A
*
X+X
*
A'+Q; % Matrix equation to be solved: AX+XA
T
+Q = 0
>> X = fsolve(LyEqn, eye(n)); % Solve the Lyapunov using fsolve
X1 =
-0.8574 -0.6776 1.0713
9 -0.6776 2.7742 -2.6581
1.0713 -2.6581 0.7611
>> Xx = lyap(A,Q); % Solve the Lyapunov using the control toolbox
Xx =
14 -0.8574 -0.6776 1.0713
-0.6776 2.7742 -2.6581
1.0713 -2.6581 0.7611
2.9.6 Summary of stability analysis
The stability of a linear continuous time transfer function is determined by the sign of the real
part of the poles. For the transfer function to be stable, all the poles must lie strictly in the left-
hand-plane. In the discrete case, the stability is determined by the magnitude of the possibly
complex poles. To be stable, the discrete poles must lie within the unit circle. (See Fig. 2.26.)
The key difference between the stability of discrete and continuous transfer functions is that the
sample time plays an important role. Generally as one increases the sample time, the discrete
system tend to instability.
To establish the stability of the transfer functions, one need not solve for the roots of the de-
nominator polynomial since exact algebraic methods such as the Routh Array, Jury blocks and
Lyapunov methods exist. However with the current computer aided tools such as MATLAB, the
task of reliably extracting the roots of high order polynomials is not considered the hurdle it once
2.10. SUMMARY 83
was. The Lyapunov method is also applicable for nonlinear systems. See Ogatas comments,
[148, p250].
2.10 Summary
This chapter briey developed the tools needed to analyse discrete dynamic systems. While
most physical plants are continuous systems, most control is performed on a digital computer,
and therefore the discrete description is far more natural for computer implementation or sim-
ulation. Converting a continuous differential equation to a discrete differential equation can be
done either by using a backward difference approximation such as Eulers scheme, or by using z
transforms. The z transform is the discrete equivalent to the Laplace transform in the continuous
domain.
A vector/matrix approach to systems modelling and control has the following characteristics:
1. We can convert any linear time invariant differential equation into the state space form
x = Ax +Bu.
2. Once we have selected a sampling time, T, we can convert from the continuous time do-
main to the discrete form equivalent; x
k+1
= x
k
+u
k
.
3. The stability of both the discrete and continuous time systems is determined by the eigen-
values of the Aor matrix.
4. We can transform the mathematical description of the process to dynamically similar de-
scriptions by adjusting our base coordinates, which may make certain computations easier.
Stability is one of the most important concepts for the control engineer. Continuous linear sys-
tems are stable if all the poles lie in the left hand side of the complex plane, ie they have negative
real parts. For discrete linear systems, the poles must lie inside the unit circle. No easy check can
be made for nonlinear systems, although the method due to Lyapunov can possibly be used, or
one can approximate the nonlinear as a linear system and check the stability of the latter.
When we deal with discrete systems, we must sample the continuous function. Sampling can
introduce problems in that we may miss interesting information if we dont sample fast enough.
The sampling theorem tells us how fast we must sample to reconstruct particular frequencies.
Over sampling is expensive, and could possibly introduce unwanted artifacts such as RHP zeros
etc.
84 CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS
Chapter 3
Modelling dynamic systems with
differential equations
The ability to solve so many problems with a small arsenal of mathematical methods gave rise
to a very optimistic world view which in the 18th Century came to be called the Age of
Reason. The essential point is that the world was felt to be predictable.
Hans Mark
3.1 Dynamic system models
Dynamic system models are groups of equations that involve time derivative terms that attempt
to reproduce behaviour that we observe around us. I admire the sense of optimism in the quote
given above by Hans Mark: if we know the governing equations, and the initial conditions, then
the future is assured. We now know that the 18th century thinkers were misguided in this sense,
but nevertheless engineers are a conservative lot, and still today with similar tools, they aim to
predict the known universe.
It is important to realise that with proven process models, control system design becomes sys-
tematic, hence the importance of modelling.
Physically dynamic systems are those that change with time. Examples include vibrating struc-
tures (bridges and buildings in earthquakes), bodies in motion (satellites in orbit, ngers on a
typewriter), changing compositions (chemical reactions, nuclear decay) and even human charac-
teristics (attitudes to religion or communism throughout a generation, or attitudes to the neigh-
bouring country throughout a football match) and of course, there are many other examples. The
aim of many modellers is to predict the future. For many of these types of questions, it is infea-
sible to experiment to destruction, but it is feasible to construct a model and test this. Today, it is
easiest to construct a simulation model and test this on a computer. The types of models referred
to in this context are mathematically based simulation models.
Black-box or heuristic models, where we just t any old curve to the experimental data, and White-
box or fundamental models, where the curves are tted to well established physical laws repre-
sent two possible extremes in modelling philosophy. In practice, most engineering models lie
somewhere in the grey zone, known appropriately as grey-box models where we combine our
partial prior knowledge with black-box components to t any residuals. Computer tools for
85
86 Modelling
grey-box modelling are developed in [30].
3.1.1 Steady state and dynamic models
Steady state models only involve algebraic equations. As such they are more useful for design
rather than control tasks. However they can be used for control to give broad guidelines about
the operating characteristics of the process. One example is Bristols relative gain array ( 3.3.4)
which uses steady state data to analyse for multivariable interaction. But it is the dynamic model
that is of most importance to the control engineer. Dynamic models involve differential equa-
tions. Solving systems involving differential equations is much harder than for algebraic equa-
tions, but is essential for the study and application of control. A good reference for techniques of
modelling dynamic chemical engineering applications is [196].
3.2 A collection of illustrative models
An economist is an expert who will know tomorrow why the things he predicted yesterday didnt happen
today.
Laurence J. Peter
This section reviews the basic steps for developing dynamic process models and gives a few
examples of common process models. There are many text books devoted to modelling for en-
gineers, notably [33, 114] for general issues, [43, 195] for solution techniques and [129, 196] for
chemical engineering applications. I recommend the following stages in the model building pro-
cess:
1. Draw a diagram of the system with a boundary and labelling the input/output ows that
cross the boundary.
2. Decide on what are state variables, what are parameters, manipulated variables, uncon-
trolled disturbances etc.
3. Write down any governing equations that may be relevant such as conservation of mass
and energy.
4. Massage these equations in a standard form suitable for simulation.
The following sections will describe models for a ow system into and out of a tank with external
heating, a double integrator such as an inverted pendulumor satellite control, a forced circulation
evaporator, and a binary distillation column.
3.2.1 Simple models
Pendulums
Pendulums provide an easy and fruitful target to model. They can easily be built, are visually
impressive, and the governing differential equations derived from the physics are simple but
nonlinear. Furthermore, if you invert the pendulum such as in a rocket, the system is unstable,
and needs an overlaying control scheme.
3.2. A COLLECTION OF ILLUSTRATIVE MODELS 87

mg

torque, T
c

mg

Inverted pendulum (unstable) Pendulum (stable)


length, l
Figure 3.1: A stable and unstable pendulum
Fig. 3.1 shows the two possible orientations. For the classical stable case, the equation of motion
for the pendulum is
ml
2
d
2

dt
2
+mgl sin = T
c
(3.1)
where is the angle of inclination, and T
c
is the applied torque. We can try to solve Eqn. 3.1
analytically using dsolve from the symbolic toolbox,
>> syms m l g positive
>> syms Tc theta
>> dsolve(m
*
l2
*
D2theta + m
*
g
*
l
*
sin(theta) = Tc)
Warning: Explicit solution could not be found; implicit solution returned.
> In C:\MATLAB6p5p1\toolbox\symbolic\dsolve.m at line 292
ans =
[ Int(m/(m
*
(2
*
m
*
g
*
l
*
cos(a)+2
*
Tc
*
a+C1
*
m
*
l2))(1/2)
*
l,a = .. theta)-t-C2 = 0]
[ Int(-m/(m
*
(2
*
m
*
g
*
l
*
cos(a)+2
*
Tc
*
a+C1
*
m
*
l2))(1/2)
*
l,a = .. theta)-t-C2 = 0]
but the solution returned is not much help indicating that this particular nonlinear differential
equation probably does not have a simple explicit solution.
Eqn. 3.1 is a second order nonlinear differential equation, but by dening a new state variable
vector, x, as
x
1
def
= (3.2)
x
2
def
= x
1
=
d
dt
(3.3)
then we note that x
2
= x
1
, so the single second order differential equation can now be written as
88 Modelling
two coupled rst order equations
x
1
= x
2
(3.4)
x
2
=
g
l
sin x
1
+
T
c
ml
2
(3.5)
Linearising Eqn. 3.5 is trivial since sin for small angles. Consequently, both linear and
nonlinear expressions are compared below
x =
_
0 x
1
g
l
sin(x
1
) 0
_
+
_
0
T
c
ml
2
_
. .
nonlinear
, x =
_
0 1
g
l
0
_
x +
_
0
T
c
ml
2
_
. .
linear
(3.6)
while the numerical results are compared on page 120.
In the inverted case, the equation for x
2
is almost the same,
x
2
= +
g
l
sin x
1
+
T
c
ml
2
(3.7)
but the sign change is enough to place the linearised pole in the right-hand plane.
A double integrator
The double integrator is a simple linear example from classical mechanics. It can describe,
amongst other things, a satellite attitude control system,
J
d
2

dt
2
= u (3.8)
where J is the moment of inertia, is the attitude angle, u is the control torque (produced by
small attitude rockets mounted on the satellites side). We can convert the second order system
in Eqn. 3.8 to two rst order systems by again dening a new state vector
x =
_
x
1
x
2
_
def
=
_

_
(3.9)
Substituting this denition into Eqn. 3.8, we get J x
2
= u and x
1
= x
2
, or in a matrix-vector form
_
x
1
x
2
_
=
_
0 1
0 0
_
x
_
0
1
J
_
u (3.10)
A liquid level tank
Buffer storage vessels such as shown in Fig. 3.2 are commonly used in chemical plants between
various pieces of equipment such as reactors and separators to dampen out uctuations in pro-
duction ows.
Our system boundary is essentially the gure boundary, so we have one input, the input ow
rate, F
in
, and one output, the output ow rate, F
out
. What interests us is the amount of uid in
the tank, M, which physically must always be less than the full tank M
max
, and greater than 0.
The governing relation is the conservation of mass,
dM
dt
= F
in
F
out
(3.11)
3.2. A COLLECTION OF ILLUSTRATIVE MODELS 89
?
tank with cross sectional area, A
valve
ow out, F
out
P
ow in, F
in
-
measured height,

h
`

true height, h
Figure 3.2: Simple buffer tank
If the tank has a constant cross sectional area, then the amount of water in the tank M is pro-
portional to the height of water h, since most uids are assumed incompressible. In addition the
mass M is proportional to the volume, M = V = Ah. Rewriting Eqn. 3.11 in terms of height
dh
dt
=
F
in
F
out
A
(3.12)
since the area and density are constant. If the liquid passes though a valve at the bottom of the
tank, the owrate out will be a function of height. For many processes, the ow is proportional
to the square root of the pressure drop, (Bernoullis equation)
F
out

P = k

h
This square root relation introduces a mild nonlinearity into the model.
The tank level is not actually measured in the tank itself, but in a level leg connected to the
tank. The level in this level leg lags behind the true tank level owing to the restriction valve on
the interconnecting line. This makes the system slightly more difcult to control owing to the
added measurement dynamics. We assume, that the level leg can be modelled using a rst order
dynamic equation, with a gain of 1, and a time constant of about 2 seconds. I can estimate this by
simply watching the apparatus. Thus
d

h
dt
=
h

h
2
(3.13)
The level signal is a current, I, between 4 and 20 mA. This current is algebraically related (by
some function f() although often approximately linearly) to the level in the level leg. Thus the
variable that is actually measured is:
I = f(

h) (3.14)
The current I is called the output or measured variable. In summary, the full model equations
are;
dh
dt
=
F
in
k

h
A
(3.15)
d

h
dt
=
h

h
2
(3.16)
I = f(

h) (3.17)
90 Modelling
The input variable (which we may have some hope of changing) is the input ow rate, F
in
, and
the exit valve position which changes k. The dependent (state) variables are the actual tank
level, h, and the measurable level in the level leg,

h. The output variable is the current, I. Con-
stant parameters are density, and tank cross-sectional area. In Table 3.1 which summarises this
nomenclature, I have written vectors in a bold face, and scalars in italics. The input variables
can be further separated into variables that can be easily changed or changed on demand such
as the outlet valve position (manipulated variables), and inputs that change outside our control
(disturbance variables). In this case the inlet owrate.
Table 3.1: Standard nomenclature used in modelling dynamic systems
type symbol variable
independent t time, t
states x h,

h
inputs u F
in
, k
outputs y I
parameters , A
A stirred tank heater
Suppose an electrical heater is added causing an increase in water temperature. Now in addition
to the mass balance, we have an energy balance. The energy balance in words is the rate of
temperature rise of the contents in the tank is proportional to the amount of heat that the heater
is supplying plus the amount of heat that is arriving in the incoming ow minus the heat lost
with the out owing stream minus any other heat losses.
We note that for water the heat capacity c
p
, is almost constant over the limited temperature range
we are considering, and that the enthalpy of water in the tank is dened as
H = Mc
p
T (3.18)
where T is the temperature difference between the actual tank temperature T and some refer-
ence temperature, T
ref
. Writing an energy balance gives
Mc
p
dT
dt
= F
in
c
p
(T
in
T
ref
) F
out
c
p
T +Qq (3.19)
where Qis the heater power input (kW) and q is the heat loss (kW). These two equations (Eqn 3.12
and 3.19) are coupled. This means that a change in mass in the tank M, will affect the temperature
in the tank T (but not the other way around). This is called one-way coupling.
For most purposes, this model would be quite adequate. But you may decide that the heat loss q
to the surroundings is not constant and the variation signicant. A more realistic approximation
of the heat loss would be to assume that it is proportional to the temperature difference between
the vessel and the ambient (room) temperature T
room
. Thus q = k(T T
room
). Note that the heat
loss now can be both positive or negative. You may also decide that the heat capacity c
p
, and
density of water are a function of temperature. Now you replace these constants with functions
as c
p
(T) and (T). These functions are tabulated in the steam tables
1
. The more complete model
1
Steam tables for MATLAB are available from http://www.kat.lth.se/edu/kat061/MfileLib.html
3.2. A COLLECTION OF ILLUSTRATIVE MODELS 91
would then be
dh
dt
=
F
in
F
out
(T)A
(3.20)
A(T)
dT
dt
= F
in
c
p
(T) (T
in
Tref) F
out
c
p
(T)T +Qk (T T
room
)
Caveat Emptor
Finally we should always state under what conditions the model is valid and invalid. For this
example we should note that the vessel temperature should not vary outside the range 0 < T <
100

C since the enthalpy equation does not account for the latent heat of freezing or boiling. We
should also note that h, F
in
, F
out
, M, A, k, c
p
, are all assumed positive.
As a summary and a check on the completeness of the model, it is wise to list all the variables,
and state whether the variable is a dependent or independent variable, whether it is a dynamic
or constant variable, or whether it is a parameter. The degree of freedom for a well posed prob-
lem should be zero. That is, the number of unknowns should equal the number of equations.
Incomplete models, and/or bad assumptions can give very misleading and bad results.
A great example highlighting the dangers of extrapolation from obviously poor models is the bi-
annual UKgovernment forecast of Britains economic performance. This performance or growth,
is dened as the change in the Gross Domestic Product (GDP) which is the total amount of goods
and services produced in the country that year. Figure 3.3 plots the actual growth over the last
few years (solid line descending), compared with the forecasts given by the Chancellor of the Ex-
chequer, (dotted lines optimistically ascending). I obtained this information from a New Scientist
article provocatively titled Why the Chancellor is always wrong, [49]. Looking at this performance,
it is easy to be cynical about governments using enormous resources to model things that are
essentially so complicated as to be unmodellable, and then produce results that are politically
advantageous.
1989 1990 1991 1992 1993
111
112
113
114
115
116
117
118
119
G
r
o
w
t
h

G
D
P

c
h
a
n
g
e
Year
Actual
Forecasts
Figure 3.3: The UK growth based on the
GDP comparing the actual growth (solid)
versus Treasury forecasts (dashed) from
19891992.
92 Modelling
3.3 Chemical process models
The best material model of a cat is another, or preferably the same, cat.
Arturo Rosenblueth, Philosophy of Science, 1945
Modelling is very important in the capital-intensive world of chemical manufacture. Perhaps
there is no better example of the benets of modelling than in distillation. One industry maga-
zine
2
reported that distillation accounted for around 3% of the total world energy consumption.
Clearly this provides a large economic incentive to improve operation. Distillation models pre-
dict the extent of the component separation given the type of trays in the column, the column di-
ameter and height and the operating conditions (temperature,pressure etc). More sophisticated
dynamic models predict the concentration in the distillate given changes in feed composition,
boilup rate and reux rate over time. An example of a simple distillation dynamic model is
further detailed in 3.3.3.
When modelling chemical engineering unit operations, we can consider (in increasing complex-
ity):
1. Lumped parameters systems such as well-mixed reactors or evaporators
2. Staged processes such as distillation columns, multiple effect evaporators, oatation.
3. Distributed parameter systems such as packed columns, poorly mixed reactors, dispersion
in lakes & ponds.
An evaporator is an example of a lumped parameter system and is described in 3.3.2 while a
rigorous distillation column model described on page 98 is an example of a staged process.
At present we will now investigate only lumped parameter systems and staged processes which
involve only ordinary differential equations, as opposed to partial differential equations, albeit
a large number of them. Problems which involve algebraic equations coupled to the ordinary
differential equations are briey considered in section 3.5.1.
A collection of good test industrial process models is available in the nonlinear model library
fromwww.hedengren.net/research/models.htm.
3.3.1 A continuously-stirred tank reactor
Tank reactors are a common unit operation in chemical processing. A model presented in [85]
considers a simple A B reaction with a cooling jacket to adjust the temperature, and hence the
reaction rate as shown in Fig. 3.4.
The reactor model has two states, the concentration of compound A, given the symbol C
a
mea-
sured in mol/m
3
and the temperature of the reaction vessel liquid, T measured in K. The manip-
ulated variables are the cooling jacket water temperature, T
c
, the temperature of the feed T
f
and
2
The Chemical Engineer, 21st October, 1999, p16
3.3. CHEMICAL PROCESS MODELS 93
-
?
?
AB
Product, T, C
a
Feed, T
f
, C
af
-
-
Cooling, T
c
Stirrer
Figure 3.4: A CSTR reactor
the concentration of the feed, C
af
.
dT
dt
=
q
V
(C
af
C
a
) k
0
exp
_
E
RT
_
C
a
(3.21)
dC
a
dt
=
q
V
(T
f
T) +
mH
C
p
k
0
exp
_
E
RT
_
C
a
+
UA
V C
p
(T
c
T) (3.22)
The values for the states and inputs at steady-state are
x
ss
def
=
_
T
C
a
_
ss
=
_
324.5
0.8772
_
, u
ss
def
=
_
_
T
c
T
f
C
af
_
_
ss
=
_
_
300
350
1
_
_
(3.23)
The values of the model parameters such as , C
p
etc. are given in Table 3.2.
Table 3.2: Parameters of the CSTR model
name variable unit
Volumetric Flowrate q = 100 m
3
/sec
Volume of CSTR V = 100 m
3
Density of A-B Mixture = 1000 kg/m
3
Heat capacity of A-B Mixture C
p
= .239 J/kg-K
Heat of reaction for AB mH = 5 10
4
J/mol
E/R = 8750 K
Pre-exponential factor k
0
= 7.2 10
10
1/sec
Overall Heat Transfer Coefcient Area UA = 5 10
4
W/K
Note: At a jacket temperature of T
c
= 305K, the reactor model has an oscillatory response. The
oscillations are characterized by reaction run-away with a temperature spike. When the concen-
tration drops to a low value, the reactor cools until the concentration builds and there is another
run-away reaction.
94 Modelling
3.3.2 A forced circulation evaporator
Evaporators such as illustrated in Fig. 3.5 are used to concentrate fruit juices, caustic soda, alu-
mina and many other mixtures of a solvent and a solute. The incentive for modelling such unit
operations is that the model can provide insight towards better operating procedures or future
design alternatives. A relatively simple dynamic model of a forced circulation evaporator is de-
veloped in [145, chapter 2] is reproduced here as a test process for a wide variety of control tech-
niques of interest to chemical engineers. Other similar evaporator models have been reported
in the literature; [65] documents research over a number of years at the University of Alberta
on a pilot scale double effect evaporator, and [40] describe a linearised pilot scale double effect
evaporator used in multivariable optimal selftuning control studies.
Condensate
Steam
Condensate
Condenser
Cooling
water
Feed
circulation pump
Product
Separator
Evaporator
Pressure
level
composition
P
L
A
Vapour
Figure 3.5: A forced circulation evaporator from [145, p7].
The nonlinear evaporator model can be linearised into a state space form with the variables de-
scribed in Table 3.3. The parameters of the linearised state space model are given in Appendix E.1.
Table 3.3: The important variables in the forced circulation evaporator
type name variable unit range
level L
2
m 02
State steam pressure P
2
kPa ??
product conc x
2
% 0100
product ow F
2
kg/min 0-10
Manipulated steam pressure P
100
kPa 100350
c/w ow F
200
kg/min 0300
circulating ow F
3
kg/min 30-70
feed ow F
1
kg/min 5-15
Disturbance feed composition x
1
% 0-10
feed temperature T
1

C 20-60
c/w temperature T
200

C 15-35
The distinguishing characteristics of this evaporator system from a control point are that the
3.3. CHEMICAL PROCESS MODELS 95
detailed plant model is nonlinear, the model is non-square (the number of manipulated variables,
u, do not equal the number of state variables, x), and that one of the states, level, is an integrator.
The dynamic model is both observable and controllable, which means that by measuring the
outputs only, we can at least in theory, control all the important state variables by changing the
inputs.
Problem 3.1 1. Look at the development of the nonlinear model given in [145, chapter 2].
What extensions to the model would you suggest? Particularly consider the assumption of
constant mass (M = 50kg) in the evaporator circuit and the observation that the level in the
separator changes. Do you think this change will make a signicant difference?
2. Describe in detail what tests you would perform experimentally to verify this model if you
had an actual evaporator available.
3. Construct a MATLAB simulation of the nonlinear evaporator. The relevant equations can be
found in [145, Chpt 2].
3.3.3 A binary distillation column model
Distillation columns, which are used to separate mixtures of different vapour pressures into al-
most pure components, are an important chemical unit operation. The columns are expensive
to manufacture, and the running costs are high owing to the high heating requirement. Hence
there is much incentive to model them with the aim to operate them efciently. Schematics of
two simple columns are given in Figures 3.6 and 3.9.
Wood and Berry experimentally modelled a binary distillation column in [202] that separated
water from ethanol as shown in Fig. 3.6. The transfer function model they derived by step testing
a real column has been extensively studied, although some authors, such as [185], point out
that the practical impact of all these studies has been, in all honesty, minimal. Other distillation
column models that are not obtained experimentally are called rigorous models and are based on
fundamental physical and chemical relations. Another more recent distillation column model,
developed by Shell and used as a test model is discussed in [137].
Columns such as given in Fig. 3.6 typically have at least 5 control valves, but because the hydro-
dynamics and the pressure loops are much faster than the composition dynamics, we can use the
bottoms exit valve to control the level at the bottom of the column, use the distillate exit valve to
control the level in the separator, and the condenser cooling water valve to control the column
pressure. This leaves the two remaining valves (steam reboiler and reux) to control the top and
bottoms composition.
The Wood-Berry model is written as a matrix of Laplace transforms in deviation variables
y =
_

_
12.8e
s
16.7s + 1
18.9e
3s
21s + 1
6.6e
7s
10.9s + 1
19.4e
3s
14.4s + 1
_

_
. .
G(s)
u +
_

_
3.8e
8s
14.9s + 1
4.9e
3.4s
13.2s + 1
_

_
d (3.24)
where the inputs u
1
and u
2
are the reux and reboiler steam owrates respectively, the outputs
y
1
and y
2
are the mole fractions of ethanol in the distillate and bottoms, and the disturbance
variable, d is the feed owrate.
It is evident from the transfer function model structure in Eqn. 3.24 that the plant will be inter-
acting and that all the transfer functions have some time delay associated with them, but the
96 Modelling
Feed, F, x
F

c/w

Distillate, D, x
D

`
`

Bottoms, x
B
, B
condensor

Distillation column
Reux, R
Steam, S
reboiler

Figure 3.6: Schematic of a distillation column


off-diagonal terms have the slightly larger time delays. Both these characteristics will make con-
trolling the column difcult.
In MATLAB, we can construct such a matrix of transfer functions (ignoring the feed) with a matrix
of deadtimes as follows:
>> G = tf({12.8, -18.9; 6.6 -19.4}, ...
{ [16.7 1],[21 1]; [10.9 1],[14.4 1]}, ...
'ioDelayMatrix',[1,3; 7,3], ...
4 'InputName',{'Reflux','Steam'}, ...
'OutputName',{'Distillate','bottoms'})
Transfer function from input "Reflux" to output...
12.8
9 Distillate: exp(-1
*
s)
*
----------
16.7 s + 1
6.6
bottoms: exp(-7
*
s)
*
----------
14 10.9 s + 1
Transfer function from input "Steam" to output...
-18.9
Distillate: exp(-3
*
s)
*
--------
19 21 s + 1
-19.4
3.3. CHEMICAL PROCESS MODELS 97
bottoms: exp(-3
*
s)
*
----------
14.4 s + 1
Once we have formulated the transfer function model G, we can perform the usual types of
analysis such as step tests etc as shown in Fig. 3.7. An alternative implementation of the column
model in SIMULINK is shown in Fig. 3.8.
20
10
0
10


T
o
:

D
i
s
t
i
l
l
a
t
e
From: Reflux
0 50 100
20
10
0
T
o
:

b
o
t
t
o
m
s
From: Steam
0 50 100
Step Response
Time (sec)
A
m
p
l
i
t
u
d
e
Figure 3.7: Step responses of the four
transfer functions that make up the
Wood-Berry binary distillation col-
umn model in Eqn. 3.24.
A 3-input/3 output matrix of transfer functions model of an 19 plate ethanol/water distillation
column model with a variable side stream draw off from [151] is
_
_
y
1
y
2
y
3
_
_
=
_

_
0.66e
2.6s
6.7s + 1
0.61e
3.5s
8.64s + 1
0.0049e
s
9.06s + 1
1.11e
6.5s
3.25s + 1
2.36e
3s
5s + 1
0.012e
1.2s
7.09s + 1
34.68e
9.2s
8.15s + 1
46.2e
9.4s
10.9s + 1
0.87(11.61s + 1)e
2.6s
(3.89s + 1)(18.8s + 1)
_

_
_
_
u
1
u
2
u
3
_
_
+
_

_
0.14e
1.2s
6.2s + 1
0.0011(26.32s + 1)e
2.66s
(3.89s + 1)(14.63s + 1)
0.53e
10.5s
6.9s + 1
0.0032(19.62s + 1)e
3.44s
(7.29s + 1)(8.94s + 1)
11.54e
0.6s
7.01s + 1
0.32e
2.6s
7.76s + 1
_

_
_
d
1
d
2
_
(3.25)
which provides an alternative model for testing multivariable control schemes. In this model
the three outputs are the overhead ethanol mole fraction, the side stream ethanol mole fraction,
and the temperature on tray 19, the three inputs are the reux ow rate, the side stream product
rate and the reboiler steam pressure, and the two disturbances are the feed ow rate and feed
temperature. This system is sometimes known as the OLMR after the initials of the authors.
Problem 3.2 1. Assuming no disturbances (d = 0), what are the steady state gains of the
Wood-Berry column model? (Eqn 3.24). Use the nal value theorem.
2. Sketch the response for y
1
and y
2
for;
(a) a change in reux ow of +0.02
98 Modelling
steam
reflux
distillate
bottoms
reflux
steam
distillate
bottoms
Wood Berry Column
(a) Overall column mask.
2
bottoms
1
distillate
Transport
Delay3
Transport
Delay2
Transport
Delay1
Transport
Delay
19.4
14.1s+1
Transfer Fcn3
10.9s+1
6.6
Transfer Fcn2
18.9
21s+1
Transfer Fcn1
16.7s+1
12.8
Transfer Fcn
2
steam
1
reflux
(b) Inside the Wood Berry column mask. Compare this with Eqn. 3.24.
Figure 3.8: Wood-Berry column model implemented in SIMULINK
(b) A change in the reux ow of 0.02 and a change in reboiler steam ow of +0.025
simultaneously.
3. Modify the SIMULINK simulation to incorporate the feed dynamics.
More rigorous distillation column models
Distillation column models are important to chemical engineers involved in the operation and
maintenance of these expensive and complicated units. While the behaviour of the actual multi-
component tower is very complicated, models that assume ideal binary systems are often good
approximations for many columns. We will deal in mole fractions of the more volatile compo-
nent, x for liquid, y for vapour and develop a column model following [130, p69].
A generic simple binary component column model of a distillation column such as shown in
Fig. 3.9 assumes:
1. Equal molar overow applies (heats of vapourisation of both components are equal, and
mixing and sensible heats are negligible.)
2. Liquid level on every tray remains above weir height.
3.3. CHEMICAL PROCESS MODELS 99
3. Relative volatility and the heat of vapourisation are constant. In fact we assume a constant
relative volatility, . This simplies the vapour-liquid equilibria (VLE) model to
y
n
=
x
n
1 + ( 1)x
n
on tray n with typically 1.22.
4. Vapour phase holdup is negligible and the feed is a saturated liquid at the bubble point.
`

Distillate, D, x
D

tray # N
tray #1

Feed, F, x
F
.
.
.

Bottoms, x
B
, B
reboiler
reux, R, x
D

`
`
.
.
.
feed tray, N
F
condensor
c/w
condensor collector
Figure 3.9: Distillation tower
The N trays are numbered from the bottom to top, (tray 0 is reboiler and tray N + 1 is the con-
denser). We will develop separate model equations for the following parts of the column, namely:
Condenser is a total condenser, where the reux is a liquid and the reux drum is perfectly
mixed.
General tray has liquid ows from above, and vapour ows from below. It is assumed to be
perfectly mixed with a variable liquid hold up, but no vapour hold up as it is assumed very
fast.
Feed tray Same as a general tray, but with an extra (liquid) feed term.
Top & bottom trays Same as a general tray, but with one of the liquid (top) or vapour (bottom)
ows missing, but recycle/reux added.
Reboiler in a perfectly mixed thermo-siphon reboiler with hold up M
b
.
100 Modelling
The total mass balance in the condenser and reux drum is
dM
d
dt
= V R D
and the component balance on the top tray
dM
d
x
d
dt
= V y
NT
(R +D)x
D
(3.26)
For the general nth tray, that is trays #2 through N 1, excepting the feed tray, the total mass
balance is
dM
n
dt
= L
n+1
L
n
+V
n1
V
n
. .
0
= L
n+1
L
n
(3.27)
and the component balance
dM
n
x
n
dt
= L
n+1
x
n+1
L
n
x
n
+V y
n1
V y
n
(3.28)
For the special case of the feed n
F
th tray,
dM
nF
dt
= L
nF +1
L
nF
+F, mass balance
dM
nF
x
nF
dt
= L
nF +1
x
nF +1
L
nF
x
nF
+Fx
F
+V y
nF 1
V y
nF
, component balance
and for the reboiler and column base
dM
B
dt
= L
1
V B
dM
B
x
B
dt
= L
1
x
1
Bx
B
V x
B
In summary the number of variables for the distillation column model are:
VARIABLES
Tray compositions, x
n
, y
n
2N
T
Tray liquid ows, L
n
N
T
Tray liquid holdups, M
n
N
T
Reux comp., ow & hold up, x
D
, R, D, M
D
4
Base comp., ow & hold up, x
B
, y
B
, V, B, M
B
5
Total # of equations 4N
T
+ 9
and the number of equations are:
EQUATIONS
Tray component balance, N
T
Tray mass balance N
T
Equilibrium (tray + base) N
T
+ 1
hydraulic N
T
Reux comp. & ow 2
Base comp & ow 2
Total # of equations 4N
T
+ 7
Which leaves two degrees of freedom. From a control point of view we normally x the boildup
rate,

Q, and the reux ow rate (or ratio) with some sort of controller,
R = f(x
D
), V

Q = f(x
B
)
3.3. CHEMICAL PROCESS MODELS 101
Our dynamic model of a binary distillation column is relatively large with two inputs (R, V ), two
outputs (x
B
, x
D
) and 4N states. Since a typical column has about 20 trays, we will have around
n = 44 states. which means 44 ordinary differential equations However the (linearised) Jacobian
for this system while a large 44 44 matrix is sparse. In our case the percentage of non-zero
elements or sparsity is 9%.
_
_
x
x
..
4444
.
.
.
x
u
..
442
_
_
The structure of the Aand B matrices are, using the spy command, given in Fig. 3.10.
0 5 10 15 20 25 30 35 40 45
0
5
10
15
20
25
30
35
40
45
States & input, ([holdup, comp*holdup| [R V])
Jacobian of the Binary distiilation column model
O
D
E

e
q
u
a
t
i
o
n
s
,

(
z
d
o
t
=
)
Figure 3.10: The incidence of the Jacobian and B matrix for the ideal binary distillation column
model. Over 90% of the elements in the matrix are zero.
There are many other examples of distillation column models around (e.g. [140, pp 459]) This
model has about 40 trays, and assumes a binary mixture at constant pressure and constant rela-
tive volatility.
Simulation of the distillation column
The simple nonlinear dynamic simulation of the binary distillation column model can be used in
a number of ways including investigating the openloop response, interactions and quantify the
extent of the nonlinearities. It can be used to develop simple linear approximate transfer function
models, or we could pose What if? type questions such as quantifying the response given feed
disturbances.
An openloop simulation of a distillation column gives some idea of the dominant time constants
and the possible nonlinearities. Fig. 3.11 shows an example of one such simulation where we
step change:
1. the reux from R = 128 to R = 128 + 0.2, and
2. the reboiler from V = 178 to V = 178 + 0.2
102 Modelling
0 10 20 30
0.975
0.98
0.985
0.99
0.995
1
D
i
s
t
i
l
l

c
o
n
c
Step change in Reflux
0 10 20 30
0.975
0.98
0.985
0.99
0.995
1
Step change in Vapour
0 10 20 30
0
0.02
0.04
0.06
0.08
0.1
b
a
s
e

c
o
n
c
time (min)
0 10 20 30
0
0.02
0.04
0.06
0.08
0.1
time (min)
Figure 3.11: Open loop response of the distillation column control
From Fig. 3.11 we can note that the open loop step results are overdamped, and that steady-state
gains are very similar in magnitude. Furthermore the response looks very like a 2 2 matrix of
second order overdamped transfer functions,
_
x
D
(s)
x
B
(s)
_
=
_
G
11
G
12
G
21
G
22
_ _
R(s)
V (s)
_
So it is natural to wonder at this point if it is possible to approximate this response with a low-
order model rather than requiring the entire 44 states and associated nonlinear differential equa-
tions.
Controlled simulation of a distillation column
A closed loop simulation of the 20 tray binary distillation column with a feed disturbance from
x
F
= 0.5 to x
F
= 0.54 at t = 10 minutes is given in Fig. 3.12.
We can look more closely in Fig. 3.13 at the distillate and base compositions to see if they really
are in control, x

b
= 0.02, x

d
= 0.98.
Distillation columns are well known to interact, and these interactions cause difculties in tuning.
We will simulate in Fig. 3.14 a step change in the distillate setpoint fromx

D
= 0.98 to x

D
= 0.985
at t = 10 min and a step change in bottoms concentration at 150 minutes. The interactions
are evident in the base composition transients owing to the changing distillate composition and
visa versa. These interactions can be minimised by either tightly tuning one of the loops so
consequently leaving the other loose, or by using a steady-state or dynamic decoupler, or even
a multivariable controller.
3.3. CHEMICAL PROCESS MODELS 103
0
0.2
0.4
0.6
0.8
1
L
i
q
u
i
d

c
o
n
c
e
n
t
r
a
t
i
o
n
Binary distillation column model
124
126
128
130
R
0 20 40 60 80 100
175
180
185
V
time (min)
Figure 3.12: A closed loop simulation of a
binary distillation column given a feed dis-
turbance. The upper plot shows the con-
centration on all the 20 trays, the lower
plots shows the manipulated variables (re-
ux and boil-up) response.
0.975
0.98
0.985
0.99
D
i
s
t
i
l
l
a
t
e
0 20 40 60 80 100
0.01
0.02
0.03
0.04
B
o
t
t
o
m
s
time [mins]
Figure 3.13: Detail of the distillate and base
concentrations from a closed loop simula-
tion of a binary distillation column given a
feed disturbance. (See also Fig. 3.12.)
3.3.4 Interaction and the Relative Gain Array
The Wood-Berry distillation column model is an example of a multivariable, interacting process.
This interaction is evident from the presence of the non-zero off diagonal terms in Eqn. 3.24. A
quantitative measure of the extent of interaction in a multivariable process is the Relative Gain
Array (RGA) due to Bristol, [35]. The RGA is only applicable to square systems (the number of
manipulated variables equal the number of controlled variables), and is a steady-state measure.
The RGA, given the symbol , is an (n n) matrix where each element is the ratio of the open
loop gain divided by the closed loop gain. Ideally, if you are the sort who do not like interactions,
you would like to be diagonally dominant. Since all the rows and all the columns must sum to
1.0, then a system with no interaction will be such that = I.
The open loop steady-state gain is easy to determine. Taking the Wood-Berry model, Eqn. 3.24,
104 Modelling
Figure 3.14: Distillation interactions are ev-
ident when we step change the distillate
and bottoms setpoints independently.
0.98
0.99
1
D
i
s
t
i
l
l
a
t
e

x
D
0
0.01
0.02
0.03
0.04
B
a
s
e
,

x
B
120
140
160
R
e
f
l
u
x
0 50 100 150 200 250 300
160
180
200
r
e
b
o
i
l
e
r
time (min)
as an example, the nal steady-state as a function of the manipulated variable u, is
y
ss
= G
ss
u =
_
12.8 18.9
6.6 19.4
_
u (3.29)
The ijth element of G
ss
is the open loop gain between y
i
and u
j
. The G
ss
matrix can be evaluated
experimentally or formed by applying the nal value theorem to Eqn 3.24. Now the closed loop
gain is a function of the open loop gain, so only the open loop gains are needed to evaluate the
RGA. Mathematically the relative gain array, , is formed by multiplying together G
ss
and G

ss
elementwise,
3
= G
ss

_
G
1
ss
_

(3.30)
where the special symbol means to take the Hardamard product (also known as the Schur
product), or simply the elementwise product of two equally dimensioned matrices as opposed to
the normal matrix multiplication.
In MATLAB, the evaluation of the relative gain array is easy.
1 >>Gss = [12.8, -18.9; 6.6, -19.4] % Steady-state gain from Eqn. 3.29
>>L = Gss.
*
inv(Gss)' % See Eqn. 3.30. Dont forget the dot-times (.*)
which should return something like
=
_
2.0094 1.0094
1.0094 2.0094
_
Note that all the columns and rows sum to 1.0. We would expect this system to exhibit severe
interactions, although the reverse pairing would be worse.
The usefulness of the RGA is in choosing which manipulated variable should go with which
control variable in a decentralised control scheme. We juggle the manipulated/control variable
parings until most approaches the identity matrix. This is an important and sensitive topic in
3
Note that this does not imply that = Gss
_
G
1
ss
_

, i.e. without the Hardamard product. See [179, p456] for further
details.
3.3. CHEMICAL PROCESS MODELS 105
process control and is discussed in more detail in [191, pp494503], and in [179, p457]. The most
frequently discussed drawback of the relative gain array, is that the technique only addresses the
steady state behaviour, and ignores the dynamics. This can lead to poor manipulated/output
pairing in some circumstances where the dynamic interaction is particularly strong. The next
section further illustrates this point.
The dynamic relative gain array
As mentioned above, the RGA is only a steady-state interaction indicator. However would could
use the same idea to generate an interaction matrix, but this time consider the elements of the
transfer function matrices as a function of frequency by substituting s = j. This now means
that the dynamic relative gain array, (), is a matrix where the elements as functions of .
Consider the (2 2) system from [181]
_
y
1
y
2
_
=
_

_
2.5e
5s
(15s + 1)(2s + 1)
5
4s + 1
1
3s + 1
4e
5s
20s + 1
_

_
. .
G(s)
_
u
1
u
2
_
(3.31)
which has as its distinguishing feature signicant time delays on the diagonal elements. We could
compute the dynamic relative gain array matrix using the denition
(s) = G(s) G(s)
T
(3.32)
perhaps using the symbolic toolbox to help us with the possibly unwieldy algebra.
Listing 3.1: Computing the dynamic relative gain array analytically
>>syms s
>>syms w real
3
>>G=[2.5
*
exp(-5
*
s)/(15
*
s+1)/(2
*
s+1), 5/(4
*
s+1); ...
1/(3
*
s+1), -4
*
exp(-5
*
s)/(20
*
s+1)] % Plant from Eqn. 3.31
>>RGA = G.
*
inv(G') % (s), Eqn. 3.32
8 >>DRGA = subs(RGA,'s',1j
*
w) % Substitute s = j
>> abs(subs(DRGA,w,1)) % Magnitude of the DRGA matrix at = 1 rad/s
ans =
0.0379 0.9793
13 0.9793 0.0379
You can see that from the numerical values of the elements of at = 1 rad/s that this system
is not diagonally dominant at this important frequency. Fig. 3.15 validates this observation.
An alternative numerical way to generate the elements of the DRGA matrix as a function of
frequency is to compute the Bode diagramfor the multivariable system, extract the current gains,
and then form the RGA from Eqn. 3.30.
Listing 3.2: Computing the dynamic relative gain array numerically as a function of . See also
Listing 3.1.
106 Modelling
G = tf({2.5, 5; 1 -4}, ...
2 {conv([15 1],[2,1]),[4 1]; [3 1],[20 1]}, ...
'ioDelayMatrix',[5,0; 0,5]) % Plant from Eqn. 3.31
[,,K] = zpkdata(G); sK =sign(K); % get sign of the gains
[Mag,Ph,w] = bode(G); % Compute Bode diagram
7 DRGA = NaN(size(Mag));
for i=1:length(w)
K = Mag(:,:,i).
*
sK; % Gain, including signs
DRGA(:,:,i) = K.
*
(inv(K))'; % () = KK
T
12 end
OnDiag = squeeze(DRGA(1,1,:)); OffDiag = squeeze(DRGA(1,2,:));
semilogx(w, OnDiag,'-',w,OffDiag,'--'); % See Fig. 3.15
The trends of the diagonal and off-diagonal elements of are plotting in Fig. 3.15. What is
interesting about this example is that if we only consider the steady-state case, = 0, then
is diagonally dominant, and our pairing looks suitable. However what we should be really
concentrating on are the values around the corner frequency at 0.1 where now the off-
diagonal terms start to dominate.
Figure 3.15: The diagonal and off-diagonal el-
ements of the RGA matrix as a function of
frequency.
10
3
10
2
10
1
10
0
10
1
0
0.2
0.4
0.6
0.8
1
frequency

1,1

1,2
For comparison, Fig. 3.16 shows the dynamic RGA for the (3 3) OLMR distillation column
model from Eqn. 3.25. In this case the off-diagonal elements do not dominate at any frequency.
Figure 3.16: The elements of the (3 3) RGA
matrix from Eqn. 3.25.
10
3
10
2
10
1
10
0
10
1
1.5
1
0.5
0
0.5
1
1.5
2
2.5
frequency
e
l
e
m
e
n
t
s

o
f

)
Diagonal elements
Offdiagonal elements

11

22

33

12

13

23
3.4. REGRESSING EXPERIMENTAL DATA BY CURVE FITTING 107
3.4 Regressing experimental data by curve tting
In most cases of industrial importance, the models are never completely white-box, meaning that
there will always be some parameters that need to be tted, or at least ne-tuned to experimental
data. Generally the following three steps are necessary:
1. Collect N experimental independent x
i
, and dependent y
i
data points.
2. Select a model structure, M() with a vector of parameters that are to be estimated.
3. Search for the parameters that optimise some sort performance index such as to maximise
the goodness of t, or equivalently minimise the sum of squared residuals.
A common performance index or loss function is to select the adjustable parameters so that the
sum of difference squared between the raw data and your model predictions is minimised. This
is the classical Gaussian least-squares minimisation problem. Formally we can write the perfor-
mance index as,
J =
N

i=1
(y
i
y
i
)
2
(3.33)
where the ith model prediction, y
i
is a function of the model, parameters and input data,
y
i
= f(M(), x
i
) (3.34)
We want to nd the best set of parameters, i.e. the set of that minimises J in Eqn. 3.33,

= arg min

_
N

i=1
(y
i
y
i
)
2
_
(3.35)
The arg min part of Eqn 3.35 can be read as the argument who minimises . . . since we are
not too interested in the actual value of the performance function at the optimum, J, but rather
the value of the parameters at the optimum,

. This least-squared estimation is an intuitive


performance index, and has certain attractable analytical properties. The German mathematician
Gauss is credited with popularising this approach, and indeed using it for analysing data taken
while surveying Germany and making astronomical observations. Note however other possible
objectives rather than Eqn. 3.33 are possible, such as minimising the sum of the absolute value
of the deviations, or minimising the single maximum deviation. Both these latter approaches
have seen a resurgence of interest of the last few years since the computer tools have enabled
investigators to by-pass the difculty in analysis.
There are many ways to search for the parameters, and any statistical text book will cover these.
However the least squares approach is popular because it is simple, requires few prior assump-
tions, and typically gives good results.
3.4.1 Polynomial regression
An obvious way to t smooth curves to experimental data is to nd a polynomial that passes
through the cloud of experimental data. This is known as polynomial regression. The nth order
polynomial to be regressed is
M() : y =
n
x
n
+
n1
x
n1
+
1
x +
0
(3.36)
108 Modelling
where we try different values of the (n+1) parameters in the vector until the difference between
the calculated dependent variable y is close to the actual measured value y. Mathematically the
vector of parameters is obtained by solving a least squares optimisation problem.
Given a set of parameters, we can compute the ith model prediction using
y
i
=
_
x
n
x
n1
x 1
_

_
_
_
_
_
_
_

n1
.
.
.

0
_
_
_
_
_
_
_
(3.37)
or written in compact matrix notation
y
i
= x
i

where x
i
is the data row vector for the ith observation. If all n observations are stacked vertically
together, we obtain the matrix system
_
_
_
_
_
y
1
y
2
.
.
.
y
N
_
_
_
_
_
=
_

_
x
n
1
x
n1
1
x
1
1
x
n
2
x
n1
1
x
2
1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
x
n
N
x
n1
N
x
N
1
_

_
. .
X
(3.38)
or y = X in a more compact matrix notation. The matrix of comprised of the stacked rows
of measured independent data, X, in Eqn. 3.38 is called the Vandermonde matrix or data matrix
and can be easily constructed in MATLAB using the vander command, although it is well known
that this matrix can become very illconditioned.
We can search for the parameters in a number of ways, but minimising the squared error is
a common and easy approach. In this case our objective function that we want to minimise
(sometimes called the cost function), is the summed squared error. In matrix notation, the error
vector is

def
= y X (3.39)
and the scalar cost function then becomes
J =

= (y X)

(y X)
= y

y y

X +

X
We want to choose such that J is minimised, ie a stationary point, thus we can set the partial
derivatives of J with respect to the parameters to zero,
4
J

= 0
= 2X

y + 2X

X (3.40)
which we can now solve for as
=
_
X

X
_
1
X

. .
pseudo-inverse
y (3.41)
As a consequence of the fact that we carefully chose our model structure in Eqn. 3.36 to be linear
in the parameters, , then the solution given by Eqn. 3.41 is analytic and therefore very reliable,
4
Ogata, [148, p938], gives some helpful rules when using matrix-vector differentials.
3.4. REGRESSING EXPERIMENTAL DATA BY CURVE FITTING 109
and straight forward to implement as opposed to nonlinear regression which require iterative
solution techniques.
This method of tting a polynomial through experimental data is called polynomial least-squares
regression. In general, the number of measurements must be greater (or equal) to the number
of parameters. Even with that proviso, the data matrix X

X can get very ill-conditioned, and


hence it becomes hard to invert in a satisfactorily manner. This problem occurs more often when
high order polynomials are used or when you are trying to over-parameterise the problem. One
solution to this problem is given in 3.4.1.
The matrix
_
X

X
_
1
X

is called the left pseudo-inverse of X, and is sometimes denoted X


+
.
The pseudo inverse is a generalised inverse applicable for even non-square matrices and is dis-
cussed in [150, p928]. MATLAB can compute
_
X

X
_
1
X

with the pseudo inverse command,


pinv, enabling the parameters to be evaluated simply by typing theta = pinv(X)
*
y, al-
though it is more efcient to simply use the backslash command, theta = X\y.
An example of polynomial curve tting using least-squares
Tabulated below is the density of air as a function of temperature. We wish to t a smooth
quadratic curve to this data.
Temperature [

C] 100 50 0 60 100 160 250 350


Air density [kg/m
3
] 1.98 1.53 1.30 1.067 0.946 0.815 0.675 0.566
200 0 200 400
0.5
1
1.5
2
2.5
Temperature [

C]
A
i
r

d
e
n
s
i
t
y
,

[
k
g
/
m
3
]


Raw Data
fitted curve
Figure 3.17: The density of air as a function
of temperature. Experimental data, , and a
tted quadratic curve. (See also Fig. 3.18 fol-
lowing for a higher-order polynomial t.)
To compute the three model parameters fromthe air density data we can run the following m-le.
Listing 3.3: Curve tting using polynomial least-squares
T = [-100 -50 0 60 100, 160 250 350]'; % Temperature, T
rho = [1.98, 1.53, 1.30, 1.067 0.946, 0.815, 0.675, 0.566]'; % Air density,
X = vander(T); % Vandermonde matrix
5 X = X(:,end-2:end); % Keep only last 3 columns
theta = X\rho; % Solve for , where = 1T
2
+2T +3
Ti = linspace(-130,400); % validate with a plot
110 Modelling
rho_pred = polyval(theta,Ti);
10 plot(T,rho,'o',Ti,rho_pred,'r-') % See Fig. 3.17.
The resulting curve is compared with the experimental data in Fig. 3.17.
In the example above, we constructed the Vandemonde data matrix explicitly, and solved for the
parameters using the pseudo-inverse. In practice however, we would normally simply use the
built-in MATLAB command polyfit which essentially does the same thing.
Improvements to the least squares estimation algorithm
There are many extensions to this simple multi-linear regression algorithm that try to avoid the
poor numerical properties of the scheme given above. If you consider pure computational speed,
then solving a set of linear equations is about twice as fast as inverting a matrix. Therefore instead
of Eqn. 3.41, the equivalent
X

X = X

y (3.42)
is the preferred scheme to calculate . MATLABS backslash operator, \, used in the example
above follows this scheme internally. We write it as if we expect an inverse, but it actually solves
a system of linear equations.
A numerical technique that uses singular value decomposition (SVD) gives better accuracy (for
the same number of bits to represent the data), than just applying Eqn 3.41, [161, 176]. Singular
values stem from the property that we can decompose any matrix T into the product of two
orthogonal matrices (U, V) and a diagonal matrix ,
T = UV

(3.43)
where due to the orthogonality,
UU

= I = U

U and VV

= I = V

V (3.44)
The diagonal matrix consists of the square roots of the eigenvalues of T

T which are called


the singular values of T, and the number that differ signicantly from zero is the rank of T. We
can make one further modication to Eqn 3.41 by adding a weighting matrix W. This makes the
solution more general, but often in practice one sets W= I. Starting with Eqn 3.42 including the
weighting matrix W
1
= G

G,
X

W
1
X = X

W
1
y (3.45)
X

GX = X

Gy (3.46)
Now we dene T
def
= GXand z
def
= Gy gives
T

T = T

z (3.47)
Now we take the singular value decomposition (SVD) of T in Eqn 3.47 giving
_
VU

__
UV

_
= VU

z (3.48)
V
2
V

= (3.49)
3.4. REGRESSING EXPERIMENTAL DATA BY CURVE FITTING 111
Multiplying both sides by V

and noting that is diagonal we get,

2
V

= U

z (3.50)
VV

. .
identity
= V
1
U

z (3.51)
= V
1
U

. .
pseudo inverse
z (3.52)
The inverse of is simply the inverse of each of the individual diagonal (and non-zero) elements,
since it is diagonal. The key point here is that we never in the algorithm needed to calculate the
possibly ill-conditioned matrix T

T. Consequently we should always use Eqn. 3.52 in preference


to Eqn. 3.41 due to the more robust numerical properties as shown in Listing 3.4.
Listing 3.4: Polynomial least-squares using singular value decomposition. This routine follows
from, and provides an alternative to Listing 3.3.
[U,S,V] = svd(X,0); % Use the economy sized SVD, UV

= X
theta2 = V
*
(S\U')
*
rho % = V
1
U

, Eqn. 3.52.
It does not take much for the troublesome X
T
X matrix to get ill-conditioned. Consider the tem-
perature/density data for air from Fig. 3.17, but in this case we will use temperature in degrees
Kelvin (as opposed to Celsius), and we will take data over slightly larger range of temperatures.
This is a reasonable experimental request, and so we should expect to be able to t a polynomial
in much the same way we did in Listing 3.3.
However as shown in Fig. 3.18, we cannot reliably t a fth-order polynomial using standard
least-squares to this data set, although we can reliably t such a 5th-order polynomial using the
SVD strategy of Eqn. 3.52. Note that MATLABs polyfit uses the reliable SVD strategy.
100 200 300 400 500 600 700
0
0.5
1
1.5
2
2.5
3
3.5
Temperature [degrees Kelvin]
A
i
r

d
e
n
s
i
t
y
,

[
k
g
/
m
3
]
Polynomial order = 5


= (X

X)
1
X

y
= V
1
U
T
y
Raw Data
standard LS
SVD fitted
LS using SVD
Standard leastsquares
Figure 3.18: Fitting a high-order polyno-
mial to some physical data, in this case
the density of air as a function of tempera-
ture in degrees Kelvin. Experimental data,
a tted quintic curve using standard least
squares, and one using the more robust
singular value decomposition. (See also
Fig. 3.17.)
A further rened regression technique is termed partial least squares (PLS), and is summarised
in [74]. Typically these schemes decompose the data matrix X, into other matrices that are
ordered in some manner that roughly corresponds to information. The matrices with the least
information (and typically most noise) are omitted, and the subsequent regression uses only the
remaining information.
The example on page 109 used the least squares method for estimating the parameters of an
algebraic equation. However the procedure for estimating a dynamic equation remains the same.
This will be demonstrated later in 6.7.
112 Modelling
Problem 3.3 Accuracy and numerical stability are very important when we are dealing with com-
puted solutions. Suppose we wish to invert
A =
_
1 1
1 1 +
_
where is a small quantity (such as nearly the machine eps)
1. What is the (algebraic) inverse of A?
2. Obviously if = 0 we will have trouble inverting since A is singular, but what does the
pseudo-inverse, A
+
, converge to as 0?
3.4.2 Nonlinear least-squares model identication
If the model equation is nonlinear in the parameters, then the solution procedure to nd the opti-
mum parameters requires a nonlinear optimiser rather than the relatively robust explicit relation
given by Eqn. 3.41 or equivalent. Nonlinear optimisers are usually based on iterative schemes
additionally often requiring good initial parameter estimates and even then may quite possibly
fail to converge to a sensible solution. There are many algorithms for nonlinear optimisation
problems including exhaustive search, the simplex method due to Nelder-Mead, and gradient
methods.
MATLAB provides a simple unconstrained optimiser, fminsearch, which uses the Nelder-Mead
simplex algorithm. A collection of more robust algorithms and algorithms to optimise con-
strained systems possibly with integer constraints is the OPTI toolbox
5
.
A nonlinear curve-tting example
The following biochemical example illustrates the solution of a nonlinear algebraic optimisation
problem. Many biological reactions are of the Michalis-Menton form where the cell number y(t)
is given at time t by the relation
y =
t
t + 1
(3.53)
Suppose we have some experimental data for a particular reaction given as
time, t 0 0.2 0.5 1 1.5 2 2.5
cell count, y 0 1.2 2.1 2.43 2.52 2.58 2.62
where we wish to estimate the parameters and in Eqn 3.53 using nonlinear optimisation tech-
niques. Note that the model equation (3.53) is nonlinear in the parameters. While it is impossible
to write the equation in the linear form y = f(t) as done in 3.4, it is possible to linearise the
equation (Lineweaver-Burke plot) by transforming the equation. However this will also trans-
form and bias the errors around the parameters. This is not good practice as it introduces bias
in the estimates, but does give good starting estimates for the nonlinear estimator. Transforming
Eqn 3.53 we get
y =


y
t
5
The OPTI toolbox is available from www.i2c2.aut.ac.nz
3.4. REGRESSING EXPERIMENTAL DATA BY CURVE FITTING 113
Thus plotting y/t against y should result in a straight line with an intercept of / and a slope of
1/.
Assuming we have the experimental data stored as
column vectors [t,y] in MATLAB, we could plot
t = [0, 0.2, 0.5:0.5:2.5]';
y = [0,1.2,2.1,2.43,2.52,2.58,2.62]';
3 % ignore divide-by-zero
plot(y./t,y,'o-')
0 1 2 3 4 5 6
1
1.5
2
2.5
3
3.5
y/t
c
e
l
l

c
o
u
n
t

y
which should given an approximately straight line (ignoring the rst and possibly the second
points). To nd the slope and intercept, we use the polyfit function to t a line and we get a
slope = 0.2686 and intercept = 2.98. This corresponds to = 11.1 and = 3.723.
Now we can rene these estimates using the fminsearch Nelder-Mead nonlinear optimiser.
We must rst construct a a small objection function le which evaluates the sum of the squared
error for a given set of trial parameters and the experimental data. This is succinctly coded as an
anonymous function in Listing 3.5 following.
Since we require the experimental data variables y and t in the objective function, but we are not
optimising with respect to them, we must pass these variables as additional parameters to the
optimiser.
Listing 3.5: Curve tting using a generic nonlinear optimiser
1 % Compute sum of square errors given trial and (t, y) data.
sse= @(theta,t,y) sum((y-theta(1)
*
t./(theta(2)
*
t+1)).2);
optns = optimset('Diagnostics','on','Tolx',1e-5);
theta = fminsearch(sse,[11.1 3.723]',optns,t,y) % Polish the estimates.
6 plot(t,y,'o',t, theta(1)
*
t./(theta(2)
*
t+1)) % Check nal t in Fig. 3.19.
Listing 3.5 returns the rened estimates for as

=
_

_
=
_
12.05
4.10
_
and a comparison of both the experimental data and the models predictions is given in Fig. 3.19.
Curve tting using the OPTI optimisation toolbox
The MATLABOPTIMISATION toolbox contains more sophisticated routines specically intended
for least-squares curve tting. Rather than write an objective function to compute the sum of
squares and then subsequently call a generic optimiser as we did in Listing 3.5, we can solve the
problem in a much more direct manner. The opti_lsqcurvefit is the equivalent routine in
the OPTI toolbox that solves least-squares regression problems.
Listing 3.6: Curve tting using the OPTI optimisation toolbox. (Compare with Listing 3.5.)
>> theta0 = [11,3]'; % Initial guess 0
114 Modelling
Figure 3.19: The tted (dashed) and experi-
mental, , data for a bio-chemical reaction.
The asymptotic nal cell count, /, is given
by the dashed horizontal line.
0 0.5 1 1.5 2 2.5
0
0.5
1
1.5
2
2.5
3
time
c
e
l
l

c
o
u
n
t


Exptal data
Best fit curve
/
>> F = @(x,t) x(1)
*
t./(x(2)
*
t+1); % f(, t) = 1t/(2t + 1)
>> >> theta = opti_lsqcurvefit(F,theta0,t,y)
4 theta =
12.0440
4.1035
Note that in Listing 3.6 we encapsulate the function in an anonymous function which is then
passed to the least-squares curve t routine, opti_lsqcurvefit.
Higher dimensional model tting
Searching for parameters where we have made two independent measurements is just like search-
ing when we have made one independent measurement, except that to plot the results we must
resort to contour or three-dimensional plots. This makes the visualisation a little more difcult,
but changes nothing in the general technique.
We will aim to t a simple four parameter, two variable function to model the compressibility
of water. Water, contrary to what we taught in school, is compressible, although this is only
noticeable at very high pressures. If we look up the physical properties for compressed water
in steam tables,
6
we will nd something like table 3.4. Fig. 3.20(a) graphically illustrates the
Table 3.4: Density of compressed water, ( 10
3
kg/m
3
)
Pressure (bar) Temperature,

C
0.01 100 200 250 300 350 374.15
100 1.0050 0.9634 0.8711 0.8065 0.7158
221.2 1.0111 0.9690 0.8795 0.8183 0.7391 0.6120
500 1.0235 0.9804 0.8969 0.8425 0.7770 0.6930 0.6410
1000 1.0460 1.0000 0.9242 0.8772 0.8244 0.7610 0.7299
strong temperature inuence on the density compared with pressure. Note how the missing data
represented by NaNs in MATLAB is ignored in the plot.
Our model relates the density of water as a function of temperature and pressure. The proposed
6
Rogers & Mayhew, Thermodynamic and Transport properties of Fluids, 3rd Edition, (1980), p11
3.4. REGRESSING EXPERIMENTAL DATA BY CURVE FITTING 115
0
100
200
300
400 0
500
1000
600
700
800
900
1000
1100

Pressure (bar)
Temperature,

C

T
r
u
e

d
e
n
s
i
t
y

k
g
/
m
3
650
700
750
800
850
900
950
1000
(a) True density of compressed water as a function of tem-
perature and pressure.
0 50 100 150 200 250 300 350 400
100
200
300
400
500
600
700
800
900
1000
1100
700
775
850
925
1e+003
1e+003
700
775
850 925 1e+003
Temperature (deg C)
P
r
e
s
s
u
r
e

(
b
a
r
)
density (kg/m3)
(b) Model t
Figure 3.20: A 2D model for the density of compressed water. In Fig. 3.20(b), the mark experi-
mental data points used to construct the 2-D model given as contour lines.
model structure is
= P
k
exp
_
a +
b
T
+
c
T
3
_
(3.54)
where the constants (model parameters ) need to be determined. We dene the parameters as;

def
=
_
a b c k

(3.55)
Again the approach is to minimise numerically the sum of the squared errors using an optimiser
such as fminsearch. We can check the results of the optimiser using a contour plot with the
experimental data from Table 3.4 superimposed.
The script le in Listing 3.7 calls the minimiser which in turn calls the anonymous function
J_rhowat which given the experimental data and proposed parameters returns the sum of
squared errors. This particular problem is tricky, since it is difcult to know appropriate starting
guesses for , and the missing data must eliminated before the optimisation. Before embarking
on the full nonlinear minimisation, I rst try a linear tting to obtain good starting estimates for
. I also scale the parameters so that the optimiser deals with numbers around unity.
Listing 3.7: Fitting water density as a function of temperature and pressure
rhowat = @(a,P,T) P.a(1).
*
exp(a(2) + ...
1e2
*
a(3)./T + 1e7
*
a(4)./T.3) % Assumed model = P
k
exp
_
a +
b
T
+
c
T
3
_
J_rhowat = @(a,P,T,rho) ...
4 norm(reshape(rho,[],1)-reshape(rhowat(a,P,T),[],1)); % SSE J =

( )
2
T = [0.01, 100, 200, 250,300,350, 374.15]'; % Temp [deg C]
P = [100 221.2 500 1000]'; % Pressure [Bar]
rhof = 1.0e3
*
[1.00250, 0.9634, 0.8711, 0.8065, 0.7158, NaN, NaN; ...
9 1.0111, 0.9690, 0.8795, 0.8183, 0.7391, 0.6120, NaN; ...
1.0235, 0.9804, 0.8969, 0.8425, 0.7770, 0.6930, 0.6410; ...
1.0460, 1.0000, 0.9242, 0.8772, 0.8244, 0.7610, 0.7299]; % density kg/m
3
[TT,PP] = meshgrid(T+273,P); Tv = TT(:); Pv = PP(:); % vectorise
116 Modelling
14 A = [ones(size(Tv)), 1.0e2 ./Tv, 1.0e7 ./Tv.3, log(Pv)]; % Scaled data matrix
idx = isnan(rhof(:)); % nd missing data points
rhofv = rhof(:); rhofv(idx) = []; % remove bad points
Tv(idx) = []; Pv(idx) = []; A(idx,:) = [];
theta = A\log(rhofv); % rst (linear) estimate
19
% Do nonlinear t
theta_opt = fminsearch(@(theta) J_rhowat(theta,Pv,Tv,rhofv),theta);
[Ti,Pi] = meshgrid([0.01:10:370]+273,[100:100:1000]); % Compare t with data
24 rho_est = rhowat(theta_opt,Pi,Ti);
Fig. 3.20(b) compares contour plots of the density of water as a function of pressure and temper-
ature derived from the experimental data and the tted model. The shows the location of the
experimental data points. The solid contour lines give the predicted density of water compared
with the contours derived from the experimental data (dashed lines). The optimum parameters
found above are

=
_

_
a
b
c
k
_

_
=
_

_
5.5383
5.8133 10
2
1.8726 10
7
0.0305
_

_
(3.56)
3.4.3 The condence of the optimised parameters
Finding the optimum model parameters to t the data is only part of the task. A potentially
more difcult objective is to try to establish how precise these optimum parameters are, or what
the condence regions of the parameters are. simply expressing the uncertainty of your model as
parameter values some interval is a good rst approximation, but it does neglect the interaction
of the other parameters, the so-called correlation effect.
To establish the individual condence limits of the parameters, we need to know the following:
1. The n optimum parameters from the m experimental observations. (For the nonlinear
case, this can be found using a numerical optimiser)
2. A linearised data matrix Xcentered about the optimised parameters.
3. The measurement noise s
Yi
(This can be approximated from the sum of the squared error
terms, or from prior knowledge.)
4. Some statistical parameters such as the t-statistic as a function of condence interval (90%,
95% etc) and degrees of freedom. This is easily obtained from statistical tables or using the
qt routine from the STIXBOX collection mentioned on page 3 for m-le implementations of
some commonly used statistical functions.
The condence interval for parameter
i
is therefore

i
t
(1/2)
s
Yi
_
P
i,i
(3.57)
where t
(1/2)
is the t-statistic evaluated at = n m (number of observations less the number
of parameters) degrees of freedom and P
i,i
are the diagonal elements of the covariance matrix P.
The measurement noise (if not already approximately known) is
s
Yi

_
s
2
r
=

n m
(3.58)
3.4. REGRESSING EXPERIMENTAL DATA BY CURVE FITTING 117
and the covariance matrix P is obtained from the data matrix. Note that if we assume we have
perfect measurements and a perfect model, then we would expect that the sum of the errors
will be exactly zero given the true parameters. This is consistent with Eqn 3.58 when

= 0
although of course this occurs rarely in practice!
An example of establishing condence intervals for a nonlinear model
This section was taken from [87, p198], but with some modications and corrections. Himmel-
blau, [87, p198], gives some reaction data as:
Pressure, p 20 30 35 40 50 55 60
rate, r 0.068 0.0858 0.0939 0.0999 0.1130 0.1162 0.1190
and proposes a 2 parameter nonlinear model of the form
r =

0
p
1 +
1
p
(3.59)
Now suppose that we use a nonlinear optimiser programto search for the parameters such that
the sum of squared error is minimised.
min

=
n

i=1
(r
i
r
i
)
2
=
_
(r r)

(r r)
_
(3.60)
If we do this using say the same technique as in 3.4.2, we will nd that the optimum parameters
are approximately
=
_

0

1
_
=
_
5.154 10
3
2.628 10
2
_
(3.61)
and the raw data and model predictions are given in Fig 3.21.
Now the linearised data matrix is a n by m matrix where n is the number of observations and m
is the number of parameters. The partial derivatives of 3.59 with respect to the parameters are;
r

0
=
p
1 +
1
p
,
r

1
=

0
p
2
(1 +
1
p)
2
and the data matrix Xis dened as
X
i,j
def
=
r
i

j
(3.62)
Thus each row of X are the partial derivatives of that particular observation with respect for the
parameters. The covariance matrix P is dened as
P
def
=
_
X

X
_
1
(3.63)
and should be positive denite and symmetric just as the variance should always be greater
than, or equal to zero. However in practice this requirement may not always hold owing to poor
numerical conditioning. The diagonal elements are the variances we will use for the individual
condence limits. When using MATLAB, it is better to look at the singular values, or check the
rank of X

Xbefore doing the inversion.


Listing 3.8 ts parameters to the nonlinear reaction rate model and also illustrates the uncertain-
ties.
118 Modelling
Listing 3.8: Parameter condence limits for a nonlinear reaction rate model
1 p = [20,30,35,40,50,55,60]'; % Pressure, P
r = [0.068,0.0858,0.0939,0.0999,0.1130,0.1162,0.1190]'; % Reaction rate, r
Rxn_rate = @(x,p) x(1)
*
p./(1+x(2)
*
p); % r =

0
p
1+
1
p
theta = lsqcurvefit(Rxn_rate,[5e-3 2e-2]',p,r); % Rene estimate of parameters
6 nobs = length(p); mpar = length(theta); % # of observations & parameters
r_est = Rxn_rate(theta,p);% Predicted reaction rate r(, p)
j = sum((r-r_est).2); % sum of squared errors J =

2
11 d1= 1+theta(2)
*
p;
X = [p./d1, -theta(1)
*
p.
*
p./d1.2]; % Data gradient matrix, Eqn. 3.62.
C = inv(X'
*
X); % not numerically sound ??
% t-distribution statistics
16 pt = @(x,v) (x0).
*
(1-0.5
*
betainc(v./(v+x.2),v/2,0.5)) + ...
(x<0).
*
(0.5
*
betainc(v./(v+x.2),v/2,0.5))
qt = @(P,v) fsolve(@(x) pt(x,v)-P,sqrt(2)
*
erfinv(2
*
P-1), ...
optimset('display','off'));
21 alpha = 0.05; % CI level (97.5%)
nu = nobs-mpar; % Degrees of freedom = n m
t = qt(1-alpha,nu); % t statistic from approx function
sy = sqrt(j/nu); % approx measurement noise std
b_ci = t
*
sy
*
diag(C); % condence regions
This gives 95% condence limits for this experiment
7
as
_
5.1061 10
3
2.2007 10
2
_
< <
_
5.2019 10
3
3.0553 10
2
_
(3.64)
A plot of the raw data (), the model with the optimum estimated parameters and the associated
error bounds using Eqn. 3.64 is given in Fig. 3.21. Note while the model prediction is quite good,
the region dened by the 95% condence on the parameters is surprisingly large. The error
bounds were generated by simulating the model with the lower and upper bounds of Eqn 3.64
respectively.
The condence region (an ellipse in the two variable case) can also be plotted. This gives a deeper
understanding of the parameter interactions, but the visualisation becomes near impossible as
the number of parameters gets much larger than 3. The region for this example is evaluated the
following section.
The condence regions of the parameters
An approximate condence region can be constructed by linearising the nonlinear model about
the optimum parameters. The covariance of the parameter estimate is
cov(b)
_
X

X
_
1

Yi
(3.65)
where b is the estimated parameter and is the true, (but unknown) parameter. Now the con-
dence region, an ellipse in two parameter space (an ellipsoid in three diameter space) is the region
7
These gures differ from the worked example in Himmelblau. I think he swapped two matrices by mistake, then
continued with this error.
3.4. REGRESSING EXPERIMENTAL DATA BY CURVE FITTING 119
10 20 30 40 50 60 70
0.06
0.07
0.08
0.09
0.1
0.11
0.12
0.13
0.14
0.15
pressure
r
a
t
e
Experimental data (o) & model fit


Data
model
Figure 3.21: The experimental raw
data (), model (), and associated
95% error bounds (dotted) for the
optimised model t.
that with a condence limit of say 95% we are certain that the true parameter () lies within.
( b)

(X

X) ( b) = s
2

Yi
mF
1
[m, n m] (3.66)
where F[m, n m] is the upper limit of the F distribution for m and n m degrees of freedom.
This value can be found in statistical tables. Note that the middle term of Eqn 3.66 is X

X and
not the inverse of this.
For the previous example, we can plot the ellipse about the true optimised parameters. Fig 3.22
shows the 95% condence ellipse about the optimised parameter (marked with a ) and the
individual condence lengths superimposed from Eqn. 3.64. Since the ellipse is slanted, we note
that the parameters are correlated with each other.
4.6 4.8 5 5.2 5.4 5.6 5.8
0.02
0.022
0.024
0.026
0.028
0.03
0.032

2
95% Confidence limit
Figure 3.22: The approximate 95% con-
dence region in 2 parameter space with
the individual condence intervals super-
imposed (marked as ).
The ellipse denes an area in which the probability that the true parameter vector lies is better
than 95%. If we use the parameter points marked as a in Fig. 3.22, then the model prediction
will differ from the prediction using the optimised parameter vector. This difference is shown as
the errorbars in the lower plot of Fig. 3.22. Note that these errorbars are much smaller than the
errorbars I obtained from considering only the condence interval for each individual parameter
120 Modelling
given in Fig 3.21. Here, owing to the correlation (slanting of the ellipse in Fig 3.22), the parameters
obtained when neglecting the correlation lie far outside the true 95% condence region. Hence
the bigger errorbars.
3.5 Numerical tools for modelling
Unfortunately there are no known methods of solving Eqn 1 (a nonlinear differential equation).
This, of course, is very disappointing.
M. Braun, [33, p493]
Since differential equations are difcult to solve analytically, we typically need to resort to nu-
merical methods as described in many texts such as [39, 41, 46, 94, 104, 169] and in addition to
[201].
Differential equations are broadly separated into two families:
ODEs Ordinary differential equations (ODEs) where time is the only independent variable. The
solution to ODEs can be described using standard plots where the dependent variables are
plotted on the ordinate or y axis against time on the x axis.
PDEs Partial differential equations (PDEs) are where space (and perhaps time) are independent
variables. To display the solution of PDEs, contour maps or 3Dplots are required in general.
Generally PDEs are much harder to solve than ODEs and are beyond the scope of this text.
The solution of nonlinear differential equations
One of the most important tools in the desk-top experimenters collection, is a good numerical
integrator. We need numerical integrators whenever we are faced with a nonlinear differential
equation which is intractable by any other means. MATLAB supplies a number of different nu-
merical integrators optimised for different classess of problems. Typically the 4th/5th dual order
Runge-Kutta implementation, ode45, is a good rst choice.
To use the integrators, you must write a function subroutine that contains your differential system
to be solved which will be called by the numerical integration routine.
1. The script le that calls the integrator (eg: ode45) with name of the function subroutine to
be integrated and parameters including initial conditions, tolerance and time span.
2. The function subroutine (named in the script le) that calculates the derivatives as a func-
tion of the independent variable (usually time), and the dependent variable (often x).
We will demonstrate this procedure by constructing templates of the above two les to solve a
small nonlinear differential equation. One can reuse this template as the base for solving other
ODE systems.
ODE template example
Suppose our task is to investigate the response of the nonlinear pendulum system given in
Eqn. 3.6 and compare this with the linearised version. The script le given in Listing 3.9 com-
putes the angle = x
1
(t) trajectory for both the nonlinear and linear approximation.
3.5. NUMERICAL TOOLS FOR MODELLING 121
Listing 3.9: Comparing the dynamic response of a pendulum to the linear approximation
g=8.81; l=1; m = 5; T_c=0; % constants
xdot = @(t,x) [x(2); -g/l
*
sin(x(1)) + T_c/m/l2]; % dx/dt
x0 = [1,1]'; % start position x(0)
5 [t,x]= ode45(xdot,[0,10],x0); % Integrate nonlinear
% Now try linear system
A = [0 1; -g/l 0]; B = [0;0]; C = [1,0];D=0;
tv = linspace(0,10)';
10 [y2,t2]=lsim(ss(A,B,C,D),0
*
tv,tv,x0);
plot(t,x(:,1),t2,y2) % See Fig. 3.23.
Note how the trajectories for the nonlinear (solid) result as calculated from ode45 and linear
approximation calculated using lsim gradually diverge in Fig. 3.23.
0 2 4 6 8 10
1.5
1
0.5
0
0.5
1
1.5
time
x
(
t
)


Non Linear
Linearised Figure 3.23: The trajectory of the true non-
linear pendulum compared with the lin-
earised approximation.
Problem 3.4 1. One of my favourite differential equations is called the Van der Pol equation;
m
d
2
y
dt
2
b
_
1 y
2
_
dy
dt
+ky = 0
where m = 1, b = 3 and k = 2. Solve the equation for 0 < t < 20 using both ode23 and
ode45. Sketch the solution. Which routine is better? You will need to create a function
called vandepol(t,y) which contains the system of equations to be solved.
2. A damped forced pendulum is an example of a chaotic system. The dynamic equations are
d
dt
=

q
sin +g cos (3.67)
d
dt
= (3.68)
d
dt
=
d
(3.69)
where there are three states, (x =
_

), and three parameters, ( =


_
q g
d

).
Simulate this system for 0 t 500 starting from x =
_
1 2 0.3

and using
=
_
2 1.5 2/3

as parameters. Be warned, this may take some computer time!


122 Modelling
Problem 3.5 A particularly nasty nonlinear chemical engineering type model is found in [83]. This
is a model of two CSTRs
8
in series, cooled with a co-current cooling coil. The model equations
are:

C
a1
=
q
V
1
(C
af
C
a1
) k
0
C
a1
exp
_

E
RT
1
_

T
1
=
q
V
1
(T
f
T
1
) +
(H)k
0
C
a1
c
p
exp
_

E
RT
1
_
+

c
c
pc
c
p
V
1
q
c
_
1 exp
_

hA
1
q
c

c
c
pc
__
(T
cf
T
1
)

C
a2
=
q
V
2
(C
a1
C
a2
) k
0
C
a2
exp
_

E
RT
2
_

T
2
=
q
V
2
(T
1
T
2
) +
(H)k
0
C
a2
c
p
exp
_

E
RT
2
_
+

c
c
pc
c
p
V
2
q
c
_
1 exp
_

hA
2
q
c

c
c
pc
__ _
T
1
T
2
+ exp
_

hA
1
q
c

c
c
pc
_
(T
cf
T
1
)
_
where the state, control, disturbance and measured variables are dened as
x
def
=
_
C
a1
T
1
C
a2
T
2

, u
def
= q
c
, d
def
=
_
C
af
T
cf

y
def
= C
a2
and the parameters values are given in Table 3.5.
Table 3.5: The parameter values for the CSTR model
description variables value units
reactant ow q 100 l/min
conc. of feed reactant A C
af
1.0 mol/l
temp. of feed T
f
350 K
temp. of cooling feed T
cf
350 K
volume of vessels V
1
= V
2
100 l
heat transfer coeff. hA
1
= hA
2
1.67 10
5
J/min.K
pre-exp. constant k
0
7.2 10
10
min
1
E/R E/R 1.0 10
4
K
reaction enthalpy H 4.78 10
4
J/mol
uid density
c
= 1.0 g/l
heat capacity c
p
= c
pc
0.239 J/g.K
Note that the model equations are nonlinear since the state variable T
1
(amongst others) is a
appears nonlinearly in the differential equation. In addition, this model is referred to as control
nonlinear, since the manipulated variable enters nonlinearly. Simulate the response of the con-
centration in the second tank (C
a2
) to a step change of 10% in the cooling ow using the initial
conditions given in Table 3.6.
You will need to write a .m le containing the model equations, and use the integrator ode45.
Solve the system over a time scale of about 20 minutes. What is unusual about this response?
How would you expect a linear system to behave in similar circumstances?
Problem 3.6 Develop a MATLAB simulation for the high purity distillation column model given in
[140, pp459]. Verify the open loop responses given on page 463. Ensure that your simulation is
easily expanded to accommodate a different number of trays, different relative volatility etc.
8
continuously stirred tank reactors
3.5. NUMERICAL TOOLS FOR MODELLING 123
Table 3.6: The initial state and manipulated variables for the CSTR simulation
description variable value units
coolant ow q
c
99.06 l/min
conc. in vessel 1 C
a1
8.53 10
2
mol/l
temp. in vessel 1 T
1
441.9 K
conc. in vessel 2 C
a2
5.0 10
3
mol/l
temp. in vessel 2 T
2
450 K
Problem 3.7 A slight complexity to the simple ODE with specied initial conditions is where we
still have the ODE system, but not all the initial conditions. In this case we may know some of the
end conditions instead, thus the system is in principle able to be solved, but not in the standard
manner; we require a trial and error approach. These types of problems are called two point
boundary problems and we see them arise in heat transfer problems and optimal control. They
are so called two point boundary problems because for ODEs we have two boundaries for the
independent variable; the start and the nish. Try to solve the following from [196, p178].
A uid enters an immersed cooling coil 10m long at 200

C and is required to leave at 40

C. The
cooling medium is at 20

C. The heat balance is
d
2
T
dx
2
= 0.01(T 20)
1.4
(3.70)
where the initial and nal conditions are;
T
x=0
= 200, T
x=10
= 40
To solve the system, we must rewrite Eqn 3.70 as a systemof two rst order differential equations,
and supply a guess for the missing initial condition
dT
dx x=0
=? We can then integrate the system
until x = 10 and check that the nal condition is as required. Solve the system.
Hint: Try 47 <
dT
dx x=0
< 42.
3.5.1 Differential/Algebraic equation systems and algebraic loops
In many cases when deriving models from rst principals, we end up with a coupled system
of some differential equations, and some algebraic equations. This is often due to our practice
of writing down conservation type equations (typically dynamic), and constraint equations, say
thermodynamic, which are typically algebraic. Such a system in general can be written as
f ( x, x, t) = 0 (3.71)
and is termed a DAE or differential/algebraic equation system. If we assume that our model
is well posed, that is we have some hope of nding a solution, then we expect that we have
the same number of variables as equations, and it follows that some of the variables will not
appear in the differential part, but only in the algebraic part. We may be able to substitute those
algebraic variables out, such that we are left with only ODEs, which can then be solved using
normal backward difference formula numerical schemes such as rk2.m. However it is more
likely that we cannot extract the algebraic variables out, and thus we need special techniques to
solve these sorts of problems (Eqn. 3.71) as one.
In a now classic article titled Differential/Algebraic Equations are not ODEs, [158] gives some in-
sight into the problems. It turns out that even for linear DAE systems, the estimate of the error,
124 Modelling
which is typically derived from the difference between the predictor and the corrector, does not
decrease as the step size is reduced. Since most normal ODE schemes are built around this as-
sumption, they will fail. This state of affairs will only occur with certain DAE structures where
the nilpotency or index is 3. Index 2 systems also tend to cause BDF schemes to fail, but
can be tackled using other methods. The index problem is important because in many times it
can be changed (preferably reduced to less than two), by rearranging the equations. Automated
modelling tools tend, if left alone, to create overly complex models with a high index that are im-
possible to solve. However if we either by using an intelligent symbolic manipulator or human,
change these equations, we may be able to reduce the index.
The difculties of algebraic loops
One reason that computer aided modelling tools such as SIMULINK have taken so long to mature
is the problem of algebraic loops. This is a particular problem when the job of assembling the
many different differential and algebraic equations in an efcient way is left to a computer.
Suppose we want to simulate a simple feedback process where the gain is a saturated function of
the output, say
K(y) = max(min(y, 5), 0.1)
If we simulate this in Simulink using
1
s+1
Transfer Fcn
Step
Scope
Saturation
Product
1
Gain1
1
Gain
we run into an Algebraic Loop error. MATLAB returns the following error diagnostic (or something
similar):
Warning: Block diagram sgainae contains 1 algebraic loop(s).
Found algebraic loop containing block(s):
sgainae/Gain1
sgainae/Saturation (discontinuity)
sgainae/Product (algebraic variable)
Discontinuities detected within algebraic loop(s), may have trouble solving
and the solution stalls.
The simplest way to avoid these types of problems is to insert some dynamics into the feedback
loop. In the example above, we could place a transfer function with a unit gain and very small
time constant in place of the algebraic gain in the feedback loop. While we desire the dynamics
of the gain to be very fast so that it approximates the original algebraic gain, overly fast dynamics
cause numerical stability problems, hence there is a trade off.
3.6. LINEARISATION OF NONLINEAR DYNAMIC EQUATIONS 125
3.6 Linearisation of nonlinear dynamic equations
While most practical engineering problems are nonlinear to some degree, it is often useful to
be able to approximate the dynamics with a linear differential equation which means we can
apply linear control theory. While it is possible to design compensators for the nonlinear system
directly, this is in general far more complicated, and one has far fewer reliable guidelines and
recipes to follow. One particular version of nonlinear controller design called exact nonlinear
feedback is discussed briey in 8.6.
Common nonlinearities can be divided into two types; hard nonlinearities such as hysterisis,
stiction, and dead zones, and soft nonlinearities such as the Arrhenius temperature depen-
dency, power laws, etc. Hard nonlinearities are characterised by functions that are not differen-
tiable, while soft nonlinearities are. Many strategies for compensating for nonlinearities are only
applicable for systems which exhibit soft nonlinearities.
We can approximate soft nonlinearities by truncating a Taylor series approximation of the origi-
nal system. The success of this approximation depends on whether the original function has any
non-differentiable terms such as hysterisis, or saturation elements, and how far we deviate from
the point of linearisation. This section follows the notation of [76, 3.10].
Suppose we have the general nonlinear dynamic plant
x = f (x(t), u(t)) (3.72)
y = g(x, u) (3.73)
and we wish to nd an approximate linear model about some operating point (x
a
, u
a
). A rst-
order Taylor series expansion of Eqns 3.723.73 is
x f (x
a
, u
a
) +
f
x

x=xa
u=ua
(x(t) x
a
) +
f
u

x=xa
u=ua
(u(t) u
a
) (3.74)
y g(x
a
, u
a
) +
g
x

x=xa
u=ua
(x(t) x
a
) +
g
u

x=xa
u=ua
(u(t) u
a
) (3.75)
where the ijth element of the Jacobian matrix f /x is f
i
/x
j
. Note that for linear systems, the
Jacobian is simply Ain this notation, although some authors dene the Jacobian as the transpose
of this, or A
T
.
The linearised system Eqn 3.743.75 can be written as
x = Ax(t) +Bu(t) +E (3.76)
y = Cx(t) +Du(t) +F (3.77)
where the constant matrices A, B, C and Dare dened as
A =
f
x

x=xa
u=ua
, B =
f
u

x=xa
u=ua
C =
g
x

x=xa
u=ua
, D =
g
u

x=xa
u=ua
and the bias vectors E and F are
E = f (x
a
, u
a
)
f
x

x=xa
u=ua
x
a

f
u

x=xa
u=ua
u
a
F = g(x
a
, u
a
)
g
x

x=xa
u=ua
x
a

g
u

x=xa
u=ua
u
a
126 Modelling
Note that Eqns 3.763.77 are almost in the standard state-space form, but they include the extra
bias constant matrices E and F. It is possible by introducing a dummy unit input to convert this
form into the standard state-space form,
x = Ax +
_
B E

_
u
1
_
(3.78)
y = Cx +
_
D F

_
u
1
_
(3.79)
which we can then directly use in standard linear controller design routines such as lsim.
In summary, the linearisation requires one to construct matrices of partial derivatives with respect
to state and input. In principle this can be automated using a symbolic manipulator provided the
derivatives exist. In both the SYMBOLIC TOOLBOX and in MAPLE we can use the jacobian
command.
Example: Linearisation using the SYMBOLIC toolbox. Suppose we want to linearise the nonlin-
ear system
x =
_
ax
1
exp
_
1
b
x2
_
cx
1
(x
2
u
2
)
_
at an operating point, x
a
= [1, 2]
T
, u
a
= 20.
First we start by dening the nonlinear plant of interest,
>> syms x1 x2 a b c u real
>> x = [x1 x2]';
3 >> fx = [a
*
x(1)
*
exp(1-b/x(2)); c
*
x(1)
*
(x(2)-u2)]
fx =
[ a
*
x1
*
exp(1-b/x2)]
[ c
*
x1
*
(x2-u2)]
Now we are ready to construct the symbolic matrix of partial derivatives,
>> Avar = jacobian(fx,x)
Avar =
[ a
*
exp(1-b/x2), a
*
x1
*
b/x22
*
exp(1-b/x2)]
4 [ c
*
(x2-u2), c
*
x1]
>> Bvar = jacobian(fx,u)
Bvar =
[ 0]
[ -2
*
c
*
x1
*
u]
9 >> Evar = fx - Avar
*
x - Bvar
*
u
Evar =
[ -a
*
x1
*
b/x2
*
exp(1-b/x2)]
[ -c
*
x1
*
x2+2
*
u2
*
c
*
x1]
We can substitute a specic set of constants, say, a = 5, b = 6, c = 7 and an operating point
x = [1, 2]
T
, u = 20, into the symbolic matrices to obtain the numeric matrices.
>> A = subs(Avar,{a,b,c,x1,x2,u},{5,6,7,1,2,20})
A =
3 1.0e+003
*
3.6. LINEARISATION OF NONLINEAR DYNAMIC EQUATIONS 127
0.0007 0.0010
-2.7860 0.0070
>> B = subs(Bvar,{a,b,c,x1,x2,u},{5,6,7,1,2,20})
B =
8 [ 0]
[ -280]
>> E = subs(Evar,{a,b,c,x1,x2,u},{5,6,7,1,2,20})
E =
1.0e+003
*
13 -0.0020
5.5860
At this point we could compare in simulation the linearised version with the full nonlinear model.
3.6.1 Linearising a nonlinear tank model
Suppose we wish to linearise the model of the level in a tank given on page 88 where the tank
geometry is such that A = 1. The nonlinear dynamic system for the level h is then simplied to
dh
dt
= k

h +F
in
For a constant ow in, F
ss
in
, the resulting steady state level is given by noting that dh/dt = 0, and
so
h
ss
=
_
F
ss
in
k
_
2
We wish to linearise the system about this steady-state, so we will actually work with deviation
variables,
x
def
= h h
ss
, u
def
= F
in
F
ss
in
Now following Eqn. 3.74, we have

h = x = f(h
ss
, F
ss
in
)
. .
=0
+
f
h
(h h
ss
) +
f
F
in
(F
in
F
ss
in
)
Note that since f/h = k/(2

h
ss
), then our linearised model about (F
ss
in
, h
ss
) is
x =
k
2

h
ss
x +u
which is in state-space form in terms of deviation variables x and u.
We can compare the linearised model with the nonlinear model in Fig. 3.24 about a nominal input
ow of F
ss
in
= 2 and k = 2 giving a steady-state level of h
ss
= 4. Note that we must subtract and
add the relevant biases when using the linearised model.
An alternative, and much simpler way to linearise a dynamic model is to use linmod which
extracts the Jacobians from a SIMULINK model by nite differences.
Listing 3.10: Using linmod to linearise an arbitrary SIMULINK module.
1 k=1; Fin_ss = 2; % Model parameters and steady-state input
hss = (Fin_ss/k)2 % Steady-state level, h
ss
[A,B,C,D] = linmod('sNL_tank_linmod',hss,Fin_ss) % Linearise
128 Modelling
level, h
level
1
s
To Workspace
simout
StateSpace
x = Ax+Bu
y = Cx+Du
Scope
Repeating
Sequence
Stair
Math
Function
sqrt
Gain
k
Fin_ss
Fin_ss
Bias1
u+Lss
Bias
uFin_ss
Add1 Add
(a) A SIMULINK nonlinear tank model and linear state-space model for comparison
0 10 20 30 40 50
3
4
5
6
7
8
9
10
time
l
e
v
e
l
linearised response
full nonlinear response
(b) Nonlinear and linearised model comparison
Figure 3.24: Comparing the linearised model with the full nonlinear tank level system
A =
6 -0.2500 % Note k/(2

h
ss
) = 1/4
B =
1
C =
1
11 D =
0
Quantifying the extent of the nonlinearity
It is important for the control designer to be able to quantify, if only approximately, the extent
of the open-loop process nonlinearity. If for example the process was deemed only marginally
nonlinear, then one would be condent a controller designed assuming a linear underlying plant
would perform satisfactory. On the other hand, if the plant was strongly nonlinear, then such a
linear controller may not be suitable. Ideally we would like to be able to compute a nonlinear
3.7. SUMMARY 129
metric, say from 0 (identically linear) to 1 (wildly nonlinear) that quanties this idea simply by
measuring the openloop input/output data. This of course is a complex task, and is going to be
a function of the type input signals, duration of the experiment, whether the plant is stable or
unstable, and if feedback is present.
One such strategy is proposed in [82] and used to assess the suitability of linear control schemes
in [177]. The idea is to compute the norm of the difference between the best linear approxima-
tion and the true nonlinear response for the worst input trajectory within a predetermined set
of trajectories. This is a nested optimisation problem with a min-max construction. Clearly the
choice of linear model family from which to choose the best one, and the choice of the set of input
trajectories will have an effect on the nal computed nonlinear measure.
3.7 Summary
Stuart Kauffman in a New Scientist article
9
succinctly paraphrased the basis of the scientic
method. He said
. . . state the variables, the laws linking the variables, and the initial and boundary
conditions, and from these compute the forward trajectory of the biosphere.
In actual fact he was lamenting that this strategy, sometimes known as scientic determinism
voiced by Laplace in the early 19th century was not always applicable to our world as we under-
stand it today. Nonetheless, for our aim of modeling for control purposes, this philosophy has
been, and will remain for some time I suspect, to be remarkably successful.
Modelling of dynamic systems is important in industry. These types of models can be used for
design and or control. Effective modelling is an art. It requires mathematical skill and engi-
neering judgement. The scope and complexity of the model is dependent on the purpose of the
model. For design studies a detailed model is usually required, although normally only steady
state models are needed at this stage. For control, simpler models (although dynamic) can be
used since the feedback component of the controller will compensate for any model-plant mis-
match. However most control schemes require dynamic models which are more complicated
than the steady state equivalent.
Many of the dynamic models used in chemical engineering applications are built from conser-
vation laws with thermodynamic constraints. These are often expressed as ordinary differential
equations where we equate the rate of accumulation of something (mass or energy) to the inputs,
outputs and generation in a dened control volume. In addition there may be some restrictions
on allowable states, which introduces some accompanying algebraic equations. Thus general
dynamic models can be expressed as a combination of dynamic and algebraic relations
dx
dt
= f (x, u, , t) (3.80)
0 = g(x, u, t) (3.81)
which are termed DAEs (differential and algebraic equations), and special techniques have been
developed to solve them efciently. DAEs crop up frequently in automated computer modelling
packages, and can be numerically difcult to solve. [133] provides more details in this eld.
Steady state models are a subset of the general dynamic model where the dynamic term, Eqn
3.80, is set to equal zero. We now have an augmented problem of the form Eqn 3.81 only. Linear
9
Stuart Kauffman, God of creativity, 10 May 2008, NewScientist, pp52-53
130 Modelling
dynamic models are useful in control because of the many simple design techniques that exist.
These models can be written in the form
x = Ax +Bu (3.82)
where the model structure and parameters are linear and often time invariant.
Models are obtained, at least in part, by writing the governing equations of the process. If these
are not known, experiments are needed to characterise fully the process. If experiments are used
the model is said to be heuristic. If the model has been obtained from detailed chemical and
physical laws, then the model is said to be mechanistic. In practice, most models are a mixture
of these two extremes. However what ever model is used, it still is only an approximation to the
real world. For this reason, the assumptions that are used in the model development must be
clearly stated and understood before the model is used.
Chapter 4
The PID controller
4.1 Introduction
The PID controller is the most common general purpose controller in the chemical process indus-
try today. It can be used as a stand-alone unit, or it can be part of a distributed computer control
system. Over 30 years ago, PID controllers were pneumatic-mechanical devices, whereas nowa-
days they are implemented in software in electronic controllers. The electronic implementation
is much more exible than the pneumatic devices since the engineer can easily re-program it to
change the conguration of things like alarm settings, tuning constants etc.
Once we have programmed the PID controller, and have constructed something, either in soft-
ware or hardware to control, we must tune the controller. This is surprisingly tricky to do success-
fully, but some general hints and guidelines will be presented in 4.6. Finally, the PID controller
is not perfect for everything, and some examples of common pitfalls when using the PID are
given in 4.8.
4.1.1 P, PI or PID control
For many industrial process control requirements, proportional only control is unsatisfactory
since the offset cannot be tolerated. Consequently the PI controller is probably the most com-
mon controller, and is adequate when the dynamics of the process are essentially rst or damped
second order. PID is satisfactory when the dynamics are second or higher order. However the
derivative component can introduce problems if the measured signal is noisy. If the process
has a large time delay (dead time), derivative action does not seem to help much. In fact PID
control nds it difcult to control processes of this nature, and generally a more sophisticated
controller such as a dead time compensator or a predictive controller is required. Processes that
are highly underdamped with complex conjugate poles close to the imaginary axis are also dif-
cult to control with a PID controller. Processes with this type of dynamic characteristics are rare
in the chemical processing industries, although more common in mechanical or robotic systems
comprising of exible structures.
My own impressions are that the derivative action is of limited use since industrial measurements
such as level, pressure, temperature are usually very noisy. As a rst step, I generally only use a PI
controller, the integral part removes any offset, and the two parameter tuning space is sufciently
small, that one has a chance to nd reasonable values for them.
131
132 CHAPTER 4. THE PID CONTROLLER
4.2 The industrial PID algorithm
This section describes how to implement a simple continuous-time PID controller. We will start
with the classical textbook algorithm, although for practical and implementation reasons indus-
trially available PID controllers are never this simple for reasons which will soon become clear.
Further details on the subtlety of implementing a practical useful PID controller are described in
[53] and the texts [13, 15, 98].
The purpose of the PID controller is to measure a process error and calculate a manipulated ac-
tion u. Note that while u is referred to as an input to the process, it is the output of the controller.
The textbook non-interacting continuous PID controller follows the equation
u = K
c
_
+
1

i
_
dt +
d
d
dt
_
(4.1)
where the three tuning constants are the controller proportional gain, K
c
, the integral time,
i
and the derivative time,
d
, the latter two constants having units of time, often minutes for in-
dustrial controllers. Personally, I nd it more intuitive to use the reciprocal of the integral time,
1/
i
, which is called reset and has units of repeats per unit time. This nomenclature scheme has
the advantage that no integral action equates to zero reset, rather than the cumbersome innite
integral time. Just to confuse you further, for some industrial controllers to turn off the integral
component, rather than type in something like 99999, you just type in zero. It is rare in engineer-
ing where we get to approximate innity with zero! Table 4.1 summarises these alternatives.
Table 4.1: Alternative PID tuning parameter conventions
Parameter symbol units alternative symbol units
Gain K
c
input/output Proportional band PB %
integral time
i
seconds reset 1/
i
seconds
1
derivative time
d
seconds
The Laplace transform of the ideal PID controller given in Eqn. 4.1 is
U(s)
E(s)
= C(s) = K
c
_
1 +
1

i
s
+
d
s
_
(4.2)
and the equivalent block diagram in parallel form is
1
is

d
s

differentiator

+
`

integrator
K
c
error input
u
controller output
where is is clear that the three terms are computed in parallel which is why this form of the PID
controller is sometimes also known as the parallel PID form.
4.2. THE INDUSTRIAL PID ALGORITHM 133
We could rearrange Eqn. 4.2 in a more familiar numerator/denominator transfer function format,
C(s) =
K
c
_

d
s
2
+
i
s + 1
_

i
s
(4.3)
where we can clearly see that the ideal PID controller is not proper, that is, the order of the
numerator (2), is larger than the order of the denominator (1) and that we have a pole at s = 0.
We shall see in section 4.2.1 that when we come to fabricate these controllers we must physically
have a proper transfer function, and so we will need to modify the ideal PID transfer function
slightly.
4.2.1 Implementing the derivative component
The textbook PID algorithm of Eqn. 4.2 includes a pure derivative term
d
s. Such a term is
not physically realisable, and nor would we really want to implement it anyway, since abrupt
changes in setpoint would cause extreme values in the manipulated variable.
There are several approximations that are used in commercial controllers to address this problem.
Most schemes simply add a small factory-set lag termto the derivative term. So instead of simply

d
s, we would use
derivative term =

d
s

d
N
s + 1
(4.4)
where N is a large value, typically set to a large number somewhere between 10 and 100. Using
this derivative term modies the textbook PID transfer function of Eqn. 4.2 or Eqn. 4.3 to
C(s) = K
c
_
1 +
1

i
s
+

d
s

d
N
s + 1
_
(4.5)
= K
c
_
(
i

d
+
i

d
N) s
2
+ (
i
N +
d
)s +N

i
s (
d
s +N)
_
(4.6)
which is now physically realisable. Note that as N , the practical PID controller of Eqn. 4.6
converges to the textbook version of Eqn. 4.3. The derivative-ltered PID controller of Eqn. 4.6
collapses to a standard PI controller if
d
= 0.
We can fabricate in MATLAB the transfer function of this D-lteredPIDcontroller with the pidstd
command which MATLAB refers to as a PID controller in standard form.
Listing 4.1: Constructing a transfer function of a PID controller
>> C = pidstd(1,2,3,100) % Construct a standard form PID controller
Continuous-time PIDF controller in standard form:
3
% C(s) = Kp
_
1 +
1

i
s
+

d
s

d
N
s+1
_
with Kp = 1, Ti = 2, Td = 3, N = 100
The generated controller is of a special class known as a pidstd, but we can convert that to the
more familiar transfer function with the now overlayed tf command.
>> tf(C)
134 CHAPTER 4. THE PID CONTROLLER
Transfer function:
4 101 s2 + 33.83 s + 16.67
-------------------------
s2 + 33.33 s
A related MATLAB function, pid, constructs a slight modication of the above PID controller in
what MATLAB refers to as parallel form,
C
parallel
(s) = P +I/s +D
s

f
s + 1
where in this case as the derivative lter time constant,
f
, approaches zero, the derivative term
approaches the pure differentiator.
4.2.2 Variations of the PID algorithm
The textbook algorithm of the PID controller given in Eqn. 4.2 is sometimes known as the par-
allel or non-interacting form, however due to historical reasons there is another form of the PID
controller that is sometimes used. This is known as the series, cascade or interacting form
G

c
(s) = K

c
_
1 +
1

i
s
_
(1 +

d
s) (4.7)
where the three series PID controller tuning constants, K

c
,

i
and

d
are related to, but distinct
from, the original PIDtuning constants, K
c
,
i
and
d
. Ablock diagramof the series PIDcontroller
is given below.

differentiator

d
s
+

+
1

i
s
integrator

1 u
K

controller output

error input
A series PID controller in the form of Eqn. 4.7 can always be represented in parallel form
K
c
= K

i
+

i
,
i
=

i
+

d
,
d
=

i
+

d
(4.8)
but not necessarily the reverse
K

c
=
K
c
2
_
1 +
_
1 4
d
/
i
_
(4.9)

i
=

i
2
_
1 +
_
1 4
d
/
i
_
(4.10)

d
=

i
2
_
1
_
1 4
d
/
i
_
(4.11)
since a series form only exists if
i
> 4
d
. For this reason, the series form of the PID controller is
less commonly used, although some argue that it is easier to tune, [186]. Note that both controller
forms are the same if the derivative component is not used. A more detailed discussion on the
various industrial controllers and associated nomenclatures is given in [98, pp32-33].
4.3. SIMULATING A PID PROCESS IN SIMULINK 135
0 20 40 60 80 100 120 140 160 180 200
0.1
0.2
0.3
0.4
0.5
o
u
t
p
u
t
PI controlled response
0 20 40 60 80 100 120 140 160 180 200
0
0.2
0.4
0.6
0.8
i
n
p
u
t
time (sec) dt=0.08
(a) PI control of a apper with K = 1 and reset= 0.2
0 20 40 60 80 100 120 140 160 180 200
0.2
0
0.2
0.4
0.6
i
n
p
u
t
time (sec) dt=0.08
0 20 40 60 80 100 120 140 160 180 200
0
0.1
0.2
0.3
0.4
o
u
t
p
u
t
Integral only control
(b) Integral-only control of a apper.
Figure 4.1: Comparing PI and integral-only control for the real-time control of a noisy apper
plant with sampling time T = 0.08.
4.2.3 Integral only control
For some types of control, integral only action is desired. Fig. 4.1(a) shows the controlled response
of the laboratory apper, (1.4.1), controlled with a PI controller. The interesting characteristic of
this plants behaviour is the signicant disturbances. Such disturbances make it both difcult to
control and demand excessive manipulated variable action.
If however we drop the proportional term, and use only integral control we obtain much the same
response but with a far better behaved input signal as shown in Fig. 4.1(b). This will decrease the
wear on the actuator.
If you are using Eqn. 4.1 with the gain K
c
set to zero, then no control at all will result irrespective
of the integral time. For this reason, controllers either have four parameters as opposed to the
three in Eqn. 4.1, or we can follow the SIMULINK convention shown in Fig. 4.4.
4.3 Simulating a PID process in SIMULINK
SIMULINK is an ideal platform to rapidly simulate control problems. While it does not have the
complete exibility of raw MATLAB, this is more than compensated for in the ease of construction
and good visual feedback necessary for rapid prototyping. Fig. 4.2 shows a SIMULINK block
diagram for the continuous PID control of a third order plant.
output Step
Plant
3s +5s +6s+1.6
3 2
3
PID Controller
PID
Figure 4.2: A SIMULINK block diagram of a PID controller and a third-order plant.
136 CHAPTER 4. THE PID CONTROLLER
The PID controller block supplied as part of SIMULINK is slightly different from the classical de-
scription given in Eqn. 4.2. SIMULINKs continuous PIDblock uses the complete parallel skeleton,
G
c
(s) = P +
I
s
+ D
Ns

d
s +N
(4.12)
where we choose the three tuning constants, P, I and D, and optionally the lter coefcient N
which typically lies between 10 and 100. You can verify this by unmasking the PID controller (via
the options menu) block to exhibit the internals as shown in Fig. 4.3.
Figure 4.3: An unmasked view of a PID
controller block that comes supplied in
SIMULINK. Note how the conguration
differs from the classical form. See also
Fig. 4.4.
y
1
SumD
Sum
Proportional Gain
P
Integrator
1
s
Integral Gain
I
Filter Coefficient
N
Filter
1
s
Derivative Gain
D
u
1
Note how the derivative component of the SIMULINK PID controller in Eqn. 4.12 follows the
realisable approximation given in Eqn. 4.4 by using a feedback loop with an integrator and gain
of N = 100 as a default.
Block diagrams of both the SIMULINK implementation and the classical PID scheme are com-
pared in Fig. 4.4. Clearly the tuning constants for both schemes are related as follows:
P = K
c
, I =
K
c

i
, D = K
c

d
(4.13)
or alternatively
K
c
= P,
i
=
K
c
I
,
d
=
D
K
c
(4.14)
The SIMULINK scheme has the advantage of allowing integral-only control without modication.
I
s
Ds

+
`

u
1
is

d
s

Simulink PID controller block Classical controller block

+
`

K
c
P
Figure 4.4: Block diagram of PID controllers as implemented in SIMULINK (left) and classical text
books (right).
4.3. SIMULATING A PID PROCESS IN SIMULINK 137
If you would rather use the classical textbook style PID controller, then it is easy to modify the
SIMULINK PID controller block. Fig. 4.5 shows a SIMULINK implementation which includes the
lter on the derivative component following Eqn. 4.6. Since PID controllers are very common,
you may like to mask the controller as illustrated in Fig. 4.6, add a suitable graphic, and add this
to your SIMULINK library.
u
1
reset
1/taui
filtered deriv
s
taud/N.s+1
deriv
taud
Pgain
Kc
Integrator
1
s
Add4
error
1
Figure 4.5: A realisable con-
tinuous PID controller imple-
mented in SIMULINK with a
lter on the derivative action.
output Step
Plant
3s +5s +6s+1.6
3 2
3
PID Controller
Figure 4.6: A SIMULINK block diagram of a classical PID controller as a mask
Note that to have a reverse acting controller, we either require all three constants to be negative,
or just add a negative gain to the output of the controller.
Reasonable SIMULINK controller tuning
constants for this example are:
P = 2, I = 1.5, D = 2
or in classical form
K
c
= 2,
i
= 1.33,
d
= 1
which gives a step response as shown op-
posite.
0
0.5
1
1.5
y

&

r
e
f
0 2 4 6 8 10
0
2
4
u
time
Because the derivative term in the PID controller acts on the error rather than the output, we see
a large derivative kick in the controller output
1
. We can avoid this by using the PID block with
anti-windup, or by modifying the PID block itself. Section 4.4.1 shows how this modication
works.
1
Note that I have re-scaled the axis in the simulation results
138 CHAPTER 4. THE PID CONTROLLER
4.4 Extensions to the PID algorithm
Industrial PID controllers are in fact considerably more complicated than the textbook formula
of Eqn. 4.1 would lead you to believe. Industrial PID controllers have typically between 15 and
25 parameters. The following describes some of the extra functionality one needs in an effective
commercial PID controller.
4.4.1 Avoiding derivative kick
If we implement the classical PIDcontroller such as Eqn. 4.3 with signicant derivative action, the
input will show jump excessively every time either the output or the setpoint changes abruptly.
Under normal operations conditions, the output is unlikely to change rapidly, but during a set-
point change, the setpoint will naturally change abruptly, and this causes a large, though brief,
spike in the derivative of the error. This spike is fed to the derivative part of the PID controller,
and causes unpleasant transients in the manipulated variable. If left unmodied, this may cause
excessive wear in the actuator. Industrial controllers and derivative kick is further covered in
[179, p191].
It is clear that there is a problemwith the controller giving a large kick when the setpoint abruptly
changes. This is referred to as derivative kick and is due to the near innite derivative of the error
when the setpoint instantaneously changes as when in a setpoint change. One way to avoid
problems of this nature is to use the derivative of the measurement y, rather than the derivative
of the error e =

y

y. If we do this, the derivative kick is eliminated, and the input is much less
excited. Equations of both the classical and the anti-kick PID controller equations are compared
below.
Normal: G
c
(s) = K
c
_
+
1

i
_
t
0
d +
d
d
dt
_
(4.15)
Anti-Kick: G
c
(s) = K
c
_
+
1

i
_
t
0
d +
d
dy
dt
_
(4.16)
The anti-derivative kick controller is sometimes known as a PI-D controller with the dash indi-
cating that the PI part acts on the error, and the D part acts on the output.
In SIMULINK you can build a PID controller with anti-kick by modifying the standard PID con-
troller block as shown in Fig. 4.7.
Fig. 4.8 compares the controlled performance for the third order plant and tuning constants given
previously in Fig. 4.2 where the derivative term uses the error (lefthand simulation), with the
modication where the derivative term uses the measured variable (righthand simulation).
Evident from Fig 4.8 is that the PID controller using the measurement rather than the error be-
haves better, with much less controller action. Of course, the performance improvement is only
evident when the setpoint is normally stationary, rather than a trajectory following problem. Sta-
tionary setpoints are the norm for industrial applications, but if for example, we subjected the
closed loop to a sine wave setpoint, then the PID that employed the error in the derivative term
would perform better than the anti-kick version.
An electromagnetic balance arm
The electromagnetic balance arm described previously in 1.4.1 is extremely oscillatory as shown
in Fig. 1.5(b). The overshoot is about 75% which corresponds to a damping ratio of 0.1
4.4. EXTENSIONS TO THE PID ALGORITHM 139
reset
1/taui
input/output
gain
Kc
derivative filter
s
taud/N.s+1
deriv
taud
Sum1 Sum
Pulse
Generator
Plant
3
(s+4)(s+1)(s+0.4)
Integrator
1
s
Figure 4.7: PID controller with anti-derivative kick. See also Fig. 4.8.
0 10 20 30 40
0.5
0
0.5
1
1.5
Normal PID
o
u
t
p
u
t

&

s
e
t
p
o
i
n
t
0 10 20 30 40
40
20
0
20
40
i
n
p
u
t
time
0 10 20 30 40
0.5
0
0.5
1
1.5
No derivative Kick
0 10 20 30 40
40
20
0
20
40
time
Figure 4.8: PID control of a plant given in Fig. 4.7. The derivative kick is evident in the input
(lower trend of the left-hand simulation) of the standard PID controller. We can avoid this kick
by using the derivative of the output rather than the error as seen in the right-hand trend. Note
that the output controlled performance is similar in both cases
140 CHAPTER 4. THE PID CONTROLLER
assuming a proto-type second order process model.
To stabilise a system with poles so close to the imaginary axis requires substantial derivative
action. Without derivative action, the integral component needed to reduce the offset would
cause instability. Unfortunately however the derivative action causes problems with noise and
abrupt setpoint changes as shown in Fig. 4.9(a).
1000
1500
2000
2500
Derivative kick
F
l
a
p
p
e
r

a
n
g
l
e
0 10 20 30 40 50 60
0
1000
2000
3000
i
n
p
u
t
time [s]
(a) PID control exhibiting signicant derivative kick.
1400
1600
1800
2000
2200
No derivative kick
0 10 20 30 40 50
800
1000
1200
1400
1600
time [s]
(b) PID control with anti-kick.
Figure 4.9: Illustrating the improvement of anti-derivative kick schemes for PID controllers when
applied to the experimental electromagnetic balance.
The controller output, u(t) exhibits a kick every time the setpoint is changed. So instead of the
normal PID controller used in Fig. 4.9(a), an anti-kick version is tried in Fig. 4.9(b). Clearly there
are no spikes in the input signal when Eqn. 4.16 is used, and the controlled response is slightly
improved.
Abrupt setpoint changes are not the only thing that can trip up a PID controller. Fig. 4.10 shows
another response from the electromagnetic balance, this time with even more derivative action.
At low levels the balance arm is very oscillatory, although this behaviour tends to disappear at
the higher levels owing to the nonlinear friction effects.
4.4.2 Input saturation and integral windup
Invariably in practical cases the actual manipulated variable value, u, demanded by the PID
controller is impossible to implement owing to physical constraints on the system. A control
valve for example cannot shut less than 0% open or open more than 100%. Normally clamps
are placed on the manipulated variable to prevent unrealisable input demands occurring such as
u
min
< u < u
max
, or u = MIN(max u,MAX(min u,u))
or in other words, if the input u is larger than the maximum input allowed max_u, it will be
reset to that maximum input, and similarly the input is saturated if it is less than the minimum
allowable limit. In addition to an absolute limit on the position of u, the manipulated variable
can not instantaneously change from one value to another. This can be expressed as a limit on
the derivative of u, such as |
du
dt
| < c
d
.
4.4. EXTENSIONS TO THE PID ALGORITHM 141
1500
2000
2500
3000
3500
4000
S
e
t
p
o
i
n
t

&

o
u
t
p
u
t
0 5 10 15 20 25 30 35
0
1000
2000
3000
4000
5000
time [s]
i
n
p
u
t
Figure 4.10: Derivative
control and noise. Note
the difference in re-
sponse character once
the setpoint is increased
over 3000. This is
due to nonlinear fric-
tion effects.
However the PID control algorithm presented so far assumes that the manipulated variable is
unconstrained so when the manipulated variable does saturate, the integral error term continues
to grow without bound. When nally the plant catches up and the error is reduced, the integral
term is still large, and the controller must eat up this error. The result is an overly oscillatory
controlled response.
This is known as integral windup. Historically with the analogue controllers, integral windup
was not much of a problem since the pneumatic controllers had only a limited integral capacity.
However, this limit is effectively innite in a digital implementation.
There are a number of ways to prevent integral windup and these are discussed in [15, pp1014]
and more recently in [138, p60] and [31]. The easiest way is to check the manipulated variable
position, and ignore the integral term if the manipulated variable is saturated.
An alternative modication is to compute the difference between the desired manipulated vari-
able and the saturated version and to feed this value back to the integrator within the controller.
This is known as anti-windup tracking and is shown in Fig. 4.11(a). When the manipulated input is
not saturated, there is no change to normal PID algorithm. Note that in this modied PID cong-
uration we differentiate the measured value (not the error), we approximate the derivative term
as discussed in section 4.2.1, and we can turn off the anti-windup component with the manual
switch.
As an example (adapted from [19, Fig 8.9]), suppose we are to control an integrator plant, G(s) =
1/s, with tight limits on the manipulated variable, |u| < 0.1. Without anti-windup, the controller
output rapidly saturates, and the uncompensated response shown in Fig. 4.11(b) is very oscilla-
tory. However with anti-windup enabled, the controlled response is much improved.
142 CHAPTER 4. THE PID CONTROLLER
1
u
1/taui
reset
Kc
gain
taud.s+1
taud/N.s+1
approx Deriv
actuator model
Sum3
Sum2
Sum1
Manual Switch
Kc*taud
Kc*deriv
1/s
Integrator
0
Constant
2
y
1
error
(a) A PID controller with anti-windup.
3
2
1
0
1
2
3
o
u
t
p
u
t

&

s
e
t
p
o
i
n
t
Antiwindup demonstration
Antiwindup on Antiwindup off
0 100 200 300 400 500 600 700 800 900 1000
0.1
0.05
0
0.05
0.1
0.15
i
n
p
u
t
time
(b) Turning on the anti-windup controller at t = 660 dramatically improves the controlled response.
Figure 4.11: The advantages of using anti-windup are evident after t = 660.
4.5. DISCRETE PID CONTROLLERS 143
4.5 Discrete PID controllers
To implement a PID controller as given in Eqn. 4.1 on a computer, one must rst discretise or
approximate the continuous controller equation. If the error at time t = kT is
k
, then the contin-
uous expression
u(t) = K
c
_
e(t) +
1

i
_
e(t) dt +
d
de(t)
dt
_
(4.17)
can be approximated with
u
k
= K
c
_
_
_
_
_
_
_

k
+
T

i
k

j=0

j
. .
integral
+

d
T
(
k

k1
)
. .
differential
_
_
_
_
_
_
_
(4.18)
The integral in Eqn. 4.17 is approximated in Eqn. 4.18 by the rectangular rule and the derivative
is approximated as a rst order difference, although other discretisations are possible. Normally
the sample time, T, used by the controller is much faster than the dominant time constants of the
process so the approximation is satisfactory and the discrete PID controller is, to all intents and
purposes, indistinguishable from a continuous controller.
It is considerably more convenient to consider the discrete PIDcontroller as a rational polynomial
expression in z. Taking z-transforms of the discrete position form of the PID controller, Eqn. 4.18,
we get
U(z) = K
c
_
_
_
_
_
E(z) +
T

i
_
z
i+1
+z
i+2
+ +z
1
+ 1
_
. .
integral
E(z) +

d
T
(1 z
1
)E(z)
. .
differential
_
_
_
_
_
This shows that the transfer function of the PID controller is
G
PID
(z) = K
c
_
1 +
T

i
1
(1 z
1
)
+

d
T
(1 z
1
)
_
(4.19)
=
K
c
T
i
_
_
T
2
+
i
T +
d

i
_

i
(T 2
d
) z
1
+
i

d
z
2
1 z
1
_
(4.20)
Eqn. 4.19 is the discrete approximation to Eqn. 4.2 and the approximation is reasonable provided
the sample time, T, is sufciently short. A block diagram of this discrete approximation is
K
c
T
i
1
(1z
1
)

+

d
T
1 z
1
`

which we could further manipulate this using (block diagram algebra rules) to use only delay
elements to give
144 CHAPTER 4. THE PID CONTROLLER
K
c
T
i

d
T


`
`
+

+
z
1

z
1
There are other alternatives for a discrete PID controller depending on how we approximate the
integral part. For example we could use a backward difference,
u
kT
= u
(k1)T
. .
old integral
+Ty
(k1)T
. .
add on
G
i
(z) =
T
z 1
or a forward difference,
u
kT
= u
(k1)T
. .
old integral
+Ty
kT
. .
add on
G
i
(z) =
Tz
z 1
(which is not to be recommended due to stability problems), or the trapezoidal approximation.
u
kT
= u
(k1)T
. .
old integral
+T/2
_
y
kT
+y
(k1)T
_
. .
add on
G
i
(z) =
T(z + 1)
2(z 1)
We can insert any one of these alternatives to give the overall discrete z-domain PID controller,
although the trapeziodal scheme
G
PID
(z) = K
c
_
1 +
T(1 +z
1
)
2
i
(1 z
1
)
+

d
T
(1 z
1
)
_
(4.21)
=
K
c
2T
i
_
_
T
2
+ 2
i
T + 2
d

i
_
+
_
T
2
2
i
T 4
i

d
_
z
1
+ 2
i

d
z
2
1 z
1
_
(4.22)
is the most accurate and therefore the preferred implementation.
A SIMULINK discrete PID controller with sample time T using the trapeziodal approximation of
Eqn. 4.21 is given in Fig. 4.12. Note that now, as opposed to the continuous time implementation
of the PID controller, the derivative and integral gain values are now a function of sample time,
T. While continuous versions of PID controllers exist in SIMULINK, discrete versions simulate
much faster.
4.5.1 Discretising continuous PID controllers
The easiest way to generate a discrete PID controller is to simply call the MATLAB standard PID
pidstd with a trailing argument to indicate that you want a discrete controller. Since the default
4.5. DISCRETE PID CONTROLLERS 145
u
1
integral
T/taui/2
gain
Kc
derivative
taud/T
Sum1
Discrete Filter2
1z
1
1
Discrete Filter1
1+z
1
1z
1
error
1
Figure 4.12: A discrete PID controller in SIMULINK using a trapezoidal approximation for the
integral with sample time T following Eqn. 4.21. This controller block is used in the simulation
presented in Fig. 4.13.
discretisation strategy is using the forward Euler, it would be prudent to use explicitly state the
stable backward Euler option for both the integration and differentiation.
Listing 4.2: Constructing a discrete (ltered) PID controller
>> C = pidstd(1,2,3,100,0.1, ...
'IFormula','BackwardEuler','DFormula','BackwardEuler')
Discrete-time PIDF controller in standard form:
4
% C(s) = Kp
_
1 +
1

Tsz
z1
+
d
1

d
/N+
Tsz
z1
_
with Kp = 1, Ti = 2, Td = 3, N = 100, Ts = 0.1
9 >> tf(C)
Transfer function:
24.13 z2 - 47.4 z + 23.31
--------------------------
14 z2 - 1.231 z + 0.2308
Sampling time: 0.1
Velocity form of the PID controller
Eqn. 4.18 is called the position form implementation of the PID controller. An alternative form
is the velocity form which is obtained by subtracting the previous control input u
k1
from the
current input u
k
to get
u
k
= u
k
u
k1
= K
c
__
1 +
T

i
+

d
T
_

_
1 +
2
d
T
_

k1
+

d
T

k2
_
(4.23)
The velocity formin Eqn. 4.23 has three advantages over the position form: (see [191, pp636-637]),
namely it requires no need for initialisation, (the computer does not need to know the current u),
no integral windup problems, and the algorithm offers some protection against computer failure
in that if the computer crashes, the input remains at the previous, presumably reasonable, value.
146 CHAPTER 4. THE PID CONTROLLER
One drawback, however, is that it should not be used for P or PD controllers since the controller
is unable to maintain the reference value.
Fig. 4.13 shows a SIMULINK block diagram of a pressure control scheme on a headbox of a paper
machine. The problem was that the pressure sensor was very slow, only delivering a new pres-
sure reading every 5 seconds. The digital PID controller however was running with a frequency
of 1 Hz. The control engineer in this application faced with poor closed loop performance, was
concerned that the pressure sensor was too slow and therefore should be changed. In Fig. 4.13,
the plant is a continuous transfer function while the discrete PID controller runs with sample
period of T = 1 second, and the pressure sensor is modelled with a zeroth-order hold with T = 5
seconds. Consequently the simulation is a mixed continuous/discrete example, with more than
one discrete sample time.
pressure sensor
200s +30s+1
2
3.5
headbox
Signal
Generator
Scope
error ctrl output
Discrete PID
Figure 4.13: Headbox control with a slow pressure transducer. The discrete PID controller was
given in Fig. 4.12.
Fig. 4.14 shows the controlled results. Note how the pressure signal to the controller lags behind
the true pressure, but the controller still manages to control the plant.
4.5.2 Simulating a PID controlled response in Matlab
We can simulate a PID controlled plant in MATLAB by writing a small script le that calls a gen-
eral PID controller function. The PID controller is written in the discrete velocity form following
Eqn. 4.23 in the MATLAB function le pidctr.m shown in listing 4.3.
Listing 4.3: A simple PID controller
function [u,e] = pidctr(err,u,dt,e,pidt)
% [u,e] = pidctr(err,u,dt,e,pidt)
% PID controller
4 % err: = , current error, u = u(t), current manipulated variable
% dt = T sample time, e: row vector of past 3 errors
% pidt = [Kc, 1/I ,
d
] = tuning constants
k = pidt(1); rs = pidt(2); td2=pidt(3)/dt;
9 e = [err,e(1:2)]; % error shift register
du = k
*
[1+rs
*
dt+td2,-1-2
*
td2,td2]
*
e';
u = du + u; % Update control value unew = u
old
+ u
return
This simple PID controller function is a very naive implementation of a PID controller without
any of the necessary modications common in robust commercial industrial controllers as de-
scribed in section 4.4.
4.5. DISCRETE PID CONTROLLERS 147
0 50 100 150
4
2
0
2
4
u
time [s]
1.5
1
0.5
0
0.5
1
1.5
2
y

&

s
e
t
p
o
i
n
t


y
y sampled
setpoint
Figure 4.14: Headbox control with a slow pressure transducer measurement sample time of T = 5
while the control sample time is T = 1. Upper: The pressure setpoint (dotted), the actual pressure
and the sampled-and-held pressure fed back to the PID controller. Lower: The controller output.
The plant to be controlled for this simulation is
G
p
(q
1
) = q
d
1.2q
1
1 0.25q
1
0.5q
2
(4.24)
where the sample time is T = 2 seconds and the dead time is d = 3 sample time units, and the
setpoint is a long period square wave. For this simulation, we will try out the PID controller with
tuning constants of K
c
= 0.3, 1/
i
= 0.2 and
d
= 0.1. How I arrived at these tuning constants is
discussed later in 4.6.
The MATLAB simulation using the PID function from Listing 4.3 is given by the following script
le:
a=[0.25,0.5];b=1.2;theta=[a b]'; dead = 3; % Plant G(q), Eqn. 4.24.
3 dt = 2.0; t = dt
*
[0:300]'; yspt = square(t/40); % time vector & setpoint
y = zeros(size(yspt));u=zeros(size(y)); % initialise y(t) & u(t)
pid = [0.3, 0.2, 0.1]; % PID tuning constants: Kc = 0.3, 1/I = 0.2,
d
= 0.1
e = zeros(1,3); % initialise error integral
8 for i=3+dead:length(y)
X = [y(i-1), y(i-2), u(i-1-dead)]; % collect i/o
y(i) = X
*
theta; % system prediction
err = yspt(i) - y(i); % current error
[u(i),e] = pidctr(err,u(i-1),dt,e,pid); % PID controller from Listing 4.3.
13 end % for
plot(t,yspt,'--',t,[y,u]) % Plot results in Fig. 4.15.
148 CHAPTER 4. THE PID CONTROLLER
Figure 4.15 shows the controlled response of this simulation. Note how I have plotted the input
(lower plot of Fig. 4.15) as a series of horizontal lines that show that the input is actually a
piecewise zeroth-order hold for this discrete case using the stairs function.
Figure 4.15: The output (up-
per solid), setpoint (upper
dashed) and discretised input
(lower) of a PID controlled
process.
2
1
0
1
2
PID control
y

&

s
e
t
p
o
i
n
t
0 50 100 150 200
1
0.5
0
0.5
1
Time
I
n
p
u
t
4.5.3 Controller performance as a function of sample time
Given that the discrete PID controller is an approximation to the continuous controller, we must
expect a deterioration in performance with increasing sample time. Our motivation to use coarse
sampling times is to reduce the computational load. Fig. 4.16 compares the controlled response
of the continuous plant,
G
p
(s) =
s + 3
(s + 4)(
2
s
2
+ 2s + 1)
with = 4, = 0.4 given the same continuous controller settings at different sampling rates.
Note that the reset and derivative controller settings for the discrete controller are functions of
time, and must be adjusted accordingly. Fig. 4.16 shows that the controller performance improves
as the sampling time is decreased and converges to the continuous case. However if the sampling
time is too small, the discrete PID controller is then suspectable to numerical problems.
4.6 PID tuning methods
Tuning PID controllers is generally considered an art and is an active research topic both in
academia and in industry. Typical chemical processing plants have hundreds or perhaps thou-
sands of control loops of which the majority of these loops are non-critical and are of the PID
type and all these loops require tuning.

Arzen [8] asserts that it is a well known fact that many
4.6. PID TUNING METHODS 149
0
0.5
1
1.5
T
s
= 4
y
0 20 40
0
0.5
1
1.5
2
2.5
u
T
s
= 2
0 20 40
T
s
= 1
0 20 40
T
s
=0.1
0 20 40
continuous
discrete
Figure 4.16: The effect of varying sampling time, T, when using a discrete PID controller com-
pared to a continuous PID controller. As T 0, the discrete PID controller converges to the
continuous PID controller.
control loops in (the) process industry are badly tuned, or run in manual mode. Supporting this
claim, here is a summary of the rather surprising results that Ender, [64], found after investigating
thousands of control loops over hundreds of plants
2
;
More than 30% of the controllers are operating in manual.
More than 60% of all installed loops produce less variance in manual than automatic.
The average loop costs $40,000 to design, instrument and install.
Note however that it is not only industry that seems unable to tune PID controllers since many
publications in the academic world also give mis-tuned PID controllers. This is most common
when comparing the PID with some other sort of more sophisticated (and therefore hopefully
better performing), controller. So it appears that it would be worthwhile to look more closely at
the tuning of PID regulators.
There are two possibilities that we face when tuning PID controllers. One is that we have a model
of the plant to be controlled, perhaps as a transfer function, so then we need to establish a suitable
PID controller such that when combined with the plant, we obtain an acceptable response. The
second case is where we dont even have a model of the plant to be controlled, so our task is also
to identify (implicitly or explicitly) this plant model as well.
Tuning PID controllers can be performed in the time domain or in the frequency domain with the
controller either operating (closed loop), or disconnected (open loop), and the tuning parameter
calculations can be performed either online or ofine. The online tuning technique is the central
component of automated self tuners, discussed more in chapter 7. Section 4.6.1 considers the two
classical time domain tuning methods, one closed loop, the other open loop.
2
mainly in the US
150 CHAPTER 4. THE PID CONTROLLER
4.6.1 Open loop tuning methods
Open loop tuning methods are where the feedback controller is disconnected and the experi-
menter excites the plant and measures the response. They key point here is that since the con-
troller is now disconnected the plant is clearly now no longer strictly under control. If the loop
is critical, then this test could be hazardous. Indeed if the process is open-loop unstable, then
you will be in trouble before you begin. Notwithstanding for many process control applications,
open loop type experiments are usually quick to perform, and deliver informative results.
To obtain any information about a dynamic process, one must excite it in some manner. If the
system is steady at setpoint, and remains so, then you have no information about howthe process
behaves. (However you do have good control so why not quit while you are ahead?) The type
of excitation is again a matter of choice. For the time domain analysis, there are two common
types of excitation signal; the step change, and the impulse test, and for more sophisticated
analysis, one can try a random input test. Each of the three basic alternatives has advantages and
disadvantages associated with them, and the choice is a matter for the practitioner.
Step change The step change method is where the experimenter abruptly changes the input to
the process. For example, if you wanted to tune a level control of a buffer tank, you could
sharply increase (or decrease) the ow into the tank. The controlled variable then slowly
rises (or falls) to the new operating level. When I want a quick feel for a new process, I
like to perform a step test and this quickly gives me a graphical indication of the degree of
damping, overshoot, rise time and time constants better than any other technique.
Impulse test The impulse test method is where the input signal is abruptly changed to a new
value, then immediately equally abruptly changed back to the old value. Essentially you
are trying to physically alter the input such that it approximates a Dirac delta function.
Technically both types of inputs are impossible to perform perfectly, although the step test
is probably easier to approximate experimentally.
The impulse test has some advantages over the step test. First, since the input after the ex-
periment is the same as before the experiment, the process should return to the same pro-
cess value. This means that the time spent producing off-specication (off-spec) product
is minimised. If the process does not return to the same operating point, then this indi-
cates that the process probably contains an integrator. Secondly the impulse test (if done
perfectly) contains a wider range of excitation frequencies than the step test. An excitation
signal with a wide frequency range gives more information about the process. However
the impulse test requires slightly more complicated analysis.
Random input The randominput technique assumes that the input is a randomvariable approx-
imating white noise. Pure white noise has a wide (theoretically innite) frequency range,
and can therefore excite the process over a similarly wide frequency range. The step test,
even a perfect step test, has a limited frequency range. The subsequent analysis of this type
of data is now much more tedious, though not really any more difcult, but it does require
a data logger (rather than just a chart recorder) and a computer with simple regression
software. Building up on this type of process identication where the input is assumed,
within reason, arbitrary, are methods referred to as Time Series Analysis (TSA), or spectral
analysis; both of which are dealt with in more detail in chapter 6.
Open-loop or process reaction curve tuning methods
There are various tuning strategies based on an open-loop step response. While they all follow
the same basic idea, they differ in slightly in how they extract the model parameters from the
4.6. PID TUNING METHODS 151
Plant

output input
`

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
K
T

L
time
tangent at inection pt
Figure 4.17: The parameters T and L to be graphically estimated for the openloop tuning method
relations given in Table 4.2.
recorded response, and also differ slightly as to relate appropriate tuning constants to the model
parameters. This section describes three alternatives, the classic Ziegler-Nichols open loop test,
the Cohen-Coon test, and the

Astr om-H agglund suggestion.
The classic way of open loop time domain tuning was rst published in the early 40s by Ziegler
and Nichols
3
, and is further described in [150, pp596597] and in [179, chap 13]. Their scheme re-
quires you to apply a unit step to the open-loop process and record the output. From the response,
you graphically estimate the two parameters T and L as shown in Fig. 4.17. Naturally if your
response is not sigmoidal or S shaped such as that sketched in Fig. 4.17 and exhibits overshoot,
or an integrator, then this tuning method is not applicable.
This method implicitly assumes the plant can be adequately approximated by a rst order trans-
fer function with time delay,
G
p

Ke
s
s + 1
(4.25)
where L is approximately the dead time , and T is the open loop process time constant . Once
you have recorded the openloop input/output data, and subsequently measured the times T and
L, the PID tuning parameters can be obtained directly from Table 4.2.
A similar open loop step tuning strategy due to Cohen and Coon published in the early 1950s is
where you record the time taken to reach 50% of the nal output value, t
2
, and the time taken to
reach 63% of the nal value, t
3
. You then calculate the effective deadtime with
=
t
2
ln(2)t
3
1 ln(2)
and time constant,
= t
3
t
1
The open loop gain can be calculated by dividing the nal change in output over the change in
the input step.
3
Ziegler & Nichols actually published two methods, one open loop, and one closed loop, [204]. However it is only the
second closed loop method that is generally remembered today as the ZieglerNichols tuning method.
152 CHAPTER 4. THE PID CONTROLLER
Once again, now that you have a model of the plant to be controlled in the form of Eqn. 4.25,
you can use one the alternative heuristics given in Table 4.2. The recommended range of values
for the deadtime ratio for the Cohen-Coon values is 0.1 < / < 1. Also listed in Table 4.2 are
the empirical suggestions from [16] known as AMIGO, or approximate M-constrained integral
gain optimisation. These values have the same form as the Cohen-Coon suggestions but perform
slightly better.
Table 4.2: The PID tuning parameters as a function of the openloop model parameters K, and
from Eqn. 4.25 as derived by Ziegler-Nichols (open loop method), Cohen and Coon, or alterna-
tively the AMIGO rules from [16].
Controller K
c

i

d
Ziegler-Nichols
(Open loop)
P

K

PI
0.9
K

0.3

PID
1.2
K
2 0.5
Cohen-Coon
P
1
K

_
1 +

3
_

PI
1
K

_
0.9 +

12
_

30 + 3/
9 + 20/

PID
1
K

_
4
3
+

4
_

32 + 6/
13 + 8/

4
11 + 2/
AMIGO PID
1
K
_
0.2 + 0.45

_
0.4 + 0.8
+ 0.1

0.5
0.3 +
Fig. 4.18 illustrates the approximate rst-order plus deadtime model tted to a higher-order over-
damped process using the two points at 50% and 63%. The subsequent controlled response using
the values derived from in Table 4.2 is given in Fig. 4.19.
Figure 4.18: Fitting a rst-order model with
deadtime using the Cohen-Coon scheme.
Note how the tted model is a reason-
able approximation to the actual response
just using the two data points and gain.
See Fig. 4.19 for the subsequent controlled
response.
0 5 10 15 20 25 30 35
0
0.5
1
1.5
2
t
2
t
3
time
y
actual
fitted model
Conventional thought now considers that both the Zeigler-Nichols scheme in Table 4.2 and the
Cohen-Coon scheme gives controller constants that are too oscillatory and hence other modied
tuning parameters exist, [178, p329]. Problem 4.1 demonstrates this tuning method.
4.6. PID TUNING METHODS 153
2
0
2
Ponly
y

&

s
e
t
p
o
i
n
t
0 100 200
5
0
5
u
time
2
0
2
PIcontrol
0 100 200
5
0
5
time
0 100 200
5
0
5
time
2
0
2
PID control
Figure 4.19: The closed loop response for a P, PI and PID controlled system using the Cohen-Coon
strategy from Fig. 4.18.
Problem 4.1 Suppose you have a process that can be described by the transfer function
G
p
=
K
(3s + 1)(6s + 1)(0.2s + 1)
Evaluate the time domain response to a unit step change in input and graphically estimate the
parameters L and T. Design a PI and PID controller for this process using Table 4.2.
Controller settings based on the open loop model
If we have gone to all the trouble of estimating a model of the process, then we could in principle
use this model for controller design in a more formal method than just rely on the suggestions
given in Table 4.2. This is the thinking behind the Internal Model Control or IMC controller
design strategy. The IMC controller is a very general controller, but if we restrict our attention to
just controllers of the PID form, we can derive simple relations between the model parameters
and appropriate controller settings.
The nice feature of the IMC strategy is that it provides the scope to adjust the tuning with a single
parameter, the desired closed loop time constant,
c
, something that is missing fromthe strategies
given previously in Table 4.2. A suitable starting guess for the desired closed loop time constant
is to set it equal to the dominant open loop time constant.
Table 4.3 gives the PID controller settings based on various common process models. For a more
complete table containing a larger selection of transfer functions, consult [179, p308].
An simplication of the this IMC idea in an effort to make the tuning as effortless as possible is
given in [186].
Perhaps the easiest way to tune a plant when the transfer function is known is to use the MATLAB
function pidtune, or the GUI, pidtool as shown in Fig. 4.20.
154 CHAPTER 4. THE PID CONTROLLER
Table 4.3: PID controller settings based on IMC for a small selection of common plants where the
control engineer gets to chose a desired closed loop time constant,
c
.
Plant PID constants
K
c
K
i

d
K/(s + 1)

c

K
(
1
s + 1)(
2
s + 1)

1
+
2

1
+
2

K/s
2

c
2
c

K
s(s + 1)
2
c
+

2
c
2
c
+
2
c

2
c
+
Ke
s
s + 1

c
+

+/2

c
+/2
+/2

2 +
Figure 4.20: PID tuning of an arbitrary transfer function using the MATLAB GUI.
4.6. PID TUNING METHODS 155
4.6.2 Closed loop tuning methods
The main disadvantage of the open loop tuning methods is that it is performed with the controller
switched to manual, i.e. leaving the output uncontrolled in open loop. This is often unreason-
able for systems that are openloop unstable, and impractical for plants where there is a large
invested interest, and the operating engineers are nervous. The Ziegler-Nichols continuous cy-
cling method described next is a well-known closed loop tuning strategy used to address this
problem, although a more recent single response strategy given later in 4.6.3 is faster, safer, and
easier to use.
Ziegler-Nichols continuous cycling method
The Ziegler-Nichols continuous cycling method is one of the best known closed loop tuning
strategies. The controller is left on automatic, but the reset and derivative components are turned
off. The controller gain is then gradually increased (or decreased) until the process output contin-
uously cycles after a small step change or disturbance. At this point, the controller gain you have
selected is the ultimate gain, K
u
, and the observed period of oscillation is the ultimate period,
P
u
.
Ziegler and Nichols originally suggested in 1942 PID tuning constants as a function of the ulti-
mate gain and ultimate period as shown in the rst three rows of Table 4.4. While these values
give near-optimum responses fort load changes, practical experience and theoretical consider-
ations (i.e. [15, 29]) have shown that these tuning values tend to give responses that are too
oscillatory for step-point changes due to the small phase margin. For this reason, various people
have subsequently modied the heuristics slightly as listed in the remaining rows of Table 4.4
which is expanded from that given in [178, p318].
Table 4.4: Various alternative Ziegler-Nichols type PID tuning rules as a function of the ultimate
gain, K
u
, and ultimate period, P
u
.
Response type PID constants
K
c

i

d
Ziegler-Nichols
P 0.5K
u

PI 0.45K
u
P
u
/1.2
PID 0.6K
u
P
u
/2 P
u
/8
Modied ZN
No overshoot 0.2K
u
P
u
/2 P
u
/2
Some overshoot 0.33K
u
P
u
/2 P
u
/3
Tyreus-Luyben
PI 0.31K
u
2.2P
u

PID 0.45K
u
2.2P
u
P
u
/6.3
Chien-Hrones-Reswick PI 0.47K
u
1

Astr om-H agglund PI 0.32K


u
0.94
Specied phase-margin,
m
PID K
u
cos(
m
) f
d
Eqn. 4.56
Experience has shown that the Chien-Hrones-Reswick values give an improved response on the
original Ziegler-Nichols, but the

Astr om-H agglund tend, like the ZN, to be overly oscillatory.
While the Tyreus-Luyben values deliver very sluggish responses, they exhibit very little over-
shoot and are favoured by process engineers for that reason.
Algorithm 4.1 summarises the ZN ultimate oscillation tuning procedure.
156 CHAPTER 4. THE PID CONTROLLER
Algorithm 4.1 Ziegler-Nichols closed loop PID tuning
To tune a PID controller using the closed-loop Ziegler-Nichols method, do the following:
1. Connect a proportional controller to the plant to be controlled. I.e. turn the controller on
automatic, but turn off the derivative and integral action. (If your controller uses integral
time, you will need to set
i
to the maximum allowable value.)
2. Choose a trial sensible controller gain, K
c
to start.
3. Disturb the process slightly and record the output.
4. If the response is unstable, decrease K
c
and go back to step 3, otherwise increase K
c
and
repeat step 3 until the output response is a steady sinusoidal oscillation. Once a gain K
c
has been found to give a stable oscillation proceed to step 5.
5. Record the current gain, and measure the period of oscillation in time units (say seconds).
These are the ultimate gain, K
u
and corresponding ultimate period, P
u
.
6. Use Table 4.4 to establish the P, PI, or PID tuning constants.
7. Test the closed loop response with the new PID values. If the response is not satisfactory,
further manual ne-tuning may be necessary.
This method has proved so popular, that automatic tuning procedures have been developed that
are based around this theory as detailed in chapter 7. Despite the fact that this closed loop test
is difcult to apply experimentally, gives only marginal tuning results in many cases, it is widely
used and very well known. Much of the academic control literature uses the Z-N tuning method
as a basis on which to compare more sophisticated schemes but often conveniently forgetting in
the process that the Z-N scheme was really developed for load disturbances as opposed to set-
point changes. Finally many practicing instrument engineers (who are the ones actually tuning
the plant) know only one formal tuning method this one.
Consequently it is interesting to read the following quote from a review of a textbook in Process
control:
4
. . . The inclusion of tuning methods based on the control loop cycling (Ziegler-Nichols
method) without a severe health warning to the user reveals a lack of control room experience on
behalf of the author.
Ziegler-Nichols continuous cycling example
Finding the ultimate gain and frequency in practice requires a tedious trial-and-error approach.
If however, we already have the model of the process, say in the form of a transfer function, then
establishing the critical frequency analytically is much easier, although we may still need to solve
a nonlinear algebraic equation.
Suppose we have identied a model of our plant as
G(s) =
1
6s
2
+ 7s + 1
e
3s
(4.26)
4
Review of A Real-Time Approach to Process Control by Svrcek, Mahoney & Young, reviewed by Patrick Thorpe in The
Chemical Engineer, January 2002, p30.
4.6. PID TUNING METHODS 157
and we want to control this plant using a PID controller. To use Ziegler-Nichols settings we need
to establish the ultimate frequency,
u
, where the angle of G(s = i
u
) = radians, or solve the
nonlinear expression
G(iu)
= (4.27)
for
u
. In the specic case given in Eqn. 4.26, we have
e
3iu

16
2
u
+7iu =
3
u
tan
1
_
7
u
1 6
2
u
_
= (4.28)
which is a non-trivial function of ultimate frequency,
u
. However it is easy to graph this relation
as a function of
u
and look for zero crossing such as shown in Fig. 4.21, or use a numerical
technique such as Newton-Rhapson to establish that
u
0.4839 rad/s implying an ultimate
period of P
u
= 2/
u
= 12.98 seconds per cycle.
0 0.2 0.4 0.6 0.8 1
2
1
0
1
2
3

3 watan2(7 w,16 w
2
)+
f
(

)
Figure 4.21: Solving F() = 0 for the
ultimate frequency. In this case the ul-
timate frequency is
u
0.48 rad/s.
A quick way to numerically solve Eqn. 4.28 is to rst dene an anonymous function and then to
use fzero to nd the root.
1 >> F = @(w) -3
*
w - atan2(7
*
w,1-6
*
w.2)+pi; % F() = 3 tan
1
_
7
16
2
_
+
>> ezplot(F,[0 1]) % See Fig. 4.21.
>> wu = fzero(F,0.1) % Solve F() = 0 for
wu =
0.4839
Once we have found the critical frequency,
u
, we can establish the magnitude at this frequency
by substituting s = i
u
into the process transfer function, Eqn. 4.26,
|G(i
u
)| = |G(0.48i)| 0.2931
which gives a critical gain, K
u
= 1/0.2931 = 3.412. An easy way to do this calculation in MATLAB
is to simply use bode at a single frequency, as in
>> [M,ph] = bode(G,wu) % Compute G(s = ju), should obtain = 180

, and Ku.
M =
0.2931
ph =
10 -180.0000
Now that we have both the ultimate gain and frequency we can use the classic Zielger-Nichols
rules in Table 4.4 to obtain our tuning constants and simulate the controlled process as shown in
Fig. 4.22.
158 CHAPTER 4. THE PID CONTROLLER
0.2
0
0.2
0.4
0.6
0.8
1
1.2
1.4
o
u
t
p
u
t

&

s
e
t
p
o
i
n
t
P control
0 50 100 150 200
0
1
2
i
n
p
u
t
time
0.2
0
0.2
0.4
0.6
0.8
1
1.2
1.4
PI control
0 50 100 150 200
0
1
2
time
0.2
0
0.2
0.4
0.6
0.8
1
1.2
1.4
PID control
0 50 100 150 200
0
1
2
time
Figure 4.22: The step and load responses of a P (left) and PI (middle) and PID (right) controlled
process using the closed loop Ziegler-Nichols suggestions from Table 4.4.
The tuned response to both a setpoint change and a load disturbance at t = 100 of all three
candidates shown in Fig. 4.22 is reasonable, but as expected the P response exhibits offset, and
the PI is sluggish. We would expect a good response from the PID controller because the actual
plant model structure (second order plus deadtime), is similar to the assumed model structure
by Ziegler and Nichols, which is rst order plus deadtime. However while it could be argued
that the step response is still too oscillatory, the response to the load disturbance is not too bad.
In the very common case of a rst order plus deadtime structure, Eqn. 4.25, we can nd the
ultimate frequency by solving the nonlinear equation

u
tan
1
(
u
) + = 0 (4.29)
for
u
, and then calculate the ultimate gain from a direct substitution
K
u
=
1
|G(i
u
)|
=

1 +
2

2
K
(4.30)
The tedious part of the above procedure is generating the nonlinear equation in
u
for the spe-
cic plant structure of interest. We can however automate this equation generation for standard
polynomial transfer functions with deadtime as shown in the listing below.
[num,den] = tfdata(G,'v') % Or use: cell2mat(G.num)
iodelay = G.iodelay;
% Construct the equation
G(i)
= and solve for
15 F = @(w) angle(polyval(num,1i
*
w))-iodelay
*
w-angle(polyval(den,1i
*
w))+pi;
wc = fzero(F,0) % Now solve for c
Rather than solve for the critical frequency algebraically, we could alternatively rely on the MAT-
LAB margin routine which tries to extract the gain and phase margins and associated frequencies
for arbitrary transfer functions. Listing 4.4 shows how we can tune a PID controller for an arbi-
trary transfer function, although note that because this strategy attempts to solve a nonlinear
4.6. PID TUNING METHODS 159
expression for the critival frequency using a numerical iterative scheme, this routine is not infal-
lible.
Listing 4.4: Ziegler-Nichols PID tuning rules for an arbitrary transfer function
G = tf(1,conv([6 1],[1 1]),'iodelay',5); % Plant of interest G =
1
(6s+1)(s+1)
e
5s
[Gm,Pm,Wcg,Wcp] = margin(G); % Establish critical points
20 Ku = Gm; Pu = 2
*
pi/Wcg; % Critical gain, Ku & period, Pu
Kc = 0.6
*
Ku; taui = Pu/2; taud = Pu/8; % PID tuning rules (Ziegler-Nichols)
Gc = tf(Kc
*
[taui
*
taud taui 1],[taui 0]); % PID controller Kc(i
d
s
2
+is + 1)/(is)
Note that while the use of the ultimate oscillation Ziegler-Nichols tuning strategy is generally dis-
couraged by practicitioners, it is the oscillation at near instability which is the chief concern, not
the general idea of relating the tuning constants to the ultimate gain and frequency. If for exam-
ple, we already have a plant model in the form of a transfer function perhaps derived from rst
principles, or system identication techniques, then we can by-pass the potentially hazardous
oscillation step, and compute directly the tuning constants as a function of ultimate gain and
frequency.
4.6.3 Closed loop single-test tuning methods
Despite the fact that Ziegler-Nichols continuous cycling tuning method is performed in closed
loop, the experiment is both tedious and dangerous. The Yuwana-Seborg tuning method de-
scribed here, [203], retains the advantages of the ZN tuning method, but avoids many of the the
disadvantages. Given the attractions of this closed-loop reaction curve tuning methodology, there
have been subsequently many extensions proposed, some of which are summarised in [48, 99].
The following development is based on the modications of [47] with the corrections noted by
[193].
The Yuwana-Seborg (YS) tuning technique is based on the assumption that the plant transfer
function, while unknown, can be approximated by the rst order plus deadtime structure,
G
m
(s) =
K
m
e
ms

m
s + 1
(4.31)
with three plant parameters, process gain K
m
, time constant,
m
, and deadtime
m
.
Surrounding this process with a trial, but known, proportional-only controller K
c
, gives a closed
loop transfer function between reference r(t) and output y(t) as
Y (s)
R(s)
=
K
c
K
m
e
ms
1 +s +K
c
K
m
e
ms
(4.32)
A Pad e approximation can be used to expand the non-polynomial term in the denominator, al-
though various people have subsequently modied this aspect of the method such as using a
different deadtime polynomial approximation. Using some approximation for the deadtime, we
can approximate the closed loop response in Eqn. 4.32 with
G
cl

Ke
s

2
s
2
+ 2s + 1
(4.33)
and we can extract the model parameters in Eqn. 4.33 from a single closed loop control step test.
160 CHAPTER 4. THE PID CONTROLLER

`
time
setpoint
`

Setpoint
change
r
0
r
1

offset
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

period, P
`

y
p2
y
p1
y
m
peak #1
peak #2
typical output
.........
`
y
ss
Figure 4.23: Typical response of a stable system to a P-controller.
Suppose we have a trial proportional-only feedback controlled response with a known controller
gain K
c
. It does not really matter what this gain is so long as the response oscillates sufciently
as shown in Fig. 4.23.
If we step change the reference variable setpoint from r
0
to r
1
, we are likely to see an under-
damped response such as shown in Fig. 4.23. Fromthis response we measure the initial output y
0
,
the rst peak y
p1
, the rst trough, y
m1
and the second peak y
p2
, and associated times. Under these
conditions we expect to see some offset given the proportional-only controlled loop, and that the
controller gain should be sufciently high such that the response exhibits some underdamped
(oscillatory) behaviour.
The nal value of the output, y

, is approximately
y

=
y
p2
y
p1
y
2
m
y
p1
+y
p2
2y
m
(4.34)
or alternatively, if the experimental test is of sufcient duration, y

could simply be just the last


value of y collected.
The closed loop gain K is given by
K =
y

r
1
r
0
(4.35)
and the overshoot is given by
H =
1
3
_
y
p1
y

+
y

y
m
y
p1
y

+
y
p2
y

y
m
_
, (4.36)
The deadtime is
= 2t
p1
t
m
, (4.37)
the shape factor
=
ln(H)
_

2
+ ln
2
(H)
, (4.38)
4.6. PID TUNING METHODS 161
and the time constant
=
(t
m
t
p1
)
_
1
2

. (4.39)
Nowthat we have tted a closed loop model, we can compute the ultimate gain, K
u
, and ultimate
frequency,
u
, by solving the nonlinear expression

u
tan
1
_
2
u
1
2

2
u
_
= (4.40)
for
u
, perhaps using an iterative scheme starting with
u
= 0. It follows then that the ultimate
gain is
K
u
= K
c
_
1 +
1
|G
cl
(i
u
)|
_
(4.41)
where
|G
cl
(i
u
)| =
K
_
(1
2

2
u
)
2
+ (2
u
)
2
(4.42)
Alternatively of course we could try to use margin to extract K
u
and
u
.
At this point, given K
u
and
u
, we can tune PID controllers using the ZN scheme directly fol-
lowing Table 4.4.
Alternatively we can derive the parameters for the assumed open loop plant model, Eqn. 4.31, as
K
m
=
|y

y
0
|
K
c
(|r
1
r
0
| |y

y
0
|)
(4.43)

m
=
1

u
_
K
2
u
K
2
m
1 (4.44)

m
=
1

u
_
tan
1
(
m

u
)

(4.45)
and then subsequently we can tune it either using the ZN strategy given in Listing 4.4, or use
the internal model controller strategy from Table 4.3, or perhaps using ITAE optimal tuning con-
stants. The optimal ITAE tuning parameters for P, PI and PID controllers are derived from
K
c
=
A
K
m
_

m
_
B
,
1

i
=
1
C
m
_

m
_
D
,
d
= E
m
_

m
_
F
(4.46)
where the constants A, B, C, D, E, F are given in Table 4.5 for P, PI and PID controllers. We are
now in a position to replace our trial K
c
with the hopefully better controller tuning constants.