Advanced Control using MATLAB

April 30, 2017 | Author: Stuff84 | Category: N/A
Share Embed Donate


Short Description

Descripción: Stabilising the unstabilisable by Prof. David L. Wilson of Auckland University of Technology....

Description

Advanced Control using M ATLAB

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

2

Introduction 1.1 Scope . . . . . . . . . . . . . . . . . . . . . . . 1.2 Matlab for computer aided control design . . 1.2.1 Alternative computer design aids . . 1.3 Economics of control . . . . . . . . . . . . . . 1.4 Laboratory equipment for control tests . . . . 1.4.1 Plants with one input and one output 1.4.2 Multi-input and multi-output plants . 1.5 Slowing down Simulink . . . . . . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

1 2 2 3 4 6 6 8 10

From differential to difference equations 2.1 Computer in the loop . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.1 Sampling an analogue signal . . . . . . . . . . . . . . . . . 2.1.2 Selecting a sample rate . . . . . . . . . . . . . . . . . . . . . 2.1.3 The sampling theorem and aliases . . . . . . . . . . . . . . 2.1.4 Discrete frequency . . . . . . . . . . . . . . . . . . . . . . . 2.2 Finite difference models . . . . . . . . . . . . . . . . . . . . . . . . 2.2.1 Difference equations . . . . . . . . . . . . . . . . . . . . . . 2.3 The z transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.1 z-transforms of common functions . . . . . . . . . . . . . . 2.4 Inversion of z-transforms . . . . . . . . . . . . . . . . . . . . . . . 2.4.1 Inverting z-transforms with symbolically . . . . . . . . . . 2.4.2 The partial fraction method . . . . . . . . . . . . . . . . . . 2.4.3 Long division . . . . . . . . . . . . . . . . . . . . . . . . . . 2.4.4 Computational approach . . . . . . . . . . . . . . . . . . . 2.4.5 Numerically inverting the Laplace transform . . . . . . . . 2.5 Discretising with a sample and hold . . . . . . . . . . . . . . . . . 2.5.1 Converting Laplace transforms to z-transforms . . . . . . 2.5.2 The bilinear transform . . . . . . . . . . . . . . . . . . . . . 2.6 Discrete root locus diagrams . . . . . . . . . . . . . . . . . . . . . . 2.7 Multivariable control and state space analysis . . . . . . . . . . . . 2.7.1 States and state space . . . . . . . . . . . . . . . . . . . . . 2.7.2 Converting differential equations to state-space form . . . 2.7.3 Interconverting between state space and transfer functions 2.7.4 Similarity transformations . . . . . . . . . . . . . . . . . . . 2.7.5 Interconverting between transfer functions forms . . . . . 2.7.6 The steady state . . . . . . . . . . . . . . . . . . . . . . . . . 2.8 Solving the vector differential equation . . . . . . . . . . . . . . . 2.8.1 Numerically computing the discrete transformation . . . . 2.8.2 Using M ATLAB to discretise systems . . . . . . . . . . . . . 2.8.3 Time delay in state space . . . . . . . . . . . . . . . . . . . 2.9 Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

13 13 14 14 16 17 20 20 22 23 24 25 26 28 29 31 34 37 38 42 43 46 47 50 54 55 56 58 61 63 67 69

iii

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

CONTENTS

iv

3

4

2.9.1 Stability in the continuous domain . . . . . . . . . . . . . . . . . . . 2.9.2 Stability of the closed loop . . . . . . . . . . . . . . . . . . . . . . . . 2.9.3 Stability of discrete time systems . . . . . . . . . . . . . . . . . . . . 2.9.4 Stability of nonlinear differential equations . . . . . . . . . . . . . . 2.9.5 Expressing matrix equations succinctly using Kronecker products . 2.9.6 Summary of stability analysis . . . . . . . . . . . . . . . . . . . . . . 2.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

70 72 73 74 80 82 83

Modelling dynamic systems with differential equations 3.1 Dynamic system models . . . . . . . . . . . . . . . . . . . . . . . . . 3.1.1 Steady state and dynamic models . . . . . . . . . . . . . . . 3.2 A collection of illustrative models . . . . . . . . . . . . . . . . . . . . 3.2.1 Simple models . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3 Chemical process models . . . . . . . . . . . . . . . . . . . . . . . . 3.3.1 A continuously-stirred tank reactor . . . . . . . . . . . . . . 3.3.2 A forced circulation evaporator . . . . . . . . . . . . . . . . . 3.3.3 A binary distillation column model . . . . . . . . . . . . . . 3.3.4 Interaction and the Relative Gain Array . . . . . . . . . . . . 3.4 Regressing experimental data by curve fitting . . . . . . . . . . . . . 3.4.1 Polynomial regression . . . . . . . . . . . . . . . . . . . . . . 3.4.2 Nonlinear least-squares model identification . . . . . . . . . 3.4.3 Parameter confidence intervals . . . . . . . . . . . . . . . . . 3.5 Numerical tools for modelling . . . . . . . . . . . . . . . . . . . . . . 3.5.1 Differential/Algebraic equation systems and algebraic loops 3.6 Linearisation of nonlinear dynamic equations . . . . . . . . . . . . . 3.6.1 Linearising a nonlinear tank model . . . . . . . . . . . . . . 3.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

85 85 86 86 86 92 92 94 95 103 107 107 112 116 120 123 125 127 129

The PID controller 4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.1.1 P, PI or PID control . . . . . . . . . . . . . . . . . . . . . . 4.2 The industrial PID algorithm . . . . . . . . . . . . . . . . . . . . 4.2.1 Implementing the derivative component . . . . . . . . . 4.2.2 Variations of the PID algorithm . . . . . . . . . . . . . . . 4.2.3 Integral only control . . . . . . . . . . . . . . . . . . . . . 4.3 Simulating a PID process in S IMULINK . . . . . . . . . . . . . . . 4.4 Extensions to the PID algorithm . . . . . . . . . . . . . . . . . . . 4.4.1 Avoiding derivative kick . . . . . . . . . . . . . . . . . . . 4.4.2 Input saturation and integral windup . . . . . . . . . . . 4.5 Discrete PID controllers . . . . . . . . . . . . . . . . . . . . . . . 4.5.1 Discretising continuous PID controllers . . . . . . . . . . 4.5.2 Simulating a PID controlled response in Matlab . . . . . 4.5.3 Controller performance as a function of sample time . . 4.6 PID tuning methods . . . . . . . . . . . . . . . . . . . . . . . . . 4.6.1 Open loop tuning methods . . . . . . . . . . . . . . . . . 4.6.2 Closed loop tuning methods . . . . . . . . . . . . . . . . 4.6.3 Closed loop single-test tuning methods . . . . . . . . . . 4.6.4 Summary on closed loop tuning schemes . . . . . . . . . 4.7 Automated tuning by relay feedback . . . . . . . . . . . . . . . . 4.7.1 Describing functions . . . . . . . . . . . . . . . . . . . . . 4.7.2 An example of relay tuning . . . . . . . . . . . . . . . . . 4.7.3 Self-tuning with noise disturbances . . . . . . . . . . . . 4.7.4 Modifications to the relay feedback estimation algorithm 4.8 Drawbacks with PID controllers . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . .

131 131 131 132 133 134 135 135 138 138 140 143 144 146 148 148 150 155 159 166 166 168 170 173 176 180

. . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . .

CONTENTS

5

6

v

4.8.1 Inverse response processes . . . . . . . . . . . . . . . . . . . . . . . . 4.8.2 Approximating inverse-response systems with additional deadtime 4.9 Dead time compensation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.10 Tuning and sensitivity of control loops . . . . . . . . . . . . . . . . . . . . . . 4.11 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

181 183 185 187 191

Digital filtering and smoothing 5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1 The nature of industrial noise . . . . . . . . . . . . . . . . 5.1.2 Differentiating without smoothing . . . . . . . . . . . . . 5.2 Smoothing measured data using analogue filters . . . . . . . . . 5.2.1 A smoothing application to find the peaks and troughs . 5.2.2 Filter types . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.3 Classical analogue filter families . . . . . . . . . . . . . . 5.3 Discrete filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.1 A low-pass filtering application . . . . . . . . . . . . . . . 5.3.2 Digital filter approximations . . . . . . . . . . . . . . . . 5.3.3 Efficient hardware implementation of discrete filters . . 5.3.4 Numerical and quantisation effects for high-order filters 5.4 The Fourier transform . . . . . . . . . . . . . . . . . . . . . . . . 5.4.1 Fourier transform definitions . . . . . . . . . . . . . . . . 5.4.2 Orthogonality and frequency spotting . . . . . . . . . . . 5.4.3 Using M ATLAB’s FFT function . . . . . . . . . . . . . . . 5.4.4 Periodogram . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.5 Fourier smoothing . . . . . . . . . . . . . . . . . . . . . . 5.5 Numerically differentiating industrial data . . . . . . . . . . . . 5.5.1 Establishing feedrates . . . . . . . . . . . . . . . . . . . . 5.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . .

193 193 194 196 197 197 197 201 209 209 212 214 217 219 221 224 225 227 228 230 231 233

Identification of process models 6.1 The importance of system identification . . . . . . . . . . . . . 6.1.1 Basic definitions . . . . . . . . . . . . . . . . . . . . . . 6.1.2 Black, white and grey box models . . . . . . . . . . . . 6.1.3 Techniques for identification . . . . . . . . . . . . . . . 6.2 Graphical and non-parametric model identification . . . . . . 6.2.1 Time domain identification using graphical techniques 6.2.2 Experimental frequency response analysis . . . . . . . 6.2.3 An alternative empirical transfer function estimate . . 6.3 Continuous model identification . . . . . . . . . . . . . . . . . 6.3.1 Fitting transfer functions using nonlinear least-squares 6.3.2 Identification using derivatives . . . . . . . . . . . . . . 6.3.3 Practical continuous model identification . . . . . . . . 6.4 Popular discrete-time linear models . . . . . . . . . . . . . . . 6.4.1 Extending the linear model . . . . . . . . . . . . . . . . 6.4.2 Output error model structures . . . . . . . . . . . . . . 6.4.3 General input/output models . . . . . . . . . . . . . . . 6.5 Regressing discrete model parameters . . . . . . . . . . . . . . 6.5.1 Simple offline system identification routines . . . . . . 6.5.2 Bias in the parameter estimates . . . . . . . . . . . . . . 6.5.3 Using the System Identification toolbox . . . . . . . . . 6.5.4 Fitting parameters to state space models . . . . . . . . 6.6 Model structure determination and validation . . . . . . . . . 6.6.1 Estimating model order . . . . . . . . . . . . . . . . . . 6.6.2 Robust model fitting . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

235 235 236 237 238 239 239 246 253 254 254 256 258 260 262 264 265 266 268 269 270 274 276 277 280

. . . . . . . . . . . . . . . . . . . . . . . .

CONTENTS

vi 6.6.3 Common nonlinear model structures . . . . Online model identification . . . . . . . . . . . . . . 6.7.1 Recursive least squares . . . . . . . . . . . . . 6.7.2 Recursive least-squares in M ATLAB . . . . . 6.7.3 Tracking the precision of the estimates . . . . 6.8 The forgetting factor and covariance windup . . . . 6.8.1 The influence of the forgetting factor . . . . . 6.8.2 Covariance wind-up . . . . . . . . . . . . . . 6.9 Identification by parameter optimisation . . . . . . . 6.10 Online estimating of noise models . . . . . . . . . . 6.10.1 A recursive extended least-squares example 6.10.2 Recursive identification using the SI toolbox 6.10.3 Simplified RLS algorithms . . . . . . . . . . . 6.11 Closed loop identification . . . . . . . . . . . . . . . 6.11.1 Closed loop RLS in Simulink . . . . . . . . . 6.12 Summary . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

280 280 281 286 290 292 294 295 296 300 302 305 306 307 309 309

Adaptive Control 7.1 Why adapt? . . . . . . . . . . . . . . . . . . . . . . . . 7.1.1 The adaption scheme . . . . . . . . . . . . . . . 7.1.2 Classification of adaptive controllers . . . . . . 7.2 Gain scheduling . . . . . . . . . . . . . . . . . . . . . . 7.3 The importance of identification . . . . . . . . . . . . 7.3.1 Polynomial manipulations . . . . . . . . . . . 7.4 Self tuning regulators (STRs) . . . . . . . . . . . . . . 7.4.1 Simple minimum variance control . . . . . . . 7.5 Adaptive pole-placement . . . . . . . . . . . . . . . . 7.5.1 The Diophantine equation and the closed loop 7.5.2 Solving the Diophantine equation in Matlab . 7.5.3 Adaptive pole-placement with identification . 7.6 Practical adaptive pole-placement . . . . . . . . . . . 7.6.1 Dealing with non-minimum phase systems . . 7.6.2 Separating stable and unstable factors . . . . . 7.6.3 Experimental adaptive pole-placement . . . . 7.6.4 Minimum variance control with dead time . . 7.7 Summary of adaptive control . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

317 317 318 319 319 321 321 322 323 325 326 327 330 334 335 338 340 341 345

Multivariable controller design 8.1 Controllability and observability . . . . . . . . . . . 8.1.1 Controllability . . . . . . . . . . . . . . . . . . 8.1.2 Observability . . . . . . . . . . . . . . . . . . 8.1.3 Computing controllability and observability 8.1.4 State reconstruction . . . . . . . . . . . . . . 8.2 State space pole-placement controller design . . . . 8.2.1 Poles and where to place them . . . . . . . . 8.2.2 Deadbeat control . . . . . . . . . . . . . . . . 8.3 Estimating the unmeasured states . . . . . . . . . . . 8.4 Combining estimation and state feedback . . . . . . 8.5 Generic model control . . . . . . . . . . . . . . . . . 8.5.1 The tuning parameters . . . . . . . . . . . . . 8.5.2 GMC control of a linear model . . . . . . . . 8.5.3 GMC applied to a nonlinear plant . . . . . . 8.6 Exact feedback linearisation . . . . . . . . . . . . . . 8.6.1 The nonlinear system . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

351 352 352 354 355 356 359 362 364 366 367 369 371 373 375 380 380

6.7

7

8

. . . . . . . . . . . . . . . .

CONTENTS

8.7 9

vii

8.6.2 The input/output feedback linearisation control law . . . . . . . . . . . . . 380 8.6.3 Exact feedback example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386

Classical optimal control 9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.2 Parametric optimisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.2.1 Choosing a performance indicator . . . . . . . . . . . . . . . . . . . . . . 9.2.2 Optimal tuning of a PID regulator . . . . . . . . . . . . . . . . . . . . . . 9.2.3 Using S IMULINK inside an optimiser . . . . . . . . . . . . . . . . . . . . . 9.2.4 An optimal batch reactor temperature policy . . . . . . . . . . . . . . . . 9.3 The general optimal control problem . . . . . . . . . . . . . . . . . . . . . . . . . 9.3.1 The optimal control formulation . . . . . . . . . . . . . . . . . . . . . . . 9.3.2 The two-point boundary problem . . . . . . . . . . . . . . . . . . . . . . 9.3.3 Optimal control examples . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3.4 Problems with a specified target set . . . . . . . . . . . . . . . . . . . . . 9.4 Linear quadratic control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.4.1 Continuous linear quadratic regulators . . . . . . . . . . . . . . . . . . . 9.4.2 Analytical solution to the LQR problem . . . . . . . . . . . . . . . . . . . 9.4.3 The steady-state solution to the matrix Riccati equation . . . . . . . . . . 9.4.4 The discrete LQR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.4.5 A numerical validation of the optimality of LQR . . . . . . . . . . . . . . 9.4.6 An LQR with integral states . . . . . . . . . . . . . . . . . . . . . . . . . . 9.5 Estimation of state variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.5.1 Random processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.5.2 Combining deterministic and stochastic processes . . . . . . . . . . . . . 9.5.3 The Kalman filter estimation scheme . . . . . . . . . . . . . . . . . . . . . 9.5.4 The steady-state form of the Kalman filter . . . . . . . . . . . . . . . . . . 9.5.5 Current and future prediction forms . . . . . . . . . . . . . . . . . . . . . 9.5.6 An application of the Kalman filter . . . . . . . . . . . . . . . . . . . . . . 9.5.7 The role of the Q and R noise covariance matrices in the state estimator 9.5.8 Extensions to the basic Kalman filter algorithm . . . . . . . . . . . . . . . 9.5.9 The Extended Kalman Filter . . . . . . . . . . . . . . . . . . . . . . . . . . 9.5.10 Combining state estimation and state feedback . . . . . . . . . . . . . . . 9.5.11 Optimal control using only measured outputs . . . . . . . . . . . . . . . 9.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

10 Predictive control 10.1 Model predictive control . . . . . . . . . . . . 10.1.1 Constrained predictive control . . . . 10.1.2 Dynamic matrix control . . . . . . . . 10.2 A Model Predictive Control Toolbox . . . . . 10.2.1 A model predictive control GUI . . . 10.2.2 MPC toolbox in M ATLAB . . . . . . . 10.2.3 Using the MPC toolbox in S IMULINK 10.2.4 Further readings on MPC . . . . . . . 10.3 Optimal control using linear programming . 10.3.1 Development of the LP problem . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

387 387 388 388 389 395 396 397 399 401 402 406 409 409 411 415 418 423 427 431 431 437 438 442 443 447 448 452 454 457 457 459

. . . . . . . . . .

461 461 464 468 474 474 474 476 477 478 479

CONTENTS

viii 11 Expert systems and neural networks 11.1 Expert systems . . . . . . . . . . . . . . . . . . . 11.1.1 Where are they used? . . . . . . . . . . 11.1.2 Features of an expert system . . . . . . 11.1.3 The user interface . . . . . . . . . . . . . 11.1.4 Expert systems used in process control 11.2 Neural networks . . . . . . . . . . . . . . . . . 11.2.1 The architecture of the neural network . 11.2.2 Curve fitting using neural networks . . 11.3 Summary . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

487 487 488 488 490 490 493 495 499 503

A List of symbols

505

B Useful utility functions in Matlab

507

C Transform pairs

509

D A comparison of Maple and MuPad D.1 Partial fractions . . . . . . . . . D.2 Integral transforms . . . . . . . D.3 Differential equations . . . . . . D.4 Vectors and matrices . . . . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

511 511 511 512 513

E Useful test models 515 E.1 A forced circulation evaporator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515 E.2 Aircraft model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516

List of Figures 1.1 1.2 1.3

Traditional vs. Advanced control . . . . . . . . . . . . . . . . . . Economic improvements of better control . . . . . . . . . . . . . Blackbox configuration. The manual switch marked will toggle or 9 low-pass filters. . . . . . . . . . . . . . . . . . . . . . . . . . . 1.4 The “Black-box” . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5 Balance arm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.6 The flapper wiring . . . . . . . . . . . . . . . . . . . . . . . . . . 1.7 Flapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.8 Helicopter plant with 2 degrees of freedom. See also Fig. 1.9(a). 1.9 Helicopter control . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.10 Helicopter flying . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.11 Real-time Simulink simulations . . . . . . . . . . . . . . . . . . . 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 2.12 2.13 2.14 2.15 2.16 2.17 2.18 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26

. . . . . . . . . . . . . . . . . . . . . . between either 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The computer in the control loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 bit sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A time series with unknown frequency components . . . . . . . . . . . . . . . . . . The frequency component of a sampled signal . . . . . . . . . . . . . . . . . . . . . Frequency aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Scarlet Letter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . H´enon’s attractor in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . H´enon’s attractor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Inverting z-transforms using dimpulse . . . . . . . . . . . . . . . . . . . . . . . . . . Numerically inverting the Laplace transform using the Bromwich integral . . . . . Numerically inverting the Laplace transform . . . . . . . . . . . . . . . . . . . . . . Numerically inverting Laplace transforms . . . . . . . . . . . . . . . . . . . . . . . . Ideal sampler and zeroth-order hold . . . . . . . . . . . . . . . . . . . . . . . . . . . Zeroth-order hold effects on the discrete Bode diagram . . . . . . . . . . . . . . . . Bode plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The discrete root locus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Various discrete closed loop responses . . . . . . . . . . . . . . . . . . . . . . . . . . A binary distillation column with multiple inputs and multiple outputs . . . . . . A block diagram of a state-space dynamic system, (a) continuous system: x˙ = Ax + Bu, and (b) discrete system: xk+1 = Φxk + ∆uk . (See also Fig. 2.20.) . . . . A complete block diagram of a state-space dynamic system with output and direct measurement feed-through, Eqn. 2.41. . . . . . . . . . . . . . . . . . . . . . . . . . . Unsteady and steady states for level systems . . . . . . . . . . . . . . . . . . . . . . Submarine step response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Issues in assessing system stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . Nyquist diagram of Eqn. 2.94 in (a) three dimensions and (b) as typically presented in two dimensions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Liapunov (1857–1918) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Regions of stability for the poles of continuous (left) and discrete (right) systems . ix

5 6 7 7 8 9 9 10 11 12 12 14 15 18 18 19 20 21 22 29 33 33 34 35 41 42 44 44 45 47 48 57 66 69 73 75 82

LIST OF FIGURES

x 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 3.20 3.21 3.22 3.23 3.24

A stable and unstable pendulum . . . . . . . . . . . . Simple buffer tank . . . . . . . . . . . . . . . . . . . . The UK growth based on the GDP . . . . . . . . . . . A CSTR reactor . . . . . . . . . . . . . . . . . . . . . . A forced circulation evaporator . . . . . . . . . . . . . Schematic of a distillation column . . . . . . . . . . . Wood-Berry step response . . . . . . . . . . . . . . . . Wood-Berry column in S IMULINK . . . . . . . . . . . . Distillation tower . . . . . . . . . . . . . . . . . . . . . Sparsity of the distillation column model . . . . . . . Open loop distillation column control . . . . . . . . . Distillation column control . . . . . . . . . . . . . . . . Distillation column control (in detail) . . . . . . . . . . Distillation interactions . . . . . . . . . . . . . . . . . . Dynamic RGA . . . . . . . . . . . . . . . . . . . . . . . Dynamic RGA . . . . . . . . . . . . . . . . . . . . . . . Density of Air . . . . . . . . . . . . . . . . . . . . . . . Fitting a high-order polynomial to some physical data A bio-chemical reaction . . . . . . . . . . . . . . . . . Model of compressed water . . . . . . . . . . . . . . . Experimental pressure-rate data . . . . . . . . . . . . . Parameter confidence regions . . . . . . . . . . . . . . Linear and nonlinear trajectories . . . . . . . . . . . . Linearising a nonlinear tank model . . . . . . . . . . .

4.1

Comparing PI and integral-only control for the real-time control of a noisy flapper plant with sampling time T = 0.08. . . . . . . . . . . . . . . . . . . . . . . . . . . . . PID simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . PID internals in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block diagram of PID controllers as implemented in S IMULINK (left) and classical text books (right). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Realisable PID controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . PID controller in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . PID controller with anti-derivative kick. . . . . . . . . . . . . . . . . . . . . . . . . . Avoiding derivative kick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Illustrating the improvement of anti-derivative kick schemes for PID controllers when applied to the experimental electromagnetic balance. . . . . . . . . . . . . . . Derivative control and noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Anti-windup comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Discrete PID controller in S IMULINK . . . . . . . . . . . . . . . . . . . . . . . . . . . Headbox control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Headbox controlled response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A PID controlled process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sample time and discrete PID control . . . . . . . . . . . . . . . . . . . . . . . . . . The parameters T and L to be graphically estimated for the openloop tuning method relations given in Table 4.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Cohen-Coon model fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Cohen-Coon tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . PID tuning using a GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Solving for the ultimate frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ziegler-Nichols tuned responses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Typical response of a stable system to a P-controller. . . . . . . . . . . . . . . . . . . A Yuwana-Seborg closed loop step test . . . . . . . . . . . . . . . . . . . . . . . . . . Closed loop responses using the YS scheme . . . . . . . . . . . . . . . . . . . . . . .

4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10 4.11 4.12 4.13 4.14 4.15 4.16 4.17 4.18 4.19 4.20 4.21 4.22 4.23 4.24 4.25

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

87 89 91 93 94 96 97 98 99 101 102 103 103 104 106 106 109 111 114 115 119 119 121 128 135 135 136 136 137 137 139 139 140 141 142 145 146 147 148 149 151 152 153 154 157 158 160 163 164

LIST OF FIGURES 4.26 4.27 4.28 4.29 4.30 4.31 4.32 4.33 4.34 4.35 4.36 4.37 4.38 4.39 4.40 4.41 4.42 4.43 4.44 4.45 4.46 4.47 4.48

xi

A self-tuning PID controlled process . . . . . . . . . . . . . . . . . . . . . . . . . . . A process under relay tuning with the PID regulator disabled. . . . . . . . . . . . . An unknown plant under relay feedback exhibits an oscillation . . . . . . . . . . . Nyquist & Bode diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . PID Relay tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Relay tuning with noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Relay tuning of the blackbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Relay tuning results of the blackbox . . . . . . . . . . . . . . . . . . . . . . . . . . . A relay with hysteresis width h and output amplitude d. . . . . . . . . . . . . . . . Relay feedback with hysteresis width h. . . . . . . . . . . . . . . . . . . . . . . . . . Relay feedback with hysteresis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Relay feedback with an integrator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-point Relay identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The J curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . An inverse response process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A NMP plant controlled with a PI controller . . . . . . . . . . . . . . . . . . . . . . Approximating inverse-response systems with additional deadtime . . . . . . . . . The Smith predictor structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Smith predictor structure from Fig. 4.43 assuming no model/plant mis-match. Smith predictor in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Dead time compensation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Deadtime compensation applied to the blackbox . . . . . . . . . . . . . . . . . . . . Closed loop with plant G(s) and controller C(s) subjected to disturbances and measurement noise. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.49 Sensitivity transfer functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.50 Sensitivity robustness measure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

167 167 169 171 172 174 175 176 177 178 178 178 180 181 182 183 184 185 186 186 187 188

5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.10 5.11 5.12 5.13 5.14 5.15 5.16 5.17 5.18 5.19 5.20

193 194 195 196 198 199 199 200 202 207 208 211 212 213 214 215 216 217 218

5.21 5.22 5.23 5.24 5.25

A filter as a transfer function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A noisy measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Noise added to a true, but unknown, signal . . . . . . . . . . . . . . . . . . . . . . . Derivative action given noisy data . . . . . . . . . . . . . . . . . . . . . . . . . . . . Smoothing industrial data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Low-pass filter specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Three single low-pass filters cascaded together to make a third-order filter. . . . . . Amplitude response for ideal, low-pass, high pass and band-pass filters. . . . . . . Analogue Butterworth filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Analogue Chebyshev filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Butterworth and Chebyshev filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using a Butterworth filter to smooth noisy data . . . . . . . . . . . . . . . . . . . . . The frequency response for Butterworth filters . . . . . . . . . . . . . . . . . . . . . Various Butterworth filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Advantages of frequency pre-warping . . . . . . . . . . . . . . . . . . . . . . . . . . Hardware difference equation in Direct Form I . . . . . . . . . . . . . . . . . . . . . An IIR filter with a minimal number of delays, Direct Form II . . . . . . . . . . . . Cascaded second-order sections to realise a high-order filter. See also Fig. 5.19. . . A second-order section (SOS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparing single precision second-order sections with filters in direct form II transposed form. Note that the direct form II filter is actually unstable when run in single precision. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating square waves with sine waves . . . . . . . . . . . . . . . . . . . . . The Fourier approximation to a square wave . . . . . . . . . . . . . . . . . . . . . . Two signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Critical radio frequencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Power spectrum for a signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

189 190 190

219 223 223 224 228 229

LIST OF FIGURES

xii

5.26 Smoothing by Fourier transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 5.27 Differentiating and smoothing noisy measurement . . . . . . . . . . . . . . . . . . . 232 5.28 Filtering industrial data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 6.10 6.11 6.12 6.13 6.14 6.15 6.16 6.17

6.18 6.19 6.20 6.21 6.22 6.23 6.24 6.25 6.26 6.27 6.28 6.29

6.30 6.31 6.32 6.33 6.34 6.35 6.36 6.37 6.38 6.39 6.40 6.41

The prediction problem: Given a model and the input, u, can we predict the output, y? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A good model, M, duplicates the behaviour of the true plant, S. . . . . . . . . . . . An experimental setup for input/output identification. We log both the input and the response data to a computer for further processing. . . . . . . . . . . . . . . . . Typical open loop step tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Areas method for model identification . . . . . . . . . . . . . . . . . . . . . . . . . . Examples of the Areas method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Identification of the Blackbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Balance arm step test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Random signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A 5-element binary shift register to generate a pseudo-random binary sequence. . Pseudo-random binary sequence generator in S IMULINK . . . . . . . . . . . . . . . Black box experimental setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Black box response analysis using a series of sine waves . . . . . . . . . . . . . . . . Black box response using an input chirp signal. . . . . . . . . . . . . . . . . . . . . . Black box frequency response analysis using a chirp signal. . . . . . . . . . . . . . . Flapper response to a chirp signal. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Experimental setup to subject a random input into an unknown plant. The input/output data was collected, processed through Listing 6.2 to give the frequency response shown in Fig. 6.18. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The experimental frequency response compared to the true analytical Bode diagram. See the routine in Listing 6.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Black box response given a pseudo-random input sequence. . . . . . . . . . . . . . Black box frequency response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Empirical transfer function estimate . . . . . . . . . . . . . . . . . . . . . . . . . . . Experimental data from a continuous plant . . . . . . . . . . . . . . . . . . . . . . . A continuous-time model fitted to input/output data . . . . . . . . . . . . . . . . . Continuous model identification strategy . . . . . . . . . . . . . . . . . . . . . . . . Continuous model identification simulation . . . . . . . . . . . . . . . . . . . . . . . Continuous model identification of the blackbox . . . . . . . . . . . . . . . . . . . . Identification using Laguerre functions . . . . . . . . . . . . . . . . . . . . . . . . . A signal flow 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. . . A signal flow 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 filtering the noise term. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A signal flow diagram of an output-error model. Compare this structure with the similar ARX model in Fig. 6.28. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A general input/output model structure . . . . . . . . . . . . . . . . . . . . . . . . . ARX estimation exhibiting bias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Offline system identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Identification of deadtime from the step response . . . . . . . . . . . . . . . . . . . Deadtime estimation at fast sampling . . . . . . . . . . . . . . . . . . . . . . . . . . Deadtime estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Blackbox step model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Hammerstein and Wiener model structures . . . . . . . . . . . . . . . . . . . . . . . Ideal RLS parameter estimation. (See also Fig. 6.41(a).) . . . . . . . . . . . . . . . . Recursive least squares estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . RLS under S IMULINK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

235 237 238 240 241 242 242 243 244 245 245 247 247 249 249 250

250 251 252 252 253 255 256 257 259 260 261 262

263 264 265 270 271 278 278 279 279 281 286 287 288

LIST OF FIGURES

xiii

6.42 6.43 6.44 6.45 6.46 6.47 6.48 6.49 6.50 6.51 6.52 6.53 6.54 6.55 6.56 6.57 6.58

RLS under S IMULINK (version 2) . . . . . . . . . . . . . . . . . . . . Estimation of a two parameter plant . . . . . . . . . . . . . . . . . . Confidence limits for estimation . . . . . . . . . . . . . . . . . . . . RLS and an abrupt plant change . . . . . . . . . . . . . . . . . . . . The memory when using a forgetting factor . . . . . . . . . . . . . . Identification using various forgetting factors . . . . . . . . . . . . . Covariance wind-up . . . . . . . . . . . . . . . . . . . . . . . . . . . The MIT rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Optimising the adaptation gain . . . . . . . . . . . . . . . . . . . . . Addition of coloured noise to a dynamic process. See also Fig. 6.31. RLS with coloured noise . . . . . . . . . . . . . . . . . . . . . . . . . Nonlinear parameter estimation . . . . . . . . . . . . . . . . . . . . Recursive extended least-squares estimation . . . . . . . . . . . . . A simplified recursive least squares algorithm . . . . . . . . . . . . Furnace input/output data . . . . . . . . . . . . . . . . . . . . . . . Closed loop estimation using Simulink . . . . . . . . . . . . . . . . . RLS in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

289 291 291 292 293 294 296 299 300 301 303 304 305 307 308 309 315

7.1 7.2 7.3 7.4 7.5 7.6 7.7

319 320 324 325 325 331

7.20

The structure of an indirect adaptive controller . . . . . . . . . . . . . . . . . . . . . Varying process gain of a spherical tank . . . . . . . . . . . . . . . . . . . . . . . . . Simple minimum variance control . . . . . . . . . . . . . . . . . . . . . . . . . . . . Simple minimum variance control (zoomed) . . . . . . . . . . . . . . . . . . . . . . Adaptive pole-placement control structure . . . . . . . . . . . . . . . . . . . . . . . Adaptive pole-placement control structure with RLS identification . . . . . . . . . Control of multiple plants with an adapting controller. We desire the same closed loop response irrespective of the choice of plant. . . . . . . . . . . . . . . . . . . . . Three open loop plants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Desired closed loop response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adaptive pole-placement with identification . . . . . . . . . . . . . . . . . . . . . . Comparing the adaptive pole-placement with the reference trajectory . . . . . . . . Bursting in adaptive control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A plant with poorly damped zeros . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adaptive pole-placement with an unstable B . . . . . . . . . . . . . . . . . . . . . . Pole-zero map of an adaptive pole-placement . . . . . . . . . . . . . . . . . . . . . . Areas of well-damped poles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adaptive pole-placement of the black-box . . . . . . . . . . . . . . . . . . . . . . . . Adaptive pole-placement of the black-box . . . . . . . . . . . . . . . . . . . . . . . . A non-minimum phase plant with an unstable zero which causes an inverse step response. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Moving average control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

345 346

8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 8.10 8.11 8.12 8.13

Reconstructing states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pole-placement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Deadbeat control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Simultaneous control and state estimation . . . . . . . . . . . . . . . . . . Control and estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . GMC tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . GMC tuning characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . Linear GMC response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Linear GMC comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . GMC CSTR control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A CSTR phase plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The configuration of an input/output feedback linearisation control law Exact feedback linearisation . . . . . . . . . . . . . . . . . . . . . . . . . .

360 363 365 368 370 372 372 374 375 378 379 381 385

7.8 7.9 7.10 7.11 7.12 7.13 7.14 7.15 7.16 7.17 7.18 7.19

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

332 332 332 334 335 336 336 339 340 340 342 343

LIST OF FIGURES

xiv 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 9.10 9.11 9.12 9.13 9.14 9.15 9.16 9.17 9.18 9.19 9.20 9.21 9.22 9.23 9.24 9.25 9.26 9.27 9.28 9.29 9.30 9.31 9.32 9.33 9.34 9.35

IAE areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ITAE breakdown . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Optimal responses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Optimal PID tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Optimum PI tuning of the blackbox plant . . . . . . . . . . . . . . . . . . . . . . . . S IMULINK model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Production of a valuable chemical in a batch reactor. . . . . . . . . . . . . . . . . . . Temperature profile optimisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Temperature profile optimisation using 3 temperatures . . . . . . . . . . . . . . . . Optimum temperature profile comparison for different number of temperatures . Optimal control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Optimal control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Optimal control with targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Steady-state and time-varying LQR control . . . . . . . . . . . . . . . . . . . . . . . Steady-state continuous LQR controller . . . . . . . . . . . . . . . . . . . . . . . . . Comparing discrete and continuous LQR controllers . . . . . . . . . . . . . . . . . . LQR control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pole-placement and LQR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pole-placement and LQR showing the input . . . . . . . . . . . . . . . . . . . . . . Trial pole locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Trial pole-placement performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . State feedback control system with an integral output state . . . . . . . . . . . . . . State feedback with integral states . . . . . . . . . . . . . . . . . . . . . . . . . . . . Black box servo control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A state-based estimation and control scheme . . . . . . . . . . . . . . . . . . . . . . PDF of a random variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Correlated noisy x, y data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2D ellipse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Kalman filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A block diagram of a steady-state prediction-type Kalman filter applied to a linear discrete plant. Compare with the alternative form in Fig. 9.31. . . . . . . . . . . . . A block diagram of a steady-state current estimator-type Kalman filter applied to a linear discrete plant. Compare with the alternative prediction form in Fig. 9.30. . Kalman filter demonstration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The performance of a Kalman filter for different q/r ratios . . . . . . . . . . . . . . A random walk process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . LQG in S IMULINK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

10.1 Horizons used in model predictive control . . . 10.2 Predictions of the Reserve Bank . . . . . . . . . . 10.3 Inverse plant . . . . . . . . . . . . . . . . . . . . . 10.4 Predictive control . . . . . . . . . . . . . . . . . . 10.5 Acausal response . . . . . . . . . . . . . . . . . . 10.6 Varying the horizons of predictive control . . . . 10.7 MPC on the blackbox . . . . . . . . . . . . . . . . 10.8 Step response coefficients, gi , for a stable system. 10.9 DMC control details . . . . . . . . . . . . . . . . 10.10DMC control . . . . . . . . . . . . . . . . . . . . . 10.11Adaptive DMC of the blackbox . . . . . . . . . . 10.12An MPC graphical user interface . . . . . . . . . 10.13Multivariable MPC . . . . . . . . . . . . . . . . . 10.14S IMULINK and MPC . . . . . . . . . . . . . . . . 10.15MPC . . . . . . . . . . . . . . . . . . . . . . . . . 10.16LP constraint matrix dimensions . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . .

389 390 390 393 394 395 396 397 398 398 404 406 408 414 417 420 423 424 425 425 426 428 429 430 431 432 435 436 442 444 445 448 451 456 458 462 462 465 466 467 468 468 469 471 472 473 474 476 476 477 481

LIST OF FIGURES 10.17LP optimal control . . . . . . . . . . . . . . . . 10.18LP optimal control with active constraints . . . 10.19Non-square LP optimal control . . . . . . . . . 10.20LP optimal control showing acausal behaviour 11.1 11.2 11.3 11.4 11.5 11.6 11.7 11.8

xv . . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

484 485 485 486

Possible neuron activation functions. . . . . . . . . . . . . . . . . A single neural processing unit with multiple inputs . . . . . . . . Single layer feedforward neural network . . . . . . . . . . . . . . A 3 layer fully interconnected feedforward neural network . . . . Single layer network with feedback . . . . . . . . . . . . . . . . . . An unknown input/output function . . . . . . . . . . . . . . . . . Fitting a Neural-Network to an unknown input/output function Tide predictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

495 496 497 497 498 499 501 502

xvi

LIST OF FIGURES

List of Tables 1.1

Computer aids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

2.1 2.2 2.3

Final and initial value theorems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Inverting a z transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Laplace transform pairs used for testing . . . . . . . . . . . . . . . . . . . . . . . . .

24 30 34

3.1 3.2 3.3 3.4 3.5 3.6

Standard nomenclature used in modelling dynamic systems . . . . Parameters of the CSTR model . . . . . . . . . . . . . . . . . . . . . The important variables in the forced circulation evaporator . . . . Compressed water . . . . . . . . . . . . . . . . . . . . . . . . . . . . The parameter values for the CSTR model . . . . . . . . . . . . . . . The initial state and manipulated variables for the CSTR simulation

4.1 4.2 4.3

4.5 4.6

Alternative PID tuning parameter conventions . . . . . . . . . . . . . . . . . . . . . Ziegler-Nichols open-loop PID tuning rules . . . . . . . . . . . . . . . . . . . . . . . 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 . . . . . . . Various alternative ‘Ziegler-Nichols’ type PID tuning rules as a function of the ultimate gain, Ku , and ultimate period, Pu . . . . . . . . . . . . . . . . . . . . . . . . Closed-loop single-test PID design rules . . . . . . . . . . . . . . . . . . . . . . . . . Relay based PID tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5.1

Filter transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201

6.1 6.2

Experimentally determined frequency response of the blackbox . . . . . . . . . . . 248 Identification in state-space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276

8.1 8.2

The relationship between regulation and estimation . . . . . . . . . . . . . . . . . . 367 Litchfield nonlinear CSTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376

9.1

Common integral performance indices . . . . . . . . . . . . . . . . . . . . . . . . . . 391

4.4

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. 90 . 93 . 94 . 114 . 122 . 123 132 152 154 155 161 172

11.1 Comparing expert systems and neural networks . . . . . . . . . . . . . . . . . . . . 494

xvii

xviii

LIST OF TABLES

Listings 2.1 2.2 2.3

Symbolic Laplace to z-transform conversion . . . . . . . . . . . . . . . . . . . . . . Symbolic Laplace to z-transform conversion with ZOH . . . . . . . . . . . . . . . . Extracting the gain, time constants and numerator time constants from an arbitrary transfer function format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.4 Submarine simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.5 Example of the Routh array using the symbolic toolbox . . . . . . . . . . . . . . . . 2.6 Solve the continuous matrix Lyapunov equation using Kronecker products . . . . 2.7 Solve the matrix Lyapunov equation using the lyap routine . . . . . . . . . . . . . 2.8 Solve the discrete matrix Lyapunov equation using Kronecker products . . . . . . 3.1 Computing the dynamic relative gain array analytically . . . . . . . . . . . . . . . . 3.2 Computing the dynamic relative gain array numerically as a function of ω. See also Listing 3.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3 Curve fitting using polynomial least-squares . . . . . . . . . . . . . . . . . . . . . . 3.4 Polynomial least-squares using singular value decomposition. This routine follows from, and provides an alternative to Listing 3.3. . . . . . . . . . . . . . . . . . 3.5 Curve fitting using a generic nonlinear optimiser . . . . . . . . . . . . . . . . . . . . 3.6 Curve fitting using the O PTI optimisation toolbox. (Compare with Listing 3.5.) . . 3.7 Fitting water density as a function of temperature and pressure . . . . . . . . . . . 3.8 Parameter confidence limits for a nonlinear reaction rate model . . . . . . . . . . . 3.9 Comparing the dynamic response of a pendulum to the linear approximation . . . 3.10 Using linmod to linearise an arbitrary S IMULINK module. . . . . . . . . . . . . . . 4.1 Constructing a transfer function of a PID controller . . . . . . . . . . . . . . . . . . 4.2 Constructing a discrete (filtered) PID controller . . . . . . . . . . . . . . . . . . . . . 4.3 A simple PID controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ¿ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4 Ziegler-Nichols PID tuning rules for an arbitrary transfer function . . . . . . . . . . 4.5 Identifies the characteristic points for the Yuwana-Seborg PID tuner from a trial closed loop response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.6 Compute the closed loop model from peak and trough data . . . . . . . . . . . . . 4.7 Compute the ultimate gain and frequency from the closed loop model parameters. 4.8 Compute the open loop model, Gm , Eqn. 4.31. . . . . . . . . . . . . . . . . . . . . . 4.9 Compute appropriate PI or PID tuning constants based on a plant model, Gm , using the IMC schemes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.10 Calculates the period and amplitude of a sinusoidal time series using least-squares. 5.1 Designing Butterworth Filters using Eqn. 5.4. . . . . . . . . . . . . . . . . . . . . . . 5.2 Designing a low-pass Butterworth filter with a cut-off frequency of fc = 800 Hz. . 5.3 Designing a high-pass Butterworth filter with a cut-off frequency of fc = 800 Hz. . 5.4 Designing Chebyshev Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5 Computing a Chebyshev Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.6 Converting a 7th-order Butterworth filter to 4 second-order sections . . . . . . . . . 5.7 Comparing DFII and SOS digital filters in single precision. . . . . . . . . . . . . . . 5.8 Routine to compute the power spectral density plot of a time series . . . . . . . . . xix

37 37 56 65 71 77 78 79 105 105 109 111 113 113 115 118 121 127 133 145 146 157 159 164 165 165 165 165 174 203 203 203 206 207 218 219 226

LISTINGS

xx 5.9 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 6.10 6.11 6.12 6.13 6.14 6.15 6.16 6.17 6.18 6.19 6.20 6.21 6.22 6.23 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 8.10 8.11 9.1 9.2

Smoothing and differentiating a noisy signal . . . . . . . . . . . . . . . . . . . . . . Identification of a first-order plant with deadtime from an openloop step response using the Areas method from Algorithm 6.1. . . . . . . . . . . . . . . . . . . . . . . Frequency response identification of an unknown plant directly from input/output data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Non-parametric frequency response identification using etfe. . . . . . . . . . . . . Function to generate output predictions given a trial model and input data. . . . . Optimising the model parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Validating the fitted model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Continuous model identification of a non-minimum phase system . . . . . . . . . . Generate some input/output data for model identification . . . . . . . . . . . . . . Estimate an ARX model from an input/output data series using least-squares . . . An alternative way to construct the data matrix for ARX estimation using Toeplitz matrices. See also Listing 6.9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Offline system identification using arx from the System Identification Toolbox . . Offline system identification with no model/plant mismatch . . . . . . . . . . . . . Demonstrate the fitting of an AR model. . . . . . . . . . . . . . . . . . . . . . . . . . Create an input/output sequence from an output-error plant. . . . . . . . . . . . . Parameter identification of an output error process using oe and arx. . . . . . . . A basic recursive least-squares (RLS) update (without forgetting factor) . . . . . . . Tests the RLS identification scheme using Listing 6.16. . . . . . . . . . . . . . . . . . A recursive least-squares (RLS) update with a forgetting factor. (See also Listing 6.16.) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adaption of the plant gain using steepest descent . . . . . . . . . . . . . . . . . . . Create an ARMAX process and generate some input/output data suitable for subsequent identification. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Identify an ARMAX process from the data generated in Listing 6.20. . . . . . . . . Recursively identify an ARMAX process. . . . . . . . . . . . . . . . . . . . . . . . . Kaczmarz’s algorithm for identification . . . . . . . . . . . . . . . . . . . . . . . . . Simple minimum variance control where the plant has no time delay . . . . . . . . A Diophantine routine to solve F A + BG = T for the polynomials F and G. . . . . Alternative Diophantine routine to solve F A + BG = T for the polynomials F and G. Compare with Listing 7.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Constructing polynomials for the Diophantine equation example . . . . . . . . . . Solving the Diophantine equation using polynomials generated from Listing 7.4. . Adaptive pole-placement control with 3 different plants . . . . . . . . . . . . . . . . The pole-placement control law when H = 1/B . . . . . . . . . . . . . . . . . . . . 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 defined as monic. . . . . . . . . . . . Minimum variance control design . . . . . . . . . . . . . . . . . . . . . . . . . . . . A simple state reconstructor following Algorithm 8.1. . . . . . . . . . . . . . . . . . Pole-placement control of a well-behaved system . . . . . . . . . . . . . . . . . . . . A deadbeat controller simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pole placement for controllers and estimators . . . . . . . . . . . . . . . . . . . . . . GMC on a Linear Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . GMC for a batch reactor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The dynamic equations of a batch reactor . . . . . . . . . . . . . . . . . . . . . . . . Find the Lie derivative for a symbolic system . . . . . . . . . . . . . . . . . . . . . . Establish relative degree, r (ignore degree 0 possibility) . . . . . . . . . . . . . . . . Design Butterworth filter of order r. . . . . . . . . . . . . . . . . . . . . . . . . . . . Symbolically create the closed loop expression . . . . . . . . . . . . . . . . . . . . . Returns the IAE performance for a given tuning. . . . . . . . . . . . . . . . . . . . . Optimal tuning of a PID controller for a non-minimum phase plant. This script file uses the objective function given in Listing 9.1. . . . . . . . . . . . . . . . . . . . . .

232 241 250 253 255 255 256 258 268 269 269 271 271 272 273 273 284 286 293 299 302 303 303 306 323 328 328 329 330 333 337 338 343 359 362 365 369 373 377 377 383 384 384 384 392 392

LISTINGS

xxi

9.3

Returns the ITSE using a S IMULINK 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 profile 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 Listing 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 vectorisation given matrices A, B, Q and 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 filter. . . 447 9.26 Computing the Kalman gain using dlqe. . . . . . . . . . . . . . . . . . . . . . . . . 449 9.27 Demonstrating the optimality of the Kalman filter. . . . . . . . . . . . . . . . . . . . 450 9.28 Potter’s algorithm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453 10.1 Predictive control with input saturation constraints using a generic nonlinear optimiser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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 fitting . . . . . . . . . . . . 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 flatter 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 find 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 physical 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 necessary corrections. Control as a technical discipline is therefore important not only in the fields 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 influencing things. For example, it is worthwhile to study the operation of a coal fired 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 protect 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 earth’s orbit, or blast the asteroid, to avoid the collision. In these latter examples, the problem exists, but our influence is negligible. The teaching of control has changed in emphasis over the last decade from that of linear singleinput/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 M ATLAB 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 first 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 M ATLAB from the MathWorks, [134]. With 1

CHAPTER 1. INTRODUCTION

2

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 filtering and smoothing are introduced in chapter 5. Identification 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 expressions, 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 fixed-width font as A=chol(B*B’). In some cases where you are to type an interactive command, the M ATLAB 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. perform intensive numerical calculations and simulations for proto-typing and testing quickly and reliably, and finally 3. to implement the controller at high speed in special hardware such as an embedded controller 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 efficiently 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 M ATLAB for the design, simulation and prototyping of controllers. M ATLAB, (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 F ORTRAN linear algebra collection of programmes, L INPACK and E ISPACK. With this direct interpretive interface, one can write quite sophisticated algorithms in a very high level language, that are consequently easy to read and maintain. Today M ATLAB 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 specific interest. The toolboxes we are most interested in, and used in this book are: Control toolbox containing functions for controller design, frequency domain analysis, conversions between various models forms, pole placement, optimal control etc. (Used throughout) Symbolic toolbox which contains a gateway to the symbolic capabilities of M APLE. Signal processing toolbox containing filters, wave form generation and spectral analysis. (Used principally in chapter 5.) System identification toolbox for identifying the parameters of various dynamic model types. (Used in chapter 6.) You may also find the following free statistics toolbox useful available at: www.maths.lth.se/matstat/stixbox/. Real-time toolbox can be used to interface M ATLAB to various analogue to digital converters. The student version of M ATLAB (at time of writing) has a special S IGNALS & S YSTEMS 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 O PTIMISATION TOOLBOX, used in chapter 9 and the N EURAL N ETWORK toolbox. Additional documentation to that supplied with M ATLAB is the concise and free summary notes [183] or the more recent [68]. Recently there has been exponential growth of other texts that heavily use M ATLAB (such as this one), and a current list is available from the Mathwork’s anonymous ftp server at www.mathworks.com. This server also contains many user contributed codes, as well as updates, bug fixes etc. If M ATLAB, 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 M ATLAB examples.

1.2.1 Alternative computer design aids Table 1.1 lists a number of alternatives computer-aided design and modelling environments similar and complimentary to M ATLAB.

Product S CI L AB O CTAVE RL AB V ISUAL M ODEL Q M ATH V IEWS M U PAD M APLE M ATHEMATICA

WWW site www.scilab.org www.octave.org rlabplus.sourceforge.net www.qxdesign.com www.mathwizards.com www.mupad.de www.maplesoft.com www.mathematica.com

comment Free Matlab/Simulink clone Free Matlab clone, inactive Matlab clone, Linux shareware Simulink clone shareware Interfaces with S CI L AB commercial CAS commercial CAS

Table 1.1: Shareware or freeware Matlab lookalikes and computer algebra systems Unlike M ATLAB, symbolic manipulators are computer programs that by manipulating symbols can perform algebra. Such programs are alternatively known as computer algebra systems or

CHAPTER 1. INTRODUCTION

4

CAS. The most well known examples are M ATHEMATICA, M APLE, M U PAD, and M ACSYMA, (see Table 1.1). These programs can find 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 Control1 group in Europe have collect together a freeware F ORTRAN subroutine library S LICOT for routines relevant in systems and control. Problem 1.1 1. Familiarise yourself with the fundamentals of M ATLAB. Run the M ATLAB demo by typing demo once inside M ATLAB. 2. Try the M ATLAB tutorial (part 1). 3. Read through the M ATLAB primer, [183] or [68], and you should get acquainted with the M ATLAB 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 people 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 Florman’s 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 expensive compared with other computers such as office or financial computers because the market is smaller, the environment harsher, the graphical requirements more critical, the duties more varied, and the potential payoffs larger. Process control has at least two main duties to perform; first 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 specifications. There is always a trade off between how much control you apply and the benefits 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 influential book challenged the balance from between commercial profits 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”. Advanced control

Optimisation

Direct search

Rule definition

Online simulation

Constraint

Steady state

dynamic methods

single variable

Regulatory

Signal condition

PID algorithm

Deadtime

multivariable

feedforward control

compensation

Basic

analogue control

Field

Valves

PLCs

Transmitters

DCS

Process computer

smart transmitters

Onstream analysers

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 field are very vague about the actual configuration of real process 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 anything 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 flavour. Thirdly many industries are deliberately vague about publishing the details of their control system since they perceive that this information could help their competitors. However some information of this type is given in [63, pp131-149] and [17]. One good

CHAPTER 1. INTRODUCTION

6

upper quality constraint violations

spt #3 loss ($)

spt #2

setpoint #1

process output

advanced control

regulatory

manual control time

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 aim to control eventually chemical plants, manufacturing processes, robots, undertake filtering 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 identification 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 filters cascaded together. The blackbox is a relatively well behaved underdamped stable system with dominant time constants 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

Input From computer D/A (connector #10)

7

Output B LACK -B OX

To computer - A/D (connector #1)

Sluggish

GND

blue

Fast

input indicator

- Earth (connector #11)

blue

Figure 1.3: Blackbox configuration. The manual switch marked will toggle between either 7 or 9 low-pass filters.

Blackbox step response

0.45 0.4 0.35

ipnut/output

0.3 0.25 0.2 0.15

input output

0.1 0.05 0 −0.05 15

20

25

30

35

40

45

50

time (s)

(a) Black-box wiring to the National Instruments (b) The response of the blackbox to 2 step inputs LabPC terminator.

Figure 1.4: The “Black-box”

is not ‘visible’ to the naked eye, and that we cannot manually introduce disturbances. One complication 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.

CHAPTER 1. INTRODUCTION

8

Step response of the balance arm 1

arm position

0.8 0.6 0.4 0.2 0 −0.2 −0.4 20

30

40

50

30

40

50

60

70

80

90

100

60 70 time ∆T=0.05 seconds

80

90

100

0.3 0.2

input

0.1 0 −0.1 −0.2 20

(a) The electromagnetic balance arm

(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 flapper in Fig. 1.6 and Fig. 1.7(b) has few dynamics, but significant low-pass filtered measurement noise. An interesting exercise is to place two flapper units in close proximity. The air from one then disturbs the flapper 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 flappers adjacent to each other, another possibility is one flapper 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 flight path.

1.4. LABORATORY EQUIPMENT FOR CONTROL TESTS

9

position transducer 

O -

Motor 6 6

angle

Flapper arm

?

6 6 power to the motor auto/man 6 6 switch

N On/Off

manual ?

Digital to Analogue

?

A/D

(Fan speed)

Figure 1.6: The flapper wiring

Step response of the flapper 0.35

output

0.3 0.25 0.2 0.15 0.1 0

5

10

15

20

25

30

35

40

45

50

5

10

15

20 25 30 time (sec) dt=0.05

35

40

45

50

0.4 input

0.3 0.2 0.1 0 −0.1 0

(a) The fan/flapper equipment

(b) Step response of the flapper

Figure 1.7: The Fan and flapper.

CHAPTER 1. INTRODUCTION

10

z

top rotor

control inputs }|

{ side rotor

plant outputs

    

azimuth



1

moveable counter weight

-

) elevation angle

support stand

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 S IMULINK simulation to have time to manually introduce step changes, add disturbances, switch from automatic to manual etc. If left alone in simulation mode, S IMULINK will run as fast as possible, but it will slow down when it needs to sub-sample the integrator around discontinuities or periods when the system is very stiff. The S IMULINK Execution Control block allows you to specify that the simulation runs at a multiple 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 ‘flying’ helicopter balanced using 2 PID controllers since it is openloop unstable and would otherwise crash. Helicopter 1.5 1

output

0.5 0 −0.5 −1 −1.5

0

10

20

30

40

50

60

70

80

90

100

0

10

20

30

40

50 Time (sec)

60

70

80

90

100

1

input

0.5

0

−0.5

−1

(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

CHAPTER 1. INTRODUCTION

12

Helicopter flight path

0.5

Up/Down

0

−0.5

−1 1.5 1 0.5 250

0 200

−0.5

150 100

−1 East/West

−1.5

50 0

time

(a) Multivariable helicopter control

(b) Model helicopter in the trees

Figure 1.10: Helicopter flying results

Scope1 Simulink Execution Control

1 s+1 Signal Generator

Transfer Fcn

Scope

Figure 1.11: Real-time Simulink simulations. A parameter in the S IMULINK E XECUTION C ON 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 flexibility 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 configuration of the computer in the loop. For the computer to respond to any outside events, the signals must first 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 computer’s processor. This device that accomplishes this conversion is called an Analogue to Digital converter or A/D. Similarly, any binary output from the pins on a processor must first be converted to an analogue signal using a Digital to Analogue converter, or D/A. In some microcontrollers, (rather than micro-processors), such as Intel’s 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 resistors, 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 problem for process control applications. Any introductory electrical engineering text such as [171] 13

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

14

Process control computer

r(t) setpoint

+ + - A/D − 6

-

computer

- D/A

-

Plant

- y(t) output

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 defined by the computer’s clock sample the continuous 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 constraints 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 212 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 M ATLAB 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 first-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 interrelationships between these quantities are     ω radians/s 1 cycles = (2.1) f= T second 2π radians/cycle

2.1. COMPUTER IN THE LOOP

15

Sampling a continuous signal 7

Analogue Sampled Sampled & quantisized

6

Signal

5 4 3 2 1 0 0

2

4 6 8 Sample time, (k∆T)

10

12

Figure 2.2: Sampling an analogue signal (heavy solid) with a three bit (8 discrete levels) A/D converter and zeroth-order hold. The sampled values, •, 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 theorem which specifies a lower limit required on the sampling rate to resolve any particular frequency unambiguously. (See §2.1.3 following.) • Any analogue filtering 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 processes, the sample time should lie somewhere between ten times the computational delay of the hardware tc and some small fraction of the process dominant time constant τ , say 10tc ≤ T ≤

τ 10

(2.2)

For most chemical engineering applications, the computational delay is negligible compared with the process time constant, (tc → 0), so we often choose T ≈ τ /10. Thus for a simple first order rise, we would expect to have about 20–30 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 from the 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

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

16

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 what’s 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 procedure 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     7 1 y1 = − sin 2π t and y2 = sin 2π t 8 8 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. Aliasing 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 y1 (solid) and y2 (dashed) just happen to coincide at t = 0, 1, 2, 3, . . . (•).

0.5 signal

1

0 −0.5 −1 0

2

4 time (s)

6

8

Consequently, at the slower sampling rate of 1 Hz, we cannot distinguish between the two different signals. This is the phenomenon known as aliasing since one of the frequencies “pretends” to be another. In conclusion, two specific 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 reasonable 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, fN . 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 (f1 = 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 (f2 = 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) = A cos(ωt) with a sample time of T , x(nT ) = A cos(ωnT ) = A cos(Ωn) where the digital frequency, Ω, is defined as def

Ω = ωT = 2πf T = 2π

f fs

then the range of analogue frequencies is 0 < f < ∞ while the range of digital frequencies is limited by the Nyquist sampling limit, fs /2 giving the allowable range for the digital frequency as 0≤Ω≤π M ATLAB unfortunately decided on a slightly different standard in the S IGNAL P ROCESSING toolbox. Instead of a range from zero to π, M ATLAB uses a range from zero to 2 where 1 corresponds to half the sampling frequency or the Nyquist frequency. See [42]. In summary:

sample time sampling frequency angular velocity digital frequency

symbol T or ∆t fs = T1 ω = 2πf Ω = ωT = 2πf fs

units s Hz rad/s –

where the allowable ranges are: 0 ≤ω < ∞, 0 ≤Ω ≤ π,

continuous sampled

and Nyquist frequency, fN , and the dimensionless Nyquist frequency, ΩN are: 1 fs = [Hz] 2 2T 2πfN =π = fs

fN = ΩN

It is practically impossible to avoid aliasing problems when sampling, using only digital filters. Almost all measured signals are corrupted by noise, and this noise has usually some high or even infinite frequency components. Thus the noise is not band limited. With this noise, no matter how fast we sample, we will always have some reflection of a higher frequency component that appears as an impostor or alias frequency.

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

18

If aliasing is still a problem, and you cannot sample at a higher rate, then you can insert a low pass analogue filter between the measurement and the analogue to digital converter (sampler). The analogue filter or in this case known as an anti-aliasing filter, will band-limit the signal, but not corrupt it with any aliasing. Expensive high fidelity audio equipment will still use analogue filters in this capacity. Analogue and digital filters 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 components of the signal. It is evident that y(t) is comprised of one or two dominating harmonics. 3 continuous Ts=0.7

output

2

Ts=1.05

1

0

Figure 2.3: Part of a noisy time series with unknown frequency components. The continuous underlying signal (solid) is sampled at T = 0.7, (•), and at T = 1.05 s (△).

−1

−2

0

1

2

3

4

5

6

7

time (s)

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 signal2 , |DF T {y(t)}|. Reading off the peak positions, and for the moment overlooking any potential 2

T = 0.7 s

10 power

s

0

10

f =0.71 N

2

T = 1.05 s

10 power

s

0

10

f =0.48 N

0

0.1

0.2

0.3

0.4 0.5 frequency (Hz)

0.6

0.7

0.8

Figure 2.4: The frequency component of a signal sampled at Ts = 0.7s (upper) and Ts = 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(2π0.1t) + sin(2π0.5t) + sin(2π0.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 fN = 1/(2Ts ) 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 reflected 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 top bottom

Ts (s) 0.7 1.05

fN (Hz) 0.7143 0.4762

peak 1 0.1 0.1

peak 2 0.50 0.152

peak 3 0.63 0.452

First we note that the low frequency peak (f1 = 0.1Hz) has not shifted from curve a (top) to curve b (bottom), so we would be reasonably confident that f1 = 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 f2 = 0.5Hz. If this is the case, then it will appear as an alias in curve b since the Nyquist frequency for curve b (fN (b) = 0.48) is less than the proposed f2 = 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) = 2fN (b) − f2 = 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 f2 . Fig. 2.5 shows this reflection.

2

Ts = 0.7 s

power

10

0

10

f =0.71 N

2

T = 1.05 s

10 power

s

0

10

f =0.48 N

0

0.1

0.2

0.3 0.4 0.5 frequency (Hz)

0.6

0.7

0.8

Figure 2.5: Reflecting the frequency response in the Nyquist frequency from Fig. 2.4 shows why one of the peaks is evident in the frequency spectrum at Ts = 1.05, but what about the other peak?

Now we turn our attention to the final peak. f3 (a) = 0.63 and f2 (b) = 0.152. Let us again try the fact that f3 (a) is the true frequency = 0.63Hz. If this were the case the apparent frequency on curve b would be fˆ3 (b) = 2fN (b) − f2 = 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 f3 (a) is the first harmonic. In that case the true frequency will be f3 = 2fN (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) = 2fN (b) − f3 = 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(2π0.1t) + sin(2π0.5t) + sin(2π0.8t) although we can never be totally sure of the validity of this model. At best we could either resample at a much higher frequency, say fs > 10Hz, or introduce an analogue low pass filter to cut out, or at least substantially reduce, any high frequencies that may be reflected.

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

20

2.2 Finite difference models To compute complex mathematical operations such as differentiation or integration, on a digital computer, we must first 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 Hawthorne’s 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 illegitimate child.

In control applications, we are often required to solve ordinary differential equations such as dy = f (t, y) dt

(2.3)

for y(t). The derivative can be approximated by the simple backward difference formula dy yt − yt−T ≈ dt T

(2.4)

where T is the step size in time or the sampling interval. Provided T is kept sufficiently 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 yt results in the famous Euler backward difference scheme; yt = yt−T + T f (t − T, yt−T )

(2.5)

Such a scheme is called a recurrence scheme since a previous solution, yt−T , is used to calculate yt , and is suitable for computer implementation. The beauty of this crude method of differentiation 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 complex, but important issue is addressed in the field of numerical analysis. Problem 2.1

1. What is the finite difference approximation for a third order derivative?

2. Write down the second order finite difference approximation to τ2

d2 y dy + 2ζτ + y = ku dt2 dt

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 differential 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 xk+1 = f (xk ) rather than resorting to integration. This step by step procedure is also known as a mathematical mapping since we map the old vector xk to a new vector xk+1 .

H´enon’s chaotic attractor The system of discrete equations known as H´enon’s attractor, xk+1 = (yk + 1) − 1.4x2k , yk+1 = 0.3xk ,

x0 = 1

(2.6)

y0 = 1

(2.7)

is an interesting example of a discrete mapping which exhibits chaotic behaviour. We will start from point x0 = (x0 , y0 ) = (1, 1) and investigate the subsequent behaviour using S IMULINK. Since H´enon’s attractor is a discrete system, we will use unit delays to shift back from xk+1 → xk and to better visualise the results we will plot an (x, y) phase plot. The S IMULINK simulation is given in Fig. 2.7. Compare this S IMULINK construction (which I have drawn deliberately to flow from right to left) so that it matches the way we read the system equations, Eqn. 2.6-Eqn. 2.7.

1.4 Gain2 x To Workspace

1/z

Product

1

x1

Sum1

y

1/z

0.3

To Workspace2

y1

Constant

XY Graph

Gain

Figure 2.7: H´enon’s attractor, (Eqns 2.6–2.7), modelled in S IMULINK. See also Fig. 2.8. The time response of x and y, (left figures in Fig. 2.8), of this mapping is not particularly interesting, but the result of the phase plot (without joining the dots), (right figure 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 S IMULINK. 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.

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

22 2

1

xk

1

Start point

0 −1 k

0.5 y

−2 1 0.5 y

k

0

0 −0.5

0

5

10

15 20 time counter

25

30

−0.5 −1.5

35

−1

−0.5

0 x

0.5

1

1.5

k

(b) The (x, y) or phase response

(a) The time response

Figure 2.8: The time response (left) and phase plot (right) of H´enon’s attractor as computed by the S IMULINK 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) =

∞ X

n=0

f (kT ) δ(t − kT )

(2.8)

where δ(x) is the Dirac delta function which is defined as being a perfect impulse at x = 0, and zero elsewhere. Note that the actual value of δ(0) is infinity, but the integral of δ(t) is 1.0. Expanding the summation term in Eqn 2.8 gives f ∗ (t) = f0 δ(t) + fT δ(t − T ) + f2T δ(t − 2T ) + f3T δ(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) = f0 δ(3) + f1 δ(2) + f2 δ(1) + f3 δ(0) + f4 δ(−1) + · · · | {z } | {z } all zero

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 (∞ ) X L {f ∗ (t)} = L fkT δ(t − kT )

(2.9)

n=0

Now the function fkT 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 simplifies to L {f ∗ (t)} = where we have defined

∞ X

fkT e−kT s =

n=0

∞ X

fk z −k

k=0

def

z = esT

(2.10)

In summary, the z-transform of the sampled function f ∗ (t) is defined as def

F (z) = Z {f ∗ (t)} =

∞ X

fk z −k

(2.11)

k=0

The function F (z) is an infinite 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 definition 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, the definition of Eqn. 2.11 is S(z) =

∞ X

k=0

k ≥ 0. The z-transform of s(kT ) following

kn z −k = 1 + 1 · z −1 + 1 · z −2 + 1 · z −3 + · · ·

(2.12)

By using the sum to infinity for a geometric series,3 we obtain the closed form equivalent for Eqn. 2.12 as 1 S(z) = (2.13) 1 − z −1 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 M ATLAB. 3 The

sum of a geometric series of n terms is a + ar + ar 2 + · · · + ar n−1 =

a (1 − r n ) ; r 6= 1 1−r

and if |r| < 1, then the sum for an infinite number of terms converges to S∞ =

a 1−r

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

24

z-transform of the ramp function using the Symbolic toolbox for M ATLAB. Z {k}

z-transform of the exponential function. n o Z e−ak 1

1

>> syms k T >> ztrans(k*T) ans = T*z/(z-1)ˆ2 6

>> syms k T a >> ztrans(exp(-a*k*T)) ans = z/exp(-a*T)/(z/exp(-a*T)-1) >> simplify(ans) 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 final value theorems given in Table 2.1. As in the continuous case, the final value theorem is only applicable if the transfer function is stable. Table 2.1: Comparing final and initial value theorems for continuous and discrete systems

Initial value, limt→0 y(t) Final value, limt→∞ y(t)

Continuous lims→∞ sY (s) lims→0 sY (s)

Discrete lim  z→∞ Y (z)   limz→1 1 − z −1 Y (z)

2.4 Inversion of z-transforms The usefulness of the z-transform is 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 final 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 inversion 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 M ATLAB use residue to compute the partial fractions. (See §2.4.2.) 3. Long division for rational polynomial expressions in the discrete domain. In M ATLAB use deconv to do the polynomial division. (See §2.4.3.) 4. Computational approach while suitable for computers, has the disadvantage that the answer 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 M U PAD. 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.

3

8

>> syms z % Define a symbolic variable z >> G = (10*z+5)/(z-1)/(z-1/4) % Construct G(z) = (10z + 5)/(z − 1)/(z − 1/4) G = (10*z+5)/(z-1)/(z-1/4) >> pretty(G) % check it 10 z + 5 ----------------(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 piecewise functions in M ATLAB. 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 defined as positive. We can explicitly inform M ATLAB 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

9

>> y=iztrans(G) y = 20-40*(1/4)ˆn >> limit(y,n,inf) ans = 20

% Invert to get,y[n] = Z −1 {G(z)} % y[∞]

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 continuous Laplace transforms. In both cases, we find 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 M ATLAB function residue forms partial fractions from a continuous transfer function, although the help file 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 z−transforms. As an example, suppose we wish to invert G(s) =

−4s2 − 58s − 24 −4s2 − 58s − 24 = 3 2 s + 2s − 24s 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) =

A B C −4s2 − 58s − 24 = + + s(s + 6)(s − 4) s s+6 s−4

where the coefficients A, B and C can be found either by equating the coefficients or using the ‘cover-up’ rule shown below. −4s2 − 58s − 24 −4s2 − 58s − 24 = 1, B = =3 A= (s + 6)(s − 4) s=0 s(s − 4) s=−6 −4s2 − 58s − 24 C= = −8 s(s + 6) s=4

In M ATLAB we can use the residue command to extract the partial fractions.

5

10

>> B = [-4 -58 -24]; >> A = [ 1 2 -24 0]; >> [r,p,k] = residue(B,A) r = 3 -8 1 p = -6 4 0 k = []

% Numerator of G(s) = (−4s2 − 58s − 24)/(s(s + 6)(s − 4)) % Denominator of G(s) % Find partial fractions % residues (top line)

% factors or poles

% No extra parts

The order of the residue and pole coefficient produced by residue is the same for each, so the partial fraction decomposition is again G(s) =

3 −8 1 −4s2 − 58s − 24 = + + s3 − 2s − 24s s+6 s−4 s

2.4. INVERSION OF Z -TRANSFORMS

27

and we can invert each term individually perhaps using tables to obtain the time domain solution g(t) = 3e−6t − 8e4t + 1 If the rational polynomial has repeated roots or complex poles, slight modifications to the procedure are necessary so you may need to consult the help file.

Special cases for z-transforms We can invert z-transforms in a manner similar to Laplace, but if you consult a table of ztransforms 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 first 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 find x(t).

Symbolic partial fractions in M ATLAB Suppose we want to invert 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 first integrating, then differentiating the polynomial. This round-about way works because M ATLAB integrates 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. G(z) =

2

7

12

>> syms z >> G = 10*z/(zˆ2 + 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) G = 5z 5z − z+3 5*z/(z+1)-5*z/(z+3) % Gives us G(z)/z = z+1 >> syms n positive; iztrans(G,z,n) ans = -5*(-3)ˆn+5*(-1)ˆn

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

28

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) = c0 + c1 z −1 + c2 z −2 + c3 z −3 + · · · The inverse of this transform is trivial since the time solution at sample number k or t = kT is simply the coefficient of the term z −k . Consequently it follows that f (0) = c0 , f (T ) = c1 , f (2T ) = c2 , . . . , f (kT ) = ck etc. Thus if we have a rational transfer function, all we must do is to synthetically divide out the two polynomials to obtain a single, albeit possibly infinite, polynomial in z. Ogata refers to this approach as “direct division” [148, p69]. In general the division will result in an infinite 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 infinite) power series by dividing the denominator into the numerator using long division or deconv. 2. The coefficients 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 capabilities of M ATLAB’s 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 “infinite” series by padding the numerator with zeros. To invert Y (z) =

z2 + z z2 + z = 3 2 (z − 1)(z − 1.1z + 1) z − 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. z7 + z6 2 = z 4 + 3.1z 3 + 4.41z{z + 3.751z + 1.7161} + remainder z 3 − 2.1z 2 + 2.1z − 1 | Q

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.

3

>> 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) >> [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

5

Output

4 3 2 1 0 0

1

2

3 sample #

4

5

6

Figure 2.9: Inverting z-transforms using dimpulse for the first 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 dimpulse for six samples as shown in Fig. 2.9. Problem 2.2

1. The pulse transfer function of a process is given by 4(z + 0.3) Y (z) = 2 X(z) z − 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 M ATLAB 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) 10z + 5 10z + 5 10z −1 + 5z −2 = = 2 = U (z) (z − 1)(z − 0.25) z − 1.25z + 0.25 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 xk = 1.25xk−1 − 0.25xk−2 + 10uk−1 + 5uk−2

(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 definition. We now have enough information to compute x(0). x0 = 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 x0 and find the next term. x1 = 1.25x0 − 0.25x−1 + 10u0 + 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, x2 = 1.25x1 − 0.25x0 + 10u1 + 5u0

= 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 first 5 samples and the final value are calculated. The final value is as calculated using the symbolic manipulator earlier on page 25. time (kT ) 0 1 2 3 4 .. .

u(k) 1 0 0 0 0 .. .



0

x(k) 0 10 17.5 19.375 19.8438 .. . 20

M ATLAB 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) =

b0 + b1 z −1 + b2 z −2 1 + a1 z −1 + a2 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

3

8

>> 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 ) >> u = [1, zeros(1,5)] % impulse input u = 1 0 0 0 0 0 >> x = filter(b,a,u) % compute output x = 10.0000 17.5000 19.3750 19.8438

which gives the same results as Table 2.2.

19.9609

19.9902

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 M ATLAB that it is a discrete system. 1

6

>> 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 ------------------zˆ2 - 1.25 z + 0.25 Sampling time: 1

11

16

>> y=impulse(sysd) % compute the impulse response y = 0 10.0000 17.5000 19.3750 19.8438 19.9609

Finally, the contour integral method can also be used to invert z-transforms, [148, §3–3], but Seborg et al maintains it is seldom used in engineering practice, [179, p571] because it is fraught with numerical implementation difficulties. These difficulties 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 important 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 Z σ+j∞ 1 f (t) = F (s) est ds (2.17) 2πj σ−j∞ 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 Mellin’s 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 examples 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 3 1 − e−5t ←→ f (t) = s(s + 5) 5

with a corresponding simple time solution. We can start by defining 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)est

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 infinite integration interval by reasonably large numbers. It is convenient that the M ATLAB routine integral works directly in the complex domain.

3

c = 0.1; % Value σ > than any singularities of F (s) a = c-100j; b = c+200j; % Contour path approx: σ − j∞ to σ + j∞ 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 component, 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 finite 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/ s2 + 1 using the Gaver-Stehfest approximation 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 numerical 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 transform pairs in Table 2.3. The first two are standard, those following are more unusual. A more challenging collection of test transforms is given in [1]. n o The numerical solution to L−1 √1s e−1/s is compared with the analytical solution from Table 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.7

2

0.6

1.5

L−1

0.5 1

n

√ 1 s 2 +1

o

f(t)

f(t)

0.4 0.5

0.3 0 0.2

L 0.1

−1

n

o

3 s(s+5)

−0.5 −1 2 error

error

0 0.02 0 −0.02

0

2

(a) Inverting o a n 3 L−1 s(s+5)

4 t

benign

6

transfer

8

function,

1 0 −1

0

5

10 t

15

20

(b) Inverting  a challenging transfer function, L−1 √ 1 s2 +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 recommended. No. of terms = 8 1 0.5 0 −0.5

0

2

4 6 8 No. of terms = 16

10

0

2

4 6 8 No. of terms = 20

10

0

2

4 6 8 No. of terms = 26

10

1 0.5 0 −0.5

1 0.5 0 −0.5

1 0 −1

0

2

4

6 t

8

10

Figure 2.11: Demonstrating the precision problems when numerically inverting the Laplace transform using 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 –◦–.

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

34

Table 2.3: A collection of Laplace transform pairs suitable for testing numerical inversion strategies.

Description Easy test Control TF Oscillatory Nasty

F (s) 1/s

f (t)

2

1 (s + 2)(s + 3) 1 √ 2 s +1 1 −1/s √ e s

Comment

t 1 2

e−t − e−3t J0 (t)

√1 πt



Bessel function, see Fig. 2.10(b) & Fig. 2.11.

√ cos( 4t),

See Fig. 2.12.

1.5

f(t)

1

L−1

0.5

n

exp(−1/s) √ s

o

0

0 −0.5 10

−2

error

10

−4

10

Figure 2.12: Testing the numerical inver√ sion of the Laplace transform e−1/s / s using the invlap routine.

−6

10

0

5

10

15

20 time

25

30

35

40

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 difficult to choose suitable algorithmic tuning constants, which mean that it is difficult 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 sampler 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 undefined for the time between the sampling instants which is inconvenient 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

f ∗ (t)



f (t)

ideal sampler

6

6

35

- Hold

- fh (t)

6

6

6

6

666

-

-

analogue signal

sample & held signal

sampled signal

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 justified even given the improved accuracy. We can find 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, output 6 Rectangular pulse 

y(t)



- time, t 0 sample time, T

Directly applying the definition of the Laplace transform, L{zoh} =

Z



y(t) e−st dt = yt

0

Z

T

0

1 − e−sT = yt × s } | {z

1 × e−st dt

zoh

we obtain the transform for the zeroth-order hold. In summary, the transformation of a continuous plant G(s) with zero-order hold is G(z) = (1 − z −1 ) Z



G(s) s



Note that this is not the same as simply the z-transform of G(s).

(2.18)

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 tables, or we can trust it to M ATLAB. First we try analytically and apply Eqn 2.18 to the continuous process. The difficult bit is the z-transformation. We note that     8 3 G(s) = Z (2.20) Z s 3 s(s + 3) 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) a s(s+a)

X(z) (1−e−aT )z −1 (1−z −1 )(1−e−aT z −1 )

Inverting using the tables, and substituting in Eqn 2.18 gives     8 G(s) 3 −1 −1 G(z) = (1 − z ) · = (1 − z ) · Z s 3 s(s + 3) (1 − e−3T )z −1 8 (1 − z −1 ) · 3 (1 − z −1 )(1 − e−3T z −1 ) 8 (1 − e−0.3 )z −1 = · 3 (1 − e−0.3 z −1 ) 0.6912z −1 = , for T = 0.1 1 − 0.7408z −1

=

(2.21)

We can repeat this conversion numerically using the continuous-to-discrete function, c2d. We first define 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 system Gc (s) = 8/(s + 3)

3

Transfer function: 8 ----s + 3

8

>> sysd = c2d(sysc,0.1,'zoh') % convert to discrete using a zoh

13

Transfer function: 0.6912 ---------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 S IMULINK, 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 controller which we wish to discretise. In these circumstances we would like to convert from a continuous transfer function in s, (such as say a Butterworth filter) to an equivalent discrete transfer function in z. The two common ways to do this are: 1. Analytically by first inverting the Laplace transform back to the time domain, and then take the (forward) z-transform.  def G(z) = 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 M ATLAB 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-transform expression 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

5

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)); return

Listing 2.2: Symbolic Laplace to z-transform conversion with ZOH

5

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)); return

We can test the conversion routines in Listings 2.1 and 2.2 on the trial transfer function G(s) = 1/s2 .

5

10

>> Gz =lap2ztran(1/sˆ2); % Convert G(s) = 1/s2 to the discrete domain G(z). >> pretty(Gz) T z -------2 (z - 1) >> Gz = lap2ztranzoh(1/sˆ2);% Do the conversion again, but this time include a ZOH. >> pretty(Gz) 2

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

38

(z + 1) T 1/2 ---------2 (z - 1)

2.5.2 The bilinear transform The analytical ‘one step back–one step forward’ procedure while strictly correct, is a little tedious, so a simpler, albeit approximate, way to transform between the Laplace domain and the z-domain is to use the bilinear transform method, sometimes known as Tustin’s method. By definition def

z = esT or z −1 = e−sT , (from Eqn. 2.10). If we substituted directly natural logs would appear in the rational polynomial in z, ln(z) (2.23) s= T making the subsequent analysis difficult. 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 exponential term as 2 − sT (2.24) e−sT = z −1 ≈ 2 + sT or alternatively 2 (1 − z −1 ) T (1 + z −1 )

s≈

(2.25)

This allows us to transform a continuous time transfer function G(s) to a discrete time transfer function G(z), (2.26) G(z) = G(s)|s= 2 1−z−1 T 1+z −1

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 filter will be stable in the discrete 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. 1 G(z) = (s + 1)(s + 2) s= 2 1−z−1 T 1+z −1

=  =

2 1−z −1 T 1+z −1

+1

1 

2 1−z −1 T 1+z −1

+2

0.0022z 2 + 0.0043z + 0.0022 z 2 − 1.723z + 0.74

=

T 2 (z + 1)2 1 2 (2T 2 + 6T + 4)z 2 + (4T 2 − 8)z + 2T 2 − 6T + 4

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 M ATLAB. 1

6

>> 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*Tˆ2*(z+1)ˆ2/(2*z-2+T*z+T)/(z-1+T*z+T) >> pretty(Gd) 2 2 T (z + 1) 1/2 ------------------------------------(2 z - 2 + T z + T) (z - 1 + T z + T)

Alternatively we could use M ATLAB to numerically verify our symbolic solution.

5

>> G = zpk([],[-1 -2],1) Zero/pole/gain: 1 ----------(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)

20

Transfer function: 0.002165 zˆ2 + 0.004329 z + 0.002165 -----------------------------------zˆ2 - 1.723 z + 0.7403 Sampling time: 0.1

The bilinear command in the S IGNAL P ROCESSING toolbox automatically performs this mapping from s to z. This is used for example in the design of discrete versions of common analogue filters such as the Butterworth or Chebyshev filters. These are further described in §5.2.3.

Problem 2.3 1. Use Tustin’s 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.

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

40

The frequency response characteristics of a hold element The zeroth order hold element modifies the transfer function, so consequently influences the closed loop stability, and frequency characteristics of the discrete process. We can investigate this influence 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 Gp (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 2–1, p49 #8 in DCS. (1 − e−aT )z −1 (1 − z −1 )(1 − e−aT z −1 ) 1.243z = (z − 1)(z − 0.208)

Gp (z) = 1.57

(2.28) (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 Gh0 Gp (z) =

1.2215z + 0.7306 (z − 1)(z − 0.208)

(2.30)

Now we can plot the discrete frequency responses using M ATLAB to duplicate the figure given in [110, p649] as shown in Fig. 2.14. In the listing below, I first construct the symbolic discrete transfer function, substitute the sampling 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.

2

7

syms s T z 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 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 fN = 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.

Bode Diagram

Magnitude (dB)

100

50

0

−50

Phase (deg)

−100 −90 Continuous No ZOH with ZOH

−135

−180

−225 −2

10

−1

10

0

10 Frequency (rad/sec)

1

10

2

10

Figure 2.14: The Bode diagram showing the difference between the continuous plant, a discretisation with and without the zeroth-order hold.

Of course we should compare the discrete Bode diagrams with that for the original continuous process. The M ATLAB bode function is in this instance the right tool for the job, but I will construct 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.

2

7

num = 1.57; % Plant of interest G(s) = 1.57/(s2 + s + 0) den = [1 1 0]; w = logspace(-2,1)'; % Select frequency range of interest 10−2 < ω < 101 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. 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.

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

42

5

AR

10

0

10

−5

10

−2

Figure 2.15: A frequency response plot of G(s) where s = jω constructed manually without using the bode command.

Phase lag φ [deg]

10

−1

10

0

10

1

10

−50 −100 −150 −200 −2 10

−1

0

10 10 frequency ω [rad/s]

1

10

2.6 Discrete root locus diagrams The root locus diagram is a classical technique used to study the characteristic response of transfer 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 M ATLAB 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 Kc , but unstable for a gain above some critical value Ku . 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 Kc . Given a process transfer function G and a controller Kc Q, the closed loop transfer function is the familiar Kc Q(z)G(z) Gcl = (2.31) 1 + Kc Q(z)G(z) where the stability is dependent on the denominator (characteristic equation) 1 + Kc Q(z)G(z), which is of course itself dependent on the controller gain Kc . Plotting the roots of 1 + Kc Q(z)G(z) = 0

(2.32)

as a function of Kc creates the root locus diagram. In this section4 we will plot the discrete root locus diagram for the process Gp (z) =

0.5(z + 0.6) z 2 (z − 0.4)

(2.33)

which is a discrete description of a first order process with dead time. We also add a discrete integral controller of the form z Gc (z) = Kc 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 Kc 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

8

Gol = Q*G; zgrid('new'); xlim([-1.5 1.5]); axis equal rlocus(Gol) rlocfind(Gol)

% open loop % % plot root locus

Once the plot such as Fig. 2.16 is on the screen, I can use rlocfind interactively to establish the values of Kc at different critical points in Fig. 2.16. Note that the values obtained are approximate.

Pole description border-line stability cross the ζ = 0.5 line critically damped overdamped, ωn = 36◦

Name ultimate gain design gain breakaway gain

≈ Kc 0.6 0.2 0.097 0.09

Once I select the gain that corresponds to the ζ = 0.5 crossing, I can simulate the closed loop step response.

2

Gol.Ts = 1; % Set sampling time 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 Kc = 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, finite 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. Classical single-input/single-output (SISO) controller design techniques such as transfer functions, frequency analysis or root locus were found to be deficient, and with the accompanying development 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.

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

44

Root Locus

1.5

1

0.1 0.3π/T 0.2 0.3 0.4 0.2π/T 0.5 0.6 0.7 0.1π/T 0.8 0.9

0.7π/T 0.8π/T

Imaginary Axis

0.5

0.9π/T 0

Ultimate gain

0.5π/T 0.6π/T 0.4π/T

Design gain

π/T π/T 0.1π/T

0.9π/T −0.5

0.8π/T

0.2π/T

breakaway gain

0.3π/T

0.7π/T 0.6π/T 0.4π/T 0.5π/T

−1

−1.5

−1.5

−1

−0.5

0

0.5

1

1.5

Real Axis

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. 2

1 K =0.1 c

0 2 1 K =0.2 c

0 2

Figure 2.17: Various discrete closed loop responses for gains Kc = 0.6, 0.2 and 0.1. Note that 1 with Kc = 0.6 we observe a response on the stability boundary, while for Kc = 0.1 we observe 0 a critically damped response as anticipated from 0 the root locus diagram given in Fig. 2.16.

K =0.6 c

10

20 30 time [s]

40

50

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 flow and composition and reflux and boil-up rates, and at least four outputs, the product flow and compositions. To control such an interacting system, multivariable 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 process orientated multivariable models.

Feed composition ( Disturbances Feed rate reflux(rate Manpipulated variables

- distillation composition, xD - distillate rate, D Distillation column

-

- tray 5 temperature, T5 - tray 15 temperature, T15 - Bottoms rate, B - Bottoms comp., xB

reboiler heat

Inputs

Outputs

Figure 2.18: A binary distillation column with multiple inputs and multiple outputs

State space analysis only considers first order differential equations. To model higher order systems, one needs only to build systems of first order equations. These equations are conveniently collected, if linear, in one large matrix. The advantage of this approach is a compact representation, 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 control 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 differential 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 convenient and numerically more robust to manipulate these equations when using programs such as M ATLAB. 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 variables. 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 variables that may change, but are outside the engineer’s immediate sphere of influence (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 simplifies to x˙ = Ax + Bu

(2.37)

or in discrete form at time t = kT xk+1 = Φxk + ∆uk

(2.38) n

where the state vector x is an (n × 1) vector, or alternatively written as x ∈ ℜ , the control input vector has m elements, or u ∈ ℜm . The model (transition) matrix is (n × n) or A, Φ ∈ ℜn×n , and the control or input matrix is (n × m) or B, ∆ ∈ ℜn×m . 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 S IMULINK for example.

2.7. MULTIVARIABLE CONTROL AND STATE SPACE ANALYSIS

u(t)

- B

-+ 6 

x˙ R -

x(t)

-

uk

- ∆

47

-+ 6

A 



xk - z −1

xk+1

Φ 

Discrete plant

Continuous plant

Figure 2.19: A block diagram of a state-space dynamic system, (a) continuous system: x˙ = Ax + Bu, and (b) discrete system: xk+1 = Φxk + ∆uk . (See also Fig. 2.20.) The output or measurement vector, y, are the variables that are directly measured from the operating 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 ∈ ℜr×n . 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 first order differential equations known as Cauchy form. Given a general linear nth order differential equation y (n) + a1 y (n−1) + a2 y (n−2) + · · · + an−1 y˙ + an y = b0 u(n) + b1 u(n−1) + · · · + bn−1 u˙ + bn u (2.42)

-

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

48

- D

-- B

u(t)

-+ 6

x(t)

x˙ R -



? -+

- C

- y(t)

A 

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 b0 sn + b1 sn−1 + · · · + bn−1 s + bn Y (s) = n U (s) s + a1 sn−1 + · · · + an−1 s + an 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 0 1 0  x˙ 2   0 0 1     ..   .. .. ..  . = . . .     x˙ n−1   0 0 0 x˙ n −a0 −a1 −a2 y=

h

b n − an b 0

.. .

··· ··· .. .



0 0 .. .

     

··· 1 · · · −an−1

bn−1 − an−1 b0

.. .

x1 x2 .. .

      xn−1 xn





0 0 .. .

      +     0 1



   u   

(2.44)

x1 x2 .. .

 i  . · · · .. b1 − a1 b0    xn−1 xn



    + b0 u  

(2.45)

which is useful when designing pole-placement controllers. The observable canonical form is        x˙ 1 0 0 ··· 0 −an x1 b n − an b 0  x˙ 2   1 0 · · · 0 −an−1   x2   bn−1 − an−1 b0         (2.46)  ..  =  .. . .   ..  +  u .. .. .. ..  .   .      . . . . . . x˙ n

0

y=



0 0

0

··· 1

−a1 

x1  x2   · · · 0 1  ...   xn−1 xn

and is useful when designing observers.

xn



    + b0 u  

b 1 − a1 b 0

(2.47)

2.7. MULTIVARIABLE CONTROL AND STATE SPACE ANALYSIS

49

If the transfer function defined by Eqn. 2.43 has real and distinct factors, Y (s) b0 sn + b1 sn−1 + · · · + bn−1 s + bn = U (s) (s + p1 )(s + p2 ) · · · (s + pn ) c2 cn c1 + + ···+ = b0 + s + p1 s + p2 s + pn we can derive an especially elegant state-space form     

x˙ 1 x˙ 2 .. . x˙ n





    =   y=



−p1

0 −p2

..

.

0

c1

c2

· · · cn

    

−pn  x1   x2  ..  .

xn

   



x1 x2 .. . xn





    +  

1 1 .. . 1



  u 

   + b0 u 

(2.48)

(2.49)

that is purely diagonal. As evident from the diagonal system matrix, this system is totally decoupled 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 M ATLAB canon command. >> G = tf([5 6],[1 2 3 4]); % Define transfer function G = (5s2 + 6s)/(s3 + 2s2 + 3s + 4) 2

>> canon(ss(G),'compan') % Convert TF to the companion or observable canonical form a = 7

x1 x2 x3

x1 0 1 0

x1 x2 x3

u1 1 0 0

y1

x1 0

y1

u1 0

x2 0 0 1

x3 -4 -3 -2

x2 5

x3 -4

b = 12

17

c =

d = 22

These transformations are discussed further in [148, p515]. M ATLAB 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 convert 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 u(s) {z } | Gp (s)

(2.51)

where Gp (s) is a matrix of expressions in s and is referred to as the transfer function matrix. The M ATLAB 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.     −7 10 4 −1 x˙ = x+ u (2.52) −3 4 2 −3 From Eqn. 2.51, the transfer function matrix is defined as −1

Gp (s) = (sI − A) B     −1  1 0 −7 10 4 = s − 0 1 −3 4 2  −1   (s + 7) −10 4 −1 = 3 (s − 4) 2 −3

−1 −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.    1 s − 4 −10 4 −1 Gp (s) = −3 s + 7 2 −3 (s + 2)(s + 1)   s + 26 4 − 2  s+2 s + 3s + 2    = 2 3(6 + s)  − 2 s+2 s + 3s + 2 We can directly apply Eqn. 2.51 using the symbolic toolbox in M ATLAB.

2

>> syms s >> 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+sˆ2+3*s)] [ 2/(s+2), -3*(s+6)/(2+sˆ2+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 inversion required. However [174, p35] describes a method due to Faddeeva that is suitable for numerical computation in M ATLAB. Faddeeva’s algorithm to convert a state-space description, x˙ = Ax + Bu into transfer function form, Gp (s).

1. Compute a, the characteristic equation of the n × n matrix A. (Use poly in M ATLAB.) 2. Set En−1 = I. 3. Compute recursively the following n − 1 matrices k = 1, 2, · · · , n − 1

En−1−k = AEn−k + an−k I, 4. The transfer function matrix is then given by Gp (s) =

sn−1 En−1 + sn−2 En−2 + · · · + E0 B an sn + an−1 sn−1 + · · · + a1 s + a0

(2.54)

Expressed in M ATLAB notation, an (incomplete) version of the algorithm is

4

a = n = I = for

poly(A); % characteristic polynomial length(a); % dimension of system eye(n-1); E=I; 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 M ATLAB (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 Faddeeva’s algorithm.       −7 10 4 −1 x˙ 1 = x+ u −3 4 x˙ 2 2 −3 We start by computing the characteristic polynomial of A a(s) = s2 + 3s + 2 = (s + 1)(s + 2) and with n = 2 we can compute E1 =



1 0

0 1



,

E0 =



5 −1 2 2



Following Eqn. 2.54 gives a matrix of polynomials in s,      1 1 0 −4 10 −1 (sI − A) = 2 s + 0 1 −3 7 s + 3s + 2   1 s−4 10 = s+7 (s + 1)(s + 2) −3

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

52

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 B to obtain the pulse transfer function matrix. Finally, we can also use the control toolbox for the conversion from state-space to transfer function form. First we construct the state-space form, A = [-7 10; -3,4]; B = [4 -1; 2 -3]; C = eye(size(A)); sys = ss(A,B,C,[])

% Continuous state-space example from Eqn. 2.52. % construct system object

where in this case if leave out the D matrix, M ATLAB 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:

12

2 ----s + 2

Transfer function from input 2 to output... -s - 26 #1: ------------sˆ2 + 3 s + 2

17

#2:

-3 s - 18 ------------sˆ2 + 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 M ATLAB 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) =

s2 + 7s + 12 (s + 3)(s + 4) = 3 (s + 1)(s + 2)(s + 5) s + 8s + 17s + 10

we can convert to state-space form using tf2ss. 1

>>num = [1 7 12]; % Numerator: s2 + 7s + 12 >>den = [1 8 17 10]; % Denominator: s3 + 8s + 17s + 10 >>[A,B,C,D] = tf2ss(num,den) % convert to state-space

2.7. MULTIVARIABLE CONTROL AND STATE SPACE ANALYSIS which returns the following four matrices   −8 −17 −10 0 0 , A= 1 0 1 0   C = 1 7 12 ,

53



 1 B= 0  0

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 C ONTROL T OOLBOX will return a slightly different ABCD package

2

7

12

17

>> Gc = tf([1 7 12],[1 8 17 10]) % Transfer function in polynomial form Transfer function: sˆ2 + 7 s + 12 ----------------------sˆ3 + 8 sˆ2 + 17 s + 10 >>[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 B = 2 0 0 C = 0.5000 0.8750 0.7500 D = 0

Alternatively we could start with zero-pole-gain form and obtain yet another equivalent statespace 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=

n

# of inputs m - -

A (n × n)

B (n × m)

C (p × n)

D (p × m)

6 n ? 6p ?

# of states

# of measurements

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 first 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) = ATz + Bu dt 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, p513–514]. 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 find 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) % find 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 specified 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 specified 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, §6–4 p646 ]. The M ATLAB function canon can convert state-space models to diagonal or observable canonical form (sometimes known as the companion form). Note however the help file for this routine discourages the use of the companion form due to its numerical illconditioning. M ATLAB comes with some utility functions to generate test models such as ord2 which generates stable second order models of a specified damping and natural frequency, and rmodel is a flexible 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 dynamic 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 + zi ) (2.58) Πj (s + pi ) where once again the poles, pj , and zeros zi are immediately apparent. This is the form that M ATLAB uses in the zeros-pole-gain format, zpk. Finally the hardware engineer would prefer to operate in the expanded polynomial form, (particularly in discrete cases), where the transfer function is of the form bm sm + bm−1 sm−1 + · · · + b0 sn + an−1 sn−1 + · · · + a0

(2.59)

This is the form that M ATLAB uses in the transfer-function format, tf. Note that the leading coefficient in the denominator is set to 1. As a M ATLAB user, you can define a transfer function that does not follow this convention, but M ATLAB will quietly convert to this normalised form if you type something like G = tf(zpk(G)). The inter-conversions between the forms is not difficult; 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) −1.5 (s − 0.3333)(s + 0.1) −60s2 + 14s + 2 = = (20s + 1)(2s + 1)(s + 1) (s + 1)(s + 0.5)(s + 0.05) 40s3 + 62s2 + 23s + 1 {z } | {z } | {z } | time constant

zero-pole-gain

expanded polynomial

It is trivial to interconvert between the zero-pole-gain, Eqn. 2.58, and the transfer function formats, Eqn. 2.59, in M ATLAB, but it is less easy to convert to the time constant description. Listing 2.3 extracts from an arbitrary transfer function form the time constants, τ , the numerator time constants, α, and the plant gain K.

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

56

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/(τj s + 1) ntau = sort(-1./z,'descend'); % Convert to numerator time constants, (αi s + 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, xss , 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 (xss , u)

(2.60)

If the system is linear, x˙ = Ax+ Bu, then the steady state can be evaluated algebraically in closed form xss = −A−1 Bu

(2.61)

Consequently to solve for the steady-state one could invert the model matrix A but which may be illconditioned or computationally time consuming. Using M ATLAB one should use xss = -A\B*u. If A has no inverse, then no (or alternatively infinite) steady states exist. An example of a process that has no steady state could be a tank-flow system that has a pump withdrawing fluid from the outlet at a constant rate independent of liquid height say just exactly balancing an input flow shown in the left hand schematic in Fig. 2.21. If the input flow suddenly increased, then the level will rise until the tank eventually overflows. 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 overflow 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 d2 y dy +7 + 12y = 3u 2 dt dt 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

flow in

?

?

6 h

6 h

?

? - flow = constant

- flow = f(height)

constant flow pump

restriction

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

1 3 · s s2 + 7s + 12

The final value theorem is only applicable if the system is stable. To check, we require that the roots of the denominator, s2 + 7s + 12, lie in the left hand plane, √ −6 ± 72 − 4 × 12 = −4 and − 3 s= 2 Given that both roots have negative real parts, we have verified that our system is stable and we are allowed to apply the final value theorem to solve for the steady-state, y(∞), lim y(t) = lim sY (s) = lim

t→∞

s→0

s→0

3 3 = = 0.25 s2 + 7s + 12 12

Using the state space approach to replicate the above, we first cast the second order differential equation into two first order differential equations using the controllable canonical form given in Eqn. 2.45. Let z1 = y and z2 = dy dt , then     0 1 0 z˙ = z+ u −12 −7 3 and the steady state is now zss = −A−1 Bu = −



−7/12 −1/12 1 0



0 3



1=



0.25 0



Noting that z1 = y, we see that the steady state is also at 0.25. Furthermore, the derivative term (z2 ) 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 find two terms, sX(s) − x0 = aX(s) + bU (s) b x0 + U (s) X(s) = s−a s−a

(2.62)

One of these terms is the response of the system owing to the initial condition, x0 eat , 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 equation. 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) = x0

(2.63)

Taking Laplace transforms, and not forgetting the initial conditions, we have sx(s) − x0 = A x(s) x(s) (sI − A) = x0 (s)

x(s) = (sI − A)

−1

x0

Finally inverting the Laplace transform back to the time domain gives n o −1 x(t) = L−1 (sI − A) x0

(2.64)

Alternatively we can solve Eqn. 2.63 by separating the variables and integrating obtaining x(t) = eAt x0

(2.65)

where the exponent of a matrix, eAt , 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 x0 to some point in the future, xt . We will give it the symbol Φ(t). The matrix exponential is defined just as in the scalar case as a Taylor series expansion, eAt or Φ(t) = I + At + def

=

∞ X Ak tk

k=0

k!

A2 t2 A3 t3 + + ··· 2! 3! (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. o n Comparing Eqn. 2.64 with Eqn. 2.65 we can see that the matrix eAt = L−1 (sI − A)−1 .

So to compute the solution, x(t), we need to know the initial condition and a strategy to numerically 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 x0 +

Z

t

Φt−τ Buτ dτ

(2.67)

0

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 continuous time differential equation can be converted to a discrete time differential equation that is suitable for computer control implementation provided the sampling rate is fixed, and the input 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 xk+1 = Φxk + ∆uk

(2.68)

where xk is the state vector x at time t = kT where T is the sample period. Once the sample period is fixed, 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 xk at time t = kT , we desire the state vector at the next sample time, xk+1 , or Z (k+1)T A T A (k+1)T xk+1 = e xk + e e−Aτ Buτ dt (2.69) kT

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 simplifies to xk+1

= eAT xk +

Z

T

eAλ Buk dλ

(2.70)

0

where λ = T − t. For convenience, we can define two new matrices as def Φ = eAT ! Z T def ∆= eAλ dλ B

(2.71) (2.72)

0

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 A is non-singular, then   ∆ = eAT − 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/s2 , can be represented in continuous state space using two states as     0 0 1 x˙ = x+ u (2.74) 1 0 0   y= 0 1 x (2.75) At sample time T , the state transition matrix is from Eqn. 2.71,    0 0 1 A T Φ=e = exp = T 0 T

0 1



and the control matrix is given by Eqn. 2.72 ! Z T ∆= eAλ dλ B 0

=

Z

T

0



T =  T2 2



 !  1 0 1 dλ λ 1 0    T 0  1   =  T2  0 T 2

For small problems such as this, the symbolic toolbox helps do the computation.

5

10

>> A = [0 0; 1 0]; B = [1; 0]; >> syms T lambda % Symbolic sample time T and λ >> Phi = expm(A*T) % Φ(T ) Phi = [ 1, 0] [ T, 1] >> Delta = int(expm(A*lambda),lambda,0,T)*B % ∆(T ) Delta = [ T] [ 1/2*Tˆ2]

Symbolic example with invertible A matrix. We can discretise the continuous state-space system     −1.5 −0.5 1 x˙ = x+ u 1 0 0 analytically at a sample time T by computing matrix exponentials symbolically. >> A = [-3/2, -1/2; 1, 0]; B = [1;0];

5

>> syms T >> Phi = expm(A*T) Phi = [ -exp(-1/2*T)+2*exp(-T), [ -2*exp(-T)+2*exp(-1/2*T),

exp(-T)-exp(-1/2*T)] 2*exp(-1/2*T)-exp(-T)]

2.8. SOLVING THE VECTOR DIFFERENTIAL EQUATION

61

Since A is invertible in this example, we can use the simpler Eqn. 2.73

3

8

  >> Delta = (Phi - eye(2))*A\B % ∆ = eAT − I A−1 B Delta = [ 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)] [ -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 first compute Z T A2 T 3 Ak−1 T k AT 2 + + ···+ + ··· Ψ= eAτ dτ = IT + 2! 3! k! 0 then

Φ = I + AΨ and ∆ = ΨB

(2.76)

A better approach, at least when using M ATLAB, follows from Eqn. 2.71 and Eqn. 2.72 where dΦ = ΦA = AΦ dt d∆ = ΦB dt These two equations can be concatenated to give    d Φ ∆ Φ = 0 dt 0 I

(2.77) (2.78)



 A B (2.79) 0 0 R R which is in the same form as da/dt = ab. Rearranging this to da/a = b dt leads to the analytical solution      Φ ∆ A B = exp T (2.80) 0 I 0 0 ∆ I

enabling us to extract the required Φ and ∆ matrices provided we can reliably compute the exponential of a matrix. The M ATLAB C ONTROL T OOLBOX 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.

2

>> A = [-3/2, -1/2; 1, 0]; B = [1;0]; >> syms T

62

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

>> [n,m] = size(B);

% extract dimensions

˜ = >> Aa = [A,B;zeros(m,n+m)] % Augmented A matrix, A 7

12

17

22



A 0

B 0



Aa = -1.5 -0.5 1.0 1.0 0.0 0.0 0.0 0.0 0.0 ˜ = exp(AT ˜ ) >> Phi_a = expm(Aa*T) compute exponential, Φ Phi_a = [ -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 = [ -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)] [ 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, pp526–533], and a paper by Cleve Moler (one of the original M ATLAB authors) and Charles Van Loan is titled Nineteen dubious ways to compute the exponential of a matrix5 , and contrasts methods involving approximation theory, differential equations, matrix eigenvalues and others. Of these 19 methods, two found their way into M ATLAB, namely expm, which is the recommended default strategy, and expm1 intended to compute ex − 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    λ  λ1 0 0 e1 0 0 D =  0 λ2 0  , then the matrix exponential is exp (D) =  0 eλ2 0  0 0 λ3 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 find 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   1 1 A= ǫ 1 5 SIAM Review, vol. 20, A 1978, pp802–836 and reprinted in [157, pp649–680]. In fact 25 years later, an update was published with some recent developments.

2.8. SOLVING THE VECTOR DIFFERENTIAL EQUATION with ǫ = 0 has a Jordan form of



1 0

1 1

63



but for ǫ 6= 0, then the Jordan form drastically changes to the diagonal matrix   √ 0√ 1+ ǫ 0 1− ǫ In summary, for serious numerical calculation we should use the matrix exponential function expm. Remember not to confuse finding the exponent of a matrix, expm, with the M ATLAB function exp which simply finds the exponent of all individual elements in the matrix.

2.8.2 Using M ATLAB to discretise systems All of the complications of discretising continuous systems to their discrete equivalent can be circumvented by using the M ATLAB 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.

3

G = tf(1,[1 0 0]) % Continuous system G(s) = 1/s2 in transfer function form Gc = ss(G) % Convert to continuous state-space Gd = c2d(Gc,2) % Convert to discrete state-space with a sample time of T = 2 a =

8

x1 x2

x1 1 2

x1 x2

u1 2 2

y1

x1 0

y1

u1 0

x2 0 1

b =

13

c = x2 1

18

d =

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 M ATLAB to compute the matrix exponential of the augmented system. 1

[A,B,C,D] = ord2(3, 0.5); Ts = 3.0;

% generate a second order system % sample time

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

64

6

[na,nb] = size(B); X = expm([A,B; zeros(nb,na+nb)]*Ts); Phi = X(1:na,1:na); Del = X(1:na,na+1:end);

% matrix exponential % Pull off blocks to obtain Φ & ∆.

We can use M ATLAB to numerically verify the expression found for the discretised double integrator on page 60 at a specific sample time, say T = 4. The double integrator in input/output form is 1 G(s) = 2 s which in packed state space notation is     0 0 1 A B = 1 0 0  C D 0 1 0

3

8

Using a sample time of T = 4, we can compute     1 0 1 0 Φ= = T 1 4 1     T 4 ∆ = T 2 = 16 2

>>Gc = tf(1,[1,0,0])% G(s) = 1/s2 >>Gc_ss = ss(Gc);% state space >>dt = 4; % sample time >>Gd_ss = c2d(Gc_ss,dt) a = x1 x2 x1 1.000 0 x2 4.000 1.000 b =

13

x1 x2

u1 4.000 8.000

c =

2

18

We can verify this using c2d in M ATLAB as demonstrated opposite.

y1

x1 0

x2 1.000

d = y1

u1 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 conditions x0 , the state vector x at each sample instant is calculated thus x1 = Φx0 + ∆u0 x2 = Φx1 + ∆u1 = Φ2 x0 + Φ∆u0 + ∆u1 x3 = Φx2 + ∆u2 = Φ3 x0 + Φ2 ∆u0 + Φ∆u1 + ∆u2 .. . xn = Φn x0 +

n−1 X

Φn−1−k ∆uk

.. . (2.81)

k=0

The M ATLAB 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 An 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 An ? (Hint: find the eigenvalues of A.) 2. What is the determinant of An ? 3. Write a couple of M ATLAB m-functions to convert between the A, B, C and D form 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 

   0 1 0 0 x˙ =  −0.0071 −0.111 0.12  x +  −0.095  u 0 0.07 −0.3 0.072

(2.82)

where the state vector x is defined 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 deflection of the stern plane. We will assume that of the three states, we can only actually measure two of them, θ and α, thus   1 0 0 C= 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 M ATLAB, the command eig(A) returns   −0.0383 + 0.07i eig(A) =  −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.

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

66

0 G

c

G

−5 x

1

d

−10

−15

0.4

x

2

0.3 0.2 0.1

Figure 2.22: Comparing the continuous and discrete step responses of the submarine model.

0

0

20

40 time

60

80

Fig. 2.22 affirms 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

6

>> u = 1; >>xss = -A\B*u; >>yss = C*xss yss = -9.3239 0.2400

% Steady-states given by xss = −ABu. % See steady-state outputs in Fig. 2.22.

which corresponds to the final 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 A is invertible, Eqn. 2.73. >> Phi = expm(A*5.0); % Don’t forget the ‘m’ in expmatrix()   >> Delta = (Phi-eye(size(A)))*(A\B) % ∆ = eAT − I A−1 B

This script should give the same Φ and ∆ matrices as the c2d function since A is non-singular. Given a discrete or continuous model, we can compute the response to an arbitrary input sequence using lsim: t = [0:dt:100]'; % time vector U = sin(t/20); % Arbitrary input U (t) 3

lsim(Gc,U,t) lsim(Gd,U)

% continuous system simulation % discrete system simulation

2.8. SOLVING THE VECTOR DIFFERENTIAL EQUATION

67

We could explicitly demand a first-order-hold as opposed to the default zeroth order by setting the options for c2d. optn = c2dOptions('Method','foh') % Ask for a first-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 = x2 x˙ 2 = 10 − 2x2 + 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 M ATLAB using the lsim function. (ie: x˙ = Ax + Br) Write down the relevant M ATLAB code segment. (Note: In practice, it is advisable to use lsim whenever possible for speed reasons.) Problem 2.6 1. Write an m-file that returns the state space system in packed matrix form that connects the two dynamic systems G1 and G2 together, Gall = G1 · G2 Assume that G1 and G2 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   A − BD−1 C −BD−1 (2.83) G−1 = D−1 C D−1 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 difficult to model systems with delay. However, by introducing new variables we can accommodate dead time or time delays. Consider the continuous differential equation, x˙ t = Axt + But−θ

(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 xk+3 = Φxk+2 + ∆uk

(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   xk def  xk+1  zk = xk+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 

   xk+1 Ixk+1  =  xk+2  =  Ixk+2 xk+3 Φxk+2 + ∆uk

zk+1

(2.87)

or in standard state-space form as 

0 I = 0 0 0 0

zk+1

   0 0 I  z k +  0  uk Φ ∆

(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 transition matrix in Eqn. 2.88 is now no longer of full rank (provided it was in the first 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); zk =



xk

xk+1

xk+2

· · · xk+β

⊤

The augmented state transition matrix Ξ and augmented control matrix Ψ are of the form 

    Ξ=   

0 I 0 0 0 0 .. .. . . 0 0 0 0

0 ··· 0 I ··· 0 0 ··· 0 . .. . . . .. . 0 ··· I 0 ··· Φ



    ,   



    and Ψ =    

0 0 0 0 .. . ∆

        

(2.89)

Now the discrete time equation is zk+1 = Ξzk + Ψuk

(2.90)

Since all the introduced states are unobservable, we have xk =



I 0

and that the output equation is amended to yk = C



I 0

0 ··· 0



0 ··· 0

zk

(2.91)



(2.92)

zk

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 difficult 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



s

Transfer function

q

I

 non-poly

Pade approx.

Nonlinear

yes/no Routh array Jury test

^ Marginal

Linearise

Lyapunov simulate

eigenvalues roots of denominator poles

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 definition 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 defined and relatively straight forward to evaluate6 , 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 briefly techniques that can be used for nonlinear systems. Before any type of stability analysis can be carried out, it is important to define 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.

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

70

2.9.1 Stability in the continuous domain The most important requirement for any controller is that the controller is stable. Here we describe 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 definition). 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 unstable, 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 definition, (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 denominator polynomial using a computer program to compute numerically the roots such as M ATLAB’s 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 M ATLAB ’ S 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 efficiency, there are two cases where this strategy falls down. One is where we do not have access to M ATLAB 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 Lyapunov’s method to assess stability. The Routh criterion states that all the roots of the polynomial characteristic equation, an sn + an−1 sn−1 + · · · + a1 s + a0 = 0

(2.93)

have negative real parts if and only if the first 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 defined starting with the coefficients of the characteristic polynomial, Eqn. 2.93, sn an an−2 an−4 · · · sn−1 an−1 an−3 an−5 · · · sn−2 b1 b2 b3 ··· c2 c3 ··· sn−3 c1 .. .. .. . . . and where the new entries b and c are defined as an−1 an−2 − an an−3 , b1 = an−1 b1 an−3 − an−1 b2 , c1 = b1

an−1 an−4 − an an−5 , an−1 b1 an−5 − an−1 b3 c2 = , b1

b2 =

etc. 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, 117–118]. 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 M ATLAB 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 s4 + 3s3 + 3s2 + 2s + K = 0 as a function of gain K.8 Listing 2.5: Example of the Routh array using the symbolic toolbox

3

8

>> syms K % Define symbolic gain K >> ra = routh([1 3 3 2 K],K) % Build Routh array for s4 + 3s3 + 3s2 + 2s + K ra = [ 1, 3, K] [ 3, 2, 0] [ 7/3, K, 0] [ -9/7*K+2, 0, 0] [ K, 0, 0]

Since all the elements in the first 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 nonpolynomial 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 www.mathworks.com/matlabcentral/fileexchange/. 8 Problem adapted from [150, p288]

MathWorks

user’s

group

collection

at

72

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

for stability considerations for the open loop. However in the closed loop the dead time term appears 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 find the roots of the denominator, since now there are an infinite number of them, but instead we must approximate the exponential term with a truncated polynomial such as a Pad´e approximation 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 Pade´ approximation and a Bode or Nyquist diagram. A first order Pade´ 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) e−0.2s (s + 5)(s + 4)(s + 3)

(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 difficult to manipulate, so we normally ignore the frequency 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 Nyquist Diagram

3D Nyquist plot

3

2

4

10

1 Imaginary Axis

ω [rad/s]

2

10

0

10

−2

10

0

−1

2 −2

0

4 2

−2 ℑ(Gi ω)

−3

0 −4

−2

−1

ℜ(Gi ω)

0

1

2

3

Real Axis

(a) The Nyquist diagram with frequency information presented in the third dimension. A ‘flagpole’ is drawn at (−1, 0i). Since the curve encircles the flagpole, the closed loop is unstable.

(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 definition of stability for a discrete time system is similar to that of the continuous time system except that the definition 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 definition z = exp(sT ), the poles of the continuous transfer function pi map to exp(pi T ) in discrete space. If pi is negative, then exp(pi T ) will be less than 1.0. If pi is positive, then the corresponding discrete pole zi will be larger than 1.0. Strictly if pi is complex, then it is the magnitude of zi that must be less than 1.0 for the system to be stable. If the discrete poles zi , 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 zi 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 z2 + 1

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

74

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 Lyapunov’s 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]. Lyapunov’s 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 6s2 + 5s + 1

at a sampling period of T = 2 and a first-order hold. The discrete transfer function is G(z) =

0.0746 + 0.2005z −1 + 0.0324z −2 1 − 0.8813z −1 + 0.1889z −2

2

with discrete poles given by the solution of 1 − 0.8813z −1 + 0.1889z −2 = 0 or z=



7

>> G = tf(1,[6 5 1]); >> Gd = c2d(G,2,'foh') >> pole(Gd) ans = 0.5134 0.3679 >> pzmap(Gd); axis('equal');

0.5134 0.3679

Since both discrete poles lie inside the unit circle, the discretised transfer function with a firstorder hold is still stable. If you are using the state space description, then simply check the eigenvalues of the homogeneous 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 difficult, if not impossible to solve, one can attempt to establish the stability without needing to find the solution. Studies of this sort fall into the realm of nonlinear systems analysis which demands a high degree of mathematical 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 Lyapunov9 address this nonlinear system stability 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 M ATLAB 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 (1857–1918) was a Russian mathematician and mechanical engineer. He had the very rare merit of producing a doctoral dissertation of lasting value. This classic work was originally published in 1892 in Russian but is now available in an English translation Stability 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 first partial derivatives satisfying V (x) is positive definite and the time derivative, V˙ (x), is negative definite, 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 definite, 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 finding a suitable Lyapunov function in the first 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 don’t 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 Discrete difference equations, Given a nonlinear difference equation,

Continuous differential equations

xk+1 = f (xk ),

Given a nonlinear differential equation,

f (0) = 0

and a scalar function V (x), continuous in x, then if

x˙ = f (x, t)

1. V (x) > 0 for x 6= 0 (or V (x) is positive definite), and

and a scalar function V (x), then if 1. V (x) is positive definite, and 2. V˙ (x), the derivative of V (x), is negative definite, and

2. ∆V (x), the difference of V (x), is negative definite, where ∆V (xk ) = V (xk+1 ) − V (xk )

3. V (x) → ∞ as kxk → ∞

then the system x˙ = f (x, t) is globally asymptotically stable.

= −V (f (xk )) − V (xk )

and 3. V (x) → ∞ as kxk → ∞

then the system xk+1 = f (xk ) is globally asymptotically stable.

Example of assessing the stability of a discrete nonlinear system using Lyapunov’s second method. Consider the dynamic equation from Ogata [150, Ex 9-18, p729] x˙ 1 = x2 − x1 x21 + x22



x˙ 2 = −x2 − x2 x21 + x22



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) = x21 + x22 which is positive definite. (Note that that was the hard bit!) Now differentiating gives dx1 dx2 V˙ (x) = 2x1 + 2x2 = −2 x21 + x22 dt dt



which is negative definite. 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 methods, 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 definiteness 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) = xT Px The Lyapunov function will be positive definite if the matrix P is positive definite. The time derivative is given by V˙ (x) = x˙ T Px + xT Px˙ = (Ax)T Px + xT P(Ax)   = xT AT P + PA x | {z } −Q

So if −Q is negative definite or alternatively Q is positive definite, 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 definite or not, but using M ATLAB we would usually attempt a Cholesky factorisation. Apart from the difficulty in deciding if a matrix is positive definite or not, we also have the problem that a failure of Q being positive definite 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 definite Q (say the identity matrix), and then solve AT 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 Sylvester’s equation.

One obvious way to solve for the symmetric matrix P in Eqn. 2.96 is by equating the coefficients which results in a n(n + 1)/2 system of linear algebraic equations. It is convenient in M ATLAB to use the Kronecker tensor product to set up the equations and then use M ATLAB’s backslash operator to solve them. This has the advantage that it is expressed succinctly in M ATLAB, 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

3

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS n= size(Q,1); % Solve AT P + PA = −Q, Q = QT I= eye(n); % Identity In , the same size as A P=reshape(-(kron(I,A')+kron(A',I))\Q(:),n,n);% −vec(I⊗AT +AT ⊗I)vec(P) = vec(Q) P= (P+P')/2; % force symmetric (hopefully unnecessary)

The final line, while strictly unnecessary, simply forces the computed result to be symmetric, which of course it should be in the first 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 9–18 Ogata [150, p766], and [148, p554]. Note however, using M ATLAB, we would not normally bother with these modifications. The C ONTROL T OOLBOX for M ATLAB includes the function lyap that solves the matrix Lyapunov equation which is more numerically robust and efficient that equating the coefficients or using the Kronecker tensor product method given on page 77. However note that the definition of the Lyapunov matrix equation used by M ATLAB, AP + PAT = −Q

(2.97)

is not exactly the same as that defined by Ogata and used previously in Eqn. 2.96. (See the M ATLAB help file for clarification of this and compare with example 9–20 in [150, p734].) Suppose we wish to establish the stability of the continuous system x˙ = Ax   0 1 = x −1 0.5 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 definite matrix such as say Q = I. Since M ATLAB’s lyap function solves the equivalent matrix equation given by Eqn. 2.97, we must pass A⊤ rather than A as the first argument to lyap. Listing 2.7: Solve the matrix Lyapunov equation using the lyap routine 1

6

>> A = [0,1;-1,-0.4]; >> P = lyap(A',eye(size(A))) % Use AT instead of A P = 2.7000 0.5000 0.5000 2.5000 >> A'*P + P*A + eye(size(A)) % Does this equal zero ? ans = 1.0e-015 * 0 -0.4441 -0.4441 0.2220

11

16

>> Q = eye(size(A)); % alternative method >> n = max(size(Q)); % solve AT X + XA = C where C ≻ 0 >> I = eye(n); >> P=reshape(-(kron(I,A')+ kron(A',I))\Q(:),n,n) 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 Sylvester’s criteria, P is positive definite and so the system is stable. We can use Sylvester’s criteria to establish if P is positive definite or not, and hence the system’s stability. To establish if a symmetric matrix is positive definite, the easiest way is to look at the eigenvalues. If they are all positive, the matrix is positive definite. Unfortunately we were originally trying to avoid to solve for the eigenvalues, so this defeats the original purpose somewhat. Another efficient strategy to check for positive definiteness with M ATLAB is to attempt a Cholesky decomposition using the [R,p]=chol(A) command. The decomposition will be successful if A is positive definite, and will terminate early with a suitable error message if not. Refer to the help file for further details. As a final check, we could evaluate the eigenvalues of A in M ATLAB 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 xk+1 = Φxk , we will again choose a positive definite quadratic function for the trial Lyapunov function, V (x) = xT Px where the matrix P is positive definite, and compute the forward difference ∆V (x) = V (xk+1 ) − V (xk )

= xTk+1 Pxk+1 − xTk Pxk

If the matrix Q

= (Φxk )T PΦxk − xTk Pxk   = xTk ΦT PΦ − P xk {z } | −Q

  Q = − ΦT PΦ − P

(2.98)

is positive definite, 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 2

n I P P

= = = =

max(size(Q)); % Solve AT PA − P = −Q, with Q ≻ 0 eye(n); % identity reshape((kron(I,I)-kron(Phi',Phi'))\Q(:),n,n) (P+P')/2; % force symmetric (hopefully unnecessary)

Once again, the more efficient dlyap routine from the C ONTROL T OOLBOX can also be used. In fact dlyap simply calls lyap after some minor pre-processing. We can demonstrate this establishing the stability of   3 −0.5 xk+1 = xk 0 0.8

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

80

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

6

11

>> 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 -0.1339 2.9886 >> [R,rc] = chol(P) % Is P +ve definite? R = [] rc = 1 % No it isn’t, unstable!

we verify that result. We can both check the definiteness of P using Sylvester’s criteria [150, pp924-926], or by using the chol function as in the above example, or even by finding 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, xk+1 = Φxk 1. Choose a convenient positive definite n × n matrix Q, say the identity, In×n , then 2. Solve either AT P + PA = −Q in the case of a continuous system, or ΦT PΦ − P = −Q in the case of a discrete system for P by either equating the coefficients or using lyap or dlyap. 3. The Lyapunov function is V (x) = xT Px, so check the definiteness of P. The system is stable if and only if P is positive definite. Check using Sylvester’s 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 specifically on Kronecker products used in control applications.

2.9. STABILITY

81

The Kronecker product, given the symbol ⊗, of two arbitrarily sized matrices, A ∈ ℜm×n and B ∈ ℜp×q , results in a new (large) matrix   a11 B · · · a1n B   .. .. mp×nq .. A⊗B= (2.99) ∈ℜ . . . am1 B

· · · amn B

of size (mp × nq). In M ATLAB we would write kron(A,B). Note in general A ⊗ B 6= B ⊗ A.

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 M ATLAB 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 multiplication as a linear transformation. For example, for the two matrices A and B of compatible dimensions, then vec (AB) = (I ⊗ A) vec(B)   = BT ⊗ I vec(A)

and for the three matrices A, B and C of compatible dimensions, then   vec (ABC) = CT ⊗ A vec(B) = (I ⊗ AB) vec(C)   = CT BT ⊗ I vec(A)

(2.100)

(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(AX − XA) = I ⊗ A − AT ⊗ 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 − AT ⊗ I .

We first solve for the unknown vector x using say x = G−1 q or some numerically sound equivalent, 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 G is (n2 ×n2 ). However [34] describes some modifications 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 O PTIMISATION T OOLBOX has the nice feature that it can solve matrix equations such as the continuous time Lyapunov equation directly. Here we wish to find the square matrix X such that AX + XAT + Q = 0 given an arbitrary square matrix A and a positive definite matrix Q. For an initial estimate for X we should start with a positive definite matrix such as I. We can compare this solution with the one generated by the dedicated lyap routine.

CHAPTER 2. FROM DIFFERENTIAL TO DIFFERENCE EQUATIONS

82



6



6

Stability boundary +1 z

9 stable

stable

- ℜ

0

+1

unstable 

imaginary axis

Continuous s-plane

unstable

−1

- ℜ

I unit circle

Discrete z-plane

Figure 2.26: Regions of stability for the poles of continuous (left) and discrete (right) systems

>> n = 4; >> A = rand(n); >> Q1 = randn(n); Q = Q1'*Q1;

% Create a ‘random’ matrix A of dimensions (n × n) % Create a ‘random’ positive definite matrix Q

4

9

14

>> LyEqn = @(X) A*X+X*A'+Q; >> X = fsolve(LyEqn, eye(n)); X1 = -0.8574 -0.6776 1.0713 -0.6776 2.7742 -2.6581 1.0713 -2.6581 0.7611

% Matrix equation to be solved: AX + XAT + Q = 0 % Solve the Lyapunov using fsolve

>> Xx = lyap(A,Q); Xx = -0.8574 -0.6776 -0.6776 2.7742 1.0713 -2.6581

% Solve the Lyapunov using the control toolbox 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 lefthand-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 denominator 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 M ATLAB, 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 Ogata’s comments, [148, p250].

2.10 Summary This chapter briefly 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 simulation. Converting a continuous differential equation to a discrete differential equation can be done either by using a backward difference approximation such as Euler’s 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 domain to the discrete form equivalent; xk+1 = Φxk + ∆uk . 3. The stability of both the discrete and continuous time systems is determined by the eigenvalues of the A or Φ matrix. 4. We can transform the mathematical description of the process to dynamically similar descriptions 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 systems 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 don’t 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 systematic, hence the importance of modelling. Physically dynamic systems are those that change with time. Examples include vibrating structures (bridges and buildings in earthquakes), bodies in motion (satellites in orbit, fingers on a typewriter), changing compositions (chemical reactions, nuclear decay) and even human characteristics (attitudes to religion or communism throughout a generation, or attitudes to the neighbouring 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 infeasible 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 fit any old curve to the experimental data, and Whitebox or fundamental models, where the curves are fitted to well established physical laws represent 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 fit any residuals. Computer tools for 85

Modelling

86 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 Bristol’s 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 equations. Solving systems involving differential equations is much harder than for algebraic equations, 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 didn’t 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 engineers, 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 process: 1. Draw a diagram of the system with a boundary and labelling the input/output flows that cross the boundary. 2. Decide on what are state variables, what are parameters, manipulated variables, uncontrolled 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 flow system into and out of a tank with external heating, a double integrator such as an inverted pendulum or 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

torque, Tc

θ length, l

θ

? mg

? mg

Inverted pendulum (unstable)

Pendulum (stable)

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 ml2

d2 θ + mgl sin θ = Tc dt2

(3.1)

where θ is the angle of inclination, and Tc 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*lˆ2*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*lˆ2))ˆ(1/2)*l,a = .. theta)-t-C2 = 0] [ Int(-m/(m*(2*m*g*l*cos(a)+2*Tc*a+C1*m*lˆ2))ˆ(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 defining a new state variable vector, x, as def

x1 = θ def

x2 = x˙ 1 =

(3.2) dθ dt

(3.3)

then we note that x˙ 2 = x ¨1 , so the single second order differential equation can now be written as

Modelling

88 two coupled first order equations x˙ 1 = x2 g Tc x˙ 2 = − sin x1 + l ml2

(3.4) (3.5)

Linearising Eqn. 3.5 is trivial since sin θ ≈ θ for small angles. Consequently, both linear and nonlinear expressions are compared below # # # " # " " " 0 0 0 1 0 x1 + x+ , x˙ = −g (3.6) x˙ = −g Tc Tc sin(x1 ) 0 0 2 2 l l ml } ml } {z {z | | nonlinear

linear

while the numerical results are compared on page 120.

In the inverted case, the equation for x˙ 2 is almost the same, Tc g x˙ 2 = + sin x1 + l ml2

(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

d2 θ =u dt2

(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 satellite’s side). We can convert the second order system in Eqn. 3.8 to two first order systems by again defining a new state vector     x1 def θ = (3.9) x= x2 θ˙ Substituting this definition into Eqn. 3.8, we get J x˙ 2 = u and x˙ 1 = x2 , or in a matrix-vector form       0 0 1 x˙ 1 (3.10) = x 1 u 0 0 x˙ 2 J 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 fluctuations in production flows. Our system boundary is essentially the figure boundary, so we have one input, the input flow rate, Fin , and one output, the output flow rate, Fout . What interests us is the amount of fluid in the tank, M , which physically must always be less than the full tank Mmax , and greater than 0. The governing relation is the conservation of mass, dM = Fin − Fout dt

(3.11)

3.2. A COLLECTION OF ILLUSTRATIVE MODELS

89

flow in, Fin tank with cross sectional area, A ? 6 ˆ measured height, h

∆P

true height, h ? valve -

flow out, Fout

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 proportional to the height of water h, since most fluids are assumed incompressible. In addition the mass M is proportional to the volume, M = ρV = ρAh. Rewriting Eqn. 3.11 in terms of height Fin − Fout dh = dt ρA

(3.12)

since the area and density are constant. If the liquid passes though a valve at the bottom of the tank, the flowrate out will be a function of height. For many processes, the flow is proportional to the square root of the pressure drop, (Bernoulli’s equation) √ √ Fout ∝ ∆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 difficult to control owing to the added measurement dynamics. We assume, that the level leg can be modelled using a first 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 ˆ ˆ dh h−h = (3.13) dt 2 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 Fin − k h = (3.15) dt ρA ˆ ˆ h−h dh = (3.16) dt 2 ˆ I = f (h) (3.17)

Modelling

90

The input variable (which we may have some hope of changing) is the input flow rate, Fin , and the exit valve position which changes k. The dependent (state) variables are the actual tank ˆ The output variable is the current, I. Conlevel, h, and the measurable level in the level leg, h. 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 flowrate. Table 3.1: Standard nomenclature used in modelling dynamic systems

type independent states inputs outputs parameters

symbol t x u y θ

variable time, t h, ˆh Fin , k I ρ, 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 flow minus the heat lost with the out flowing stream minus any other heat losses”. We note that for water the heat capacity cp , is almost constant over the limited temperature range we are considering, and that the enthalpy of water in the tank is defined as H = M cp ∆T

(3.18)

where ∆T is the temperature difference between the actual tank temperature T and some reference temperature, Tref . Writing an energy balance gives M cp

dT = Fin cp (Tin − Tref ) − Fout cp ∆T + Q − q dt

(3.19)

where Q is 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 significant. 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 Troom . Thus q = k(T − Troom ). Note that the heat loss now can be both positive or negative. You may also decide that the heat capacity cp , and density ρ of water are a function of temperature. Now you replace these constants with functions as cp (T ) and ρ(T ). These functions are tabulated in the steam tables1 . The more complete model 1 Steam

tables for M ATLAB are available from http://www.kat.lth.se/edu/kat061/MfileLib.html

3.2. A COLLECTION OF ILLUSTRATIVE MODELS

91

would then be Fin − Fout dh = dt ρ(T )A dT Aρ(T ) = Fin cp (T ) (Tin − T ref ) − Fout cp (T )∆T + Q − k (T − Troom) dt

(3.20)

“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, Fin , Fout , M, A, k, cp , ρ 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 problem 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 biannual UK government forecast of Britain’s economic performance. This performance or growth, is defined 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 Exchequer, (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.

119 Forecasts

Growth GDP change

118 117 116 115 114 113 112 111 1989

Actual 1990

1991 Year

1992

1993

Figure 3.3: The UK growth based on the GDP comparing the actual growth (solid) versus Treasury forecasts (dashed) from 1989–1992.

Modelling

92

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 benefits of modelling than in distillation. One industry magazine2 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 predict the extent of the component separation given the type of trays in the column, the column diameter 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 reflux 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 complexity): 1. Lumped parameters systems such as well-mixed reactors or evaporators 2. Staged processes such as distillation columns, multiple effect evaporators, floatation. 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 briefly considered in section 3.5.1. A collection of good test industrial process models is available in the nonlinear model library from www.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 Ca measured in mol/m3 and the temperature of the reaction vessel liquid, T measured in K. The manipulated variables are the cooling jacket water temperature, Tc , the temperature of the feed Tf and 2

The Chemical Engineer, 21st October, 1999, p16

3.3. CHEMICAL PROCESS MODELS

93

Feed, Tf , Caf

-

Stirrer

? -

Cooling, Tc

A→ B ? Product, T, Ca

Figure 3.4: A CSTR reactor

the concentration of the feed, Caf .   q −E dT Ca = (Caf − Ca ) − k0 exp dt V RT   UA q m∆H −E dCa Ca + k0 exp (Tc − T ) = (Tf − T ) + dt V ρCp RT V ρCp

(3.21) (3.22)

The values for the states and inputs at steady-state are def

xss =



T Ca



= ss



324.5 0.8772



,



   Tc 300 uss =  Tf  =  350  1 Caf ss def

(3.23)

The values of the model parameters such as ρ, Cp etc. are given in Table 3.2.

Table 3.2: Parameters of the CSTR model

name Volumetric Flowrate Volume of CSTR Density of A-B Mixture Heat capacity of A-B Mixture Heat of reaction for A→B Pre-exponential factor Overall Heat Transfer Coefficient × Area

variable q = 100 V = 100 ρ = 1000 Cp = .239 m∆H = 5 · 104 E/R = 8750 k0 = 7.2 · 1010 U A = 5 · 104

unit m3 /sec m3 kg/m3 J/kg-K J/mol K 1/sec W/K

Note: At a jacket temperature of Tc = 305K, the reactor model has an oscillatory response. The oscillations are characterized by reaction run-away with a temperature spike. When the concentration drops to a low value, the reactor cools until the concentration builds and there is another run-away reaction.

Modelling

94

3.3.2 A forced circulation evaporator Evaporators such as illustrated in Fig. 3.5 are used to concentrate fruit juices, caustic soda, alumina 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 developed in [145, chapter 2] is reproduced here as a test process for a wide variety of control techniques 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. Vapour

Cooling water Condenser Condensate L

Pressure

level

P

Separator

Steam

Evaporator

Condensate

circulation pump composition A

Feed

Product

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 described 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 State

Manipulated

Disturbance

name level steam pressure product conc product flow steam pressure c/w flow circulating flow feed flow feed composition feed temperature c/w temperature

variable L2 P2 x2 F2 P100 F200 F3 F1 x1 T1 T200

unit m kPa % kg/min kPa kg/min kg/min kg/min % ◦ C ◦ C

range 0–2 ?? 0–100 0-10 100–350 0–300 30-70 5-15 0-10 20-60 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 significant 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 M ATLAB 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 almost 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 efficiently. 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 hydrodynamics 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 reflux) to control the top and bottoms composition. The Wood-Berry model is written as a matrix of Laplace transforms in deviation variables     −18.9e−3s 3.8e−8s 12.8e−s    16.7s + 1 21s + 1   u +  14.9s + 1  d (3.24) y=   6.6e−7s −3.4s  −3s  4.9e −19.4e | 10.9s + 1 {z 14.4s + 1 G(s)

}

13.2s + 1

where the inputs u1 and u2 are the reflux and reboiler steam flowrates respectively, the outputs y1 and y2 are the mole fractions of ethanol in the distillate and bottoms, and the disturbance variable, d is the feed flowrate. It is evident from the transfer function model structure in Eqn. 3.24 that the plant will be interacting and that all the transfer functions have some time delay associated with them, but the

Modelling

96

c/w

6

Reflux, R condensor 

Feed, F, xF

-

?

?

s

-

-

Distillate, D, xD

-

Bottoms, xB , B

Distillation column  Steam, S ?

-

6  reboiler 6

Figure 3.6: Schematic of a distillation column off-diagonal terms have the slightly larger time delays. Both these characteristics will make controlling the column difficult. In M ATLAB, we can construct such a matrix of transfer functions (ignoring the feed) with a matrix of deadtimes as follows:

4

9

>> 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], ... 'InputName',{'Reflux','Steam'}, ... 'OutputName',{'Distillate','bottoms'}) Transfer function from input "Reflux" to output... 12.8 Distillate: exp(-1*s) * ---------16.7 s + 1

bottoms: 14

19

6.6 exp(-7*s) * ---------10.9 s + 1

Transfer function from input "Steam" to output... -18.9 Distillate: exp(-3*s) * -------21 s + 1 -19.4

3.3. CHEMICAL PROCESS MODELS bottoms:

97

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 S IMULINK is shown in Fig. 3.8. Step Response From: Reflux

From: Steam

To: Distillate

0 −10 −20

To: bottoms

Amplitude

10

0

−10

−20

0

50

100

0 Time (sec)

50

100

Figure 3.7: Step responses of the four transfer functions that make up the Wood-Berry binary distillation column 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 

−0.61e−3.5s −0.0049e−s 0.66e−2.6s 6.7s + 1 8.64s + 1 9.06s + 1     y1  1.11e−6.5s −3s −2.36e −0.012e−1.2s  y2  =    3.25s + 1 5s + 1 7.09s + 1 y3  −9.4s  −34.68e−9.2s 46.2e 0.87(11.61s + 1)e−2.6s 8.15s + 1 10.9s + 1 (3.89s + 1)(18.8s + 1)   −1.2s −0.0011(26.32s + 1)e−2.66s 0.14e  6.2s + 1 (3.89s + 1)(14.63s + 1)      −10.5s −0.0032(19.62s + 1)e−3.44s  d1  0.53e +   d2  6.9s + 1 (7.29s + 1)(8.94s + 1)     −11.54e−0.6s −2.6s 0.32e 7.01s + 1 7.76s + 1



    u1   u2    u3  

(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 reflux flow rate, the side stream product rate and the reboiler steam pressure, and the two disturbances are the feed flow 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 final value theorem. 2. Sketch the response for y1 and y2 for; (a) a change in reflux flow of +0.02

Modelling

98

reflux

reflux

distillate

steam

bottoms

distillate

Wood Berry Column

steam

bottoms

(a) Overall column mask. 12.8

1 reflux

1

16.7s+1 Transport Delay

Transfer Fcn

distillate

−18.9 21s+1 Transfer Fcn1

Transport Delay1

6.6 10.9s+1 Transfer Fcn2

2 steam

Transport Delay2

−19.4

2

14.1s+1 Transfer Fcn3

Transport Delay3

bottoms

(b) Inside the Wood Berry column mask. Compare this with Eqn. 3.24. Figure 3.8: Wood-Berry column model implemented in S IMULINK (b) A change in the reflux flow of −0.02 and a change in reboiler steam flow of +0.025 simultaneously. 3. Modify the S IMULINK 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 multicomponent 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 component, 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 overflow 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 simplifies the vapour-liquid equilibria (VLE) model to yn =

αxn 1 + (α − 1)xn

on tray n with typically α ≈ 1.2–2. 4. Vapour phase holdup is negligible and the feed is a saturated liquid at the bubble point. ? c/w

-

condensor

6

? condensor collector - Distillate, D, xD

 tray # N

Feed, F, xF

reflux, R, xD

.. . -

feed tray, NF

.. . tray #1

 6 reboiler  ?

6

- Bottoms, xB , B

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 condenser). We will develop separate model equations for the following parts of the column, namely: Condenser is a total condenser, where the reflux is a liquid and the reflux drum is perfectly mixed. General tray has liquid flows from above, and vapour flows 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) flows missing, but recycle/reflux added. Reboiler in a perfectly mixed thermo-siphon reboiler with hold up Mb .

Modelling

100 The total mass balance in the condenser and reflux drum is dMd =V −R−D dt and the component balance on the top tray dMd xd = V yNT − (R + D)xD dt

(3.26)

For the general nth tray, that is trays #2 through N − 1, excepting the feed tray, the total mass balance is dMn = Ln+1 − Ln + Vn−1 − Vn | {z } dt = Ln+1 − Ln

≈0

(3.27)

and the component balance dMn xn = Ln+1 xn+1 − Ln xn + V yn−1 − V yn dt

(3.28)

For the special case of the feed nF th tray, dMnF = LnF +1 − LnF + F, mass balance dt dMnF xnF = LnF +1 xnF +1 − LnF xnF + F xF + V ynF −1 − V ynF , component balance dt and for the reboiler and column base dMB = L1 − V − B dt dMB xB = L1 x1 − BxB − V xB dt In summary the number of variables for the distillation column model are:

VARIABLES

Tray compositions, xn , yn Tray liquid flows, Ln Tray liquid holdups, Mn Reflux comp., flow & hold up, xD , R, D, MD Base comp., flow & hold up, xB , yB , V, B, MB Total # of equations

2NT NT NT 4 5 4NT + 9

and the number of equations are:

E QUATIONS

Tray component balance, Tray mass balance Equilibrium (tray + base) hydraulic Reflux comp. & flow Base comp & flow Total # of equations

NT NT NT + 1 NT 2 2 4NT + 7

Which leaves two degrees of freedom. From a control point of view we normally fix the boildup ˙ and the reflux flow rate (or ratio) with some sort of controller, rate, Q, R = f (xD ),

V ∝ Q˙ = f (xB )

3.3. CHEMICAL PROCESS MODELS

101

Our dynamic model of a binary distillation column is relatively large with two inputs (R, V ), two outputs (xB , xD ) 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˙ .  ∂x ∂u  |{z} |{z} 44×44

44×2

The structure of the A and B matrices are, using the spy command, given in Fig. 3.10. Jacobian of the Binary distiilation column model 0

5

10

ODE equations, (zdot=)

15

20

25

30

35

40

45

0

5

10

15 20 25 30 35 States & input, ([holdup, comp*holdup| [R V])

40

45

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 relative 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 reflux from R = 128 to R = 128 + 0.2, and 2. the reboiler from V = 178 to V = 178 + 0.2

Modelling

102

Distill conc

Step change in Reflux

Step change in Vapour

1

1

0.995

0.995

0.99

0.99

0.985

0.985

0.98

0.98

base conc

0.975

0

10

20

30

0.975

0.1

0.1

0.08

0.08

0.06

0.06

0.04

0.04

0.02

0.02

0

0

10

20

30

0

0

10

0

10

time (min)

20

30

20

30

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, 

xD (s) xB (s)



=



G11 G21

G12 G22



R(s) V (s)



So it is natural to wonder at this point if it is possible to approximate this response with a loworder model rather than requiring the entire 44 states and associated nonlinear differential equations.

Controlled simulation of a distillation column A closed loop simulation of the 20 tray binary distillation column with a feed disturbance from xF = 0.5 to xF = 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 difficulties in tuning. We will simulate in Fig. 3.14 a step change in the distillate setpoint from x⋆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

Binary distillation column model

Liquid concentration

1 0.8 0.6 0.4 0.2 0 130 R

128 126

V

124 185 180 175

0

20

40 60 time (min)

80

100

Figure 3.12: A closed loop simulation of a binary distillation column given a feed disturbance. The upper plot shows the concentration on all the 20 trays, the lower plots shows the manipulated variables (reflux and boil-up) response.

Distillate

0.99 0.985 0.98

Bottoms

0.975 0.04 0.03 0.02 0.01

0

20

40 60 time [mins]

80

100

Figure 3.13: Detail of the distillate and base concentrations from a closed loop simulation 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,

Modelling

104

Distillate xD

1

0.99

0.98

Base, xB

0.04 0.03 0.02 0.01

Figure 3.14: Distillation interactions are evident when we step change the distillate and bottoms setpoints independently.

reboiler

Reflux

0 160 140 120 200 180 160

0

50

100

150 time (min)

200

250

as an example, the final steady-state as a function of the manipulated variable u, is   12.8 −18.9 yss = Gss u = u 6.6 −19.4

300

(3.29)

The ijth element of Gss is the open loop gain between yi and uj . The Gss matrix can be evaluated experimentally or formed by applying the final 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 Gss and G−⊤ ss elementwise,3 ⊤ (3.30) Λ = Gss ⊗ G−1 ss 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 M ATLAB, 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. Don’t 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 Λ

details.

 ⊤ = Gss G−1 , i.e. without the Hardamard product. See [179, p456] for further ss

3.3. CHEMICAL PROCESS MODELS

105

process control and is discussed in more detail in [191, pp494–503], 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]  2.5e−5s    (15s + 1)(2s + 1) y1 =  y2 1 3s + 1 | {z G(s)

 5   4s + 1   u1 −4e−5s  u2 20s + 1 }

(3.31)

which has as its distinguishing feature significant time delays on the diagonal elements. We could compute the dynamic relative gain array matrix using the definition Λ(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

8

13

>>RGA = G.*inv(G') % Λ(s), Eqn. 3.32 >>DRGA = subs(RGA,'s',1j*w) % Substitute s = jω >> abs(subs(DRGA,w,1)) ans = 0.0379 0.9793 0.9793 0.0379

% Magnitude of the DRGA matrix at ω = 1 rad/s

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 diagram for 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.

Modelling

106

2

7

12

G = tf({2.5, 5; 1 -4}, ... {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 DRGA = NaN(size(Mag)); for i=1:length(w) K = Mag(:,:,i).*sK; DRGA(:,:,i) = K.*(inv(K))'; end

% Gain, including signs % Λ(ω) = K ⊗ K−T

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 offdiagonal terms start to dominate.

1 λ

1,1

λ1,2

0.8 0.6 0.4 0.2

Figure 3.15: The diagonal and off-diagonal elements of the RGA matrix as a function of frequency.

0 −3 10

−2

−1

10

10 frequency

0

1

10

10

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.

2.5 2

λ11 λ22

elements of Λ(ω)

1.5 1 0.5

λ23

0

λ13

−0.5 −1

Figure 3.16: The elements of the (3 × 3) RGA matrix from Eqn. 3.25.

Diagonal elements

λ33

−1.5 −3 10

Off−diagonal elements

λ12 −2

10

−1

10 frequency

0

10

1

10

3.4. REGRESSING EXPERIMENTAL DATA BY CURVE FITTING

107

3.4 Regressing experimental data by curve fitting 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 fitted, or at least fine-tuned to experimental data. Generally the following three steps are necessary: 1. Collect N experimental independent xi , and dependent yi 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 fit”, 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 performance index as, N X 2 (yi − yˆi ) (3.33) J = i=1

where the ith model prediction, yˆi is a function of the model, parameters and input data, yˆi = f (M(θ), xi )

(3.34)

We want to find the “best” set of parameters, i.e. the set of θ that minimises J in Eqn. 3.33, ⋆

θ = arg min θ

(

N X i=1

2

(yi − yˆi )

)

(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 difficulty 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 assumptions, and typically gives good results.

3.4.1 Polynomial regression An obvious way to fit smooth curves to experimental data is to find 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 xn + θn−1 xn−1 + · · · θ1 x + θ0

(3.36)

Modelling

108

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   θn  θn−1       yˆi = xn xn−1 · · · x 1 ·  ...     θ1  θ0

(3.37)

or written in compact matrix notation

yˆi = xi θ where xi is the data row vector for the ith observation. If all n observations are stacked vertically together, we obtain the matrix system    n  x1 x1n−1 · · · x1 1 yˆ1 n−1  yˆ2   xn2 x1 · · · x2 1      (3.38)  ..  =  .. .. .. .. ..  θ  .   . . . . .  n−1 yˆN xnN xN · · · xN 1 {z } | X

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 M ATLAB 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 − θ ⊤ X⊤ y − y⊤ Xθ + θ⊤ 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θ which we can now solve for θ as

 −1 X⊤ y θ = X⊤ X {z } |

(3.40)

(3.41)

pseudo-inverse

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 fitting 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.  −1 The matrix X⊤ X 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 −1 X⊤ with the pseudo inverse command, cussed in [150, p928]. M ATLAB can compute X⊤ X pinv, enabling the parameters to be evaluated simply by typing theta = pinv(X)*y, although it is more efficient to simply use the backslash command, theta = X\y.

An example of polynomial curve fitting using least-squares Tabulated below is the density of air as a function of temperature. We wish to fit a smooth quadratic curve to this data. Temperature [◦ C] Air density [kg/m3 ]

−100 1.98

−50 1.53

0 1.30

60 1.067

100 0.946

160 0.815

250 0.675

350 0.566

2.5

2

3

Air density, [kg/m ]

Raw Data fitted curve

1.5

1

0.5 −200

0

200

Temperature [°C]

Figure 3.17: The density of air as a function of temperature. Experimental data, •, and a 400 fitted quadratic curve. (See also Fig. 3.18 following for a higher-order polynomial fit.)

To compute the three model parameters from the air density data we can run the following m-file. Listing 3.3: Curve fitting using polynomial least-squares T = [-100 -50 0 rho = [1.98, 1.53, 1.30,

5

X = vander(T); X = X(:,end-2:end); theta = X\rho;

60 100, 160 250 350]'; % Temperature, T 1.067 0.946, 0.815, 0.675, 0.566]'; % Air density, ρ

% Vandermonde matrix % Keep only last 3 columns % Solve for θ, where ρˆ = θ1 T 2 + θ2 T + θ3

Ti = linspace(-130,400);

% validate with a plot

Modelling

110

10

rho_pred = polyval(theta,Ti); 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 M ATLAB 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 θ. M ATLAB ’ S 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 = UΣV⊤

(3.43)

where due to the orthogonality, UU⊤ = I = U⊤ U

VV⊤ = I = V⊤ V

and

(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 significantly from zero is the rank of T. We can make one further modification 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 ⊤







X G GXθ = X G Gy def

(3.45) (3.46)

def

Now we define T = GX and z = Gy gives T⊤ Tθ = T⊤ z

(3.47)

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

VΣU⊤



 UΣV⊤ θ = VΣU⊤ z 2



VΣ V θ =

(3.48) (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 ⊤

VV | {z } θ = VΣ

−1

(3.50) ⊤

U z

(3.51)

identity

⊤ θ = |VΣ−1 {z U } z

(3.52)

pseudo inverse

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, UΣV⊤ = X theta2 = V*(S\U')*rho % θ = VΣ−1 U⊤ , Eqn. 3.52.

It does not take much for the troublesome XT X matrix to get ill-conditioned. Consider the temperature/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 fit a polynomial in much the same way we did in Listing 3.3. However as shown in Fig. 3.18, we cannot reliably fit a fifth-order polynomial using standard least-squares to this data set, although we can reliably fit such a 5th-order polynomial using the SVD strategy of Eqn. 3.52. Note that M ATLAB’s polyfit uses the reliable SVD strategy. Polynomial order = 5 3.5

3

Air density, [kg/m ]

3

Standard least−squares θ = (X ′ X)−1 X ′ y

Raw Data standard LS SVD fitted

2.5 LS using SVD θ = V Σ−1 U T y

2 1.5 1 0.5 0 100

200

300 400 500 Temperature [degrees Kelvin]

600

700

Figure 3.18: Fitting a high-order polynomial to some physical data, in this case the density of air as a function of temperature in degrees Kelvin. Experimental data, a fitted quintic curve using standard least squares, and one using the more robust singular value decomposition. (See also Fig. 3.17.)

A further refined 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.

Modelling

112

Problem 3.3 Accuracy and numerical stability are very important when we are dealing with computed solutions. Suppose we wish to invert   1 1 A= 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 identification If the model equation is nonlinear in the parameters, then the solution procedure to find the optimum 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. M ATLAB provides a simple unconstrained optimiser, fminsearch, which uses the Nelder-Mead simplex algorithm. A collection of more robust algorithms and algorithms to optimise constrained systems possibly with integer constraints is the O PTI toolbox5 .

A nonlinear curve-fitting 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 αt (3.53) y= βt + 1 Suppose we have some experimental data for a particular reaction given as time, t cell count, y

0 0

0.2 1.2

0.5 2.1

1 2.43

1.5 2.52

2 2.58

2.5 2.62

where we wish to estimate the parameters α and β in Eqn 3.53 using nonlinear optimisation techniques. 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 transform 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

O PTI 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/β. 3.5

Assuming we have the experimental data stored as column vectors [t,y] in M ATLAB, we could plot

3

cell count y

t = [0, 0.2, 0.5:0.5:2.5]'; y = [0,1.2,2.1,2.43,2.52,2.58,2.62]'; % ignore divide-by-zero plot(y./t,y,'o-')

3

2.5

2

1.5

1

0

1

2

3 y/t

4

5

6

which should given an approximately straight line (ignoring the first and possibly the second points). To find the slope and intercept, we use the polyfit function to fit a line and we get a slope = −0.2686 and intercept = 2.98. This corresponds to α = 11.1 and β = 3.723. Now we can refine these estimates using the fminsearch Nelder-Mead nonlinear optimiser. We must first construct a a small objection function file 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 fitting using a generic nonlinear optimiser 1

6

% 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. plot(t,y,'o',t, theta(1)*t./(theta(2)*t+1)) % Check final fit in Fig. 3.19.

Listing 3.5 returns the refined estimates for θ as     α 12.05 ˆ= θ = β 4.10 and a comparison of both the experimental data • and the model’s predictions is given in Fig. 3.19. Curve fitting using the O PTI optimisation toolbox The M ATLAB O PTIMISATION toolbox contains more sophisticated routines specifically intended for least-squares curve fitting. 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 O PTI toolbox that solves least-squares regression problems. Listing 3.6: Curve fitting using the O PTI optimisation toolbox. (Compare with Listing 3.5.) >> theta0 = [11,3]';

% Initial guess θ 0

Modelling

114

3

cell count

2.5 2 1.5 1

Figure 3.19: The fitted (dashed) and experimental, •, data for a bio-chemical reaction. The asymptotic final cell count, α/β, is given by the dashed horizontal line.

4

Exptal data Best fit curve α/β

0.5 0

0

0.5

1

1.5

2

2.5

time

>> F = @(x,t) x(1)*t./(x(2)*t+1); % f (θ, t) = θ1 t/(θ2 t + 1) >> >> theta = opti_lsqcurvefit(F,theta0,t,y) 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 fit routine, opti_lsqcurvefit.

Higher dimensional model fitting Searching for parameters where we have made two independent measurements is just like searching 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 difficult, but changes nothing in the general technique. We will aim to fit 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 find something like table 3.4. Fig. 3.20(a) graphically illustrates the Table 3.4: Density of compressed water, (ρ × 10−3 kg/m3 ) Pressure (bar) 100 221.2 500 1000

0.01 1.0050 1.0111 1.0235 1.0460

100 0.9634 0.9690 0.9804 1.0000

Temperature, ◦ C 200 250 300 0.8711 0.8065 0.7158 0.8795 0.8183 0.7391 0.8969 0.8425 0.7770 0.9242 0.8772 0.8244

350 — 0.6120 0.6930 0.7610

374.15 — — 0.6410 0.7299

strong temperature influence on the density compared with pressure. Note how the missing data represented by NaNs in M ATLAB 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 density (kg/m3)

1100 1000

1000

900

950

850

800

1000

775

900 Pressure (bar)

True density kg/m

3

1100

900 850 800 800

700 600 0

1000 100 200

500

Temperature, C

600 500

750

400

700

300

700 700

200

650

300 °

700

1e+003 1e+003

1e+003

925 925

850

775

100

400

0

Pressure (bar)

0

50

(a) True density of compressed water as a function of temperature and pressure.

100

150 200 250 Temperature (deg C)

300

350

400

(b) Model fit

Figure 3.20: A 2D model for the density of compressed water. In Fig. 3.20(b), the • mark experimental data points used to construct the 2-D model given as contour lines. model structure is

  c b ρ = P exp a + + 3 T T k

(3.54)

where the constants (model parameters θ) need to be determined. We define 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 file 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 difficult to know appropriate starting guesses for θ, and the missing data must eliminated before the optimisation. Before embarking on the full nonlinear minimisation, I first try a linear fitting 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

4

9

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 + Tb + Tc3 J_rhowat = @(a,P,T,rho) ... P 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; ... 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/m3 [TT,PP] = meshgrid(T+273,P); Tv = TT(:); Pv = PP(:); % vectorise

Modelling

116 14

A = [ones(size(Tv)), 1.0e2 ./Tv, 1.0e7 ./Tv.ˆ3, log(Pv)]; % Scaled data matrix idx = isnan(rhof(:)); % find missing data points rhofv = rhof(:); rhofv(idx) = []; % remove bad points Tv(idx) = []; Pv(idx) = []; A(idx,:) = []; theta = A\log(rhofv); % first (linear) estimate

19

% Do nonlinear fit theta_opt = fminsearch(@(theta) J_rhowat(theta,Pv,Tv,rhofv),theta);

24

[Ti,Pi] = meshgrid([0.01:10:370]+273,[100:100:1000]); % Compare fit with data 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 temperature derived from the experimental data and the fitted 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 5.5383  b   5.8133 · 102     θ⋆ =  (3.56)  c  =  −1.8726 · 107  k 0.0305

3.4.3 The confidence of the optimised parameters Finding the optimum model parameters to fit the data is only part of the task. A potentially more difficult objective is to try to establish how precise these optimum parameters are, or what the confidence regions of the parameters are. simply expressing the uncertainty of your model as parameter values ± some interval is a good first approximation, but it does neglect the interaction of the other parameters, the so-called correlation effect. To establish the individual confidence 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 X centered about the optimised parameters. 3. The measurement noise sY¯i (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 confidence interval (90%, 95% etc) and degrees of freedom. This is easily obtained from statistical tables or using the qt routine from the S TIXBOX collection mentioned on page 3 for m-file implementations of some commonly used statistical functions. The confidence interval for parameter θi is therefore θi ± t(1−α/2) sY¯i

p Pi,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 Pi,i are the diagonal elements of the covariance matrix P. The measurement noise (if not already approximately known) is s p ǫ⊤ ǫ sY¯i ≈ s2r = (3.58) n−m

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 confidence intervals for a nonlinear model This section was taken from [87, p198], but with some modifications and corrections. Himmelblau, [87, p198], gives some reaction data as: Pressure, p rate, r

20 0.068

30 0.0858

35 0.0939

40 0.0999

50 0.1130

55 0.1162

60 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 program to search for the parameters θ such that the sum of squared error is minimised. min = θ

n X i=1

 (ri − 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 find that the optimum parameters are approximately     5.154 · 10−3 θ0 = (3.61) θ= 2.628 · 10−2 θ1 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; −θ0 p2 ∂r = ∂θ1 (1 + θ1 p)2

∂r p = , ∂θ0 1 + θ1 p and the data matrix X is defined as def

Xi,j =

∂ri ∂θ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 defined as def

P=



−1 X⊤ X

(3.63)

and should be positive definite 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 confidence limits. When using M ATLAB, it is better to look at the singular values, or check the rank of X⊤ X before doing the inversion. Listing 3.8 fits parameters to the nonlinear reaction rate model and also illustrates the uncertainties.

Modelling

118 Listing 3.8: Parameter confidence limits for a nonlinear reaction rate model 1

6

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 θ0 p Rxn_rate = @(x,p) x(1)*p./(1+x(2)*p); % r = 1+θ 1p theta = lsqcurvefit(Rxn_rate,[5e-3 2e-2]',p,r); % Refine estimate of parameters θ nobs = length(p); mpar = length(theta); % # of observations & parameters

r_est = Rxn_rate(theta,p);% Predicted reaction rate rˆ(θ, p) P j = sum((r-r_est).ˆ2); % sum of squared errors J = i ǫ2 11

16

21

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 pt = @(x,v) (x≥0).*(1-0.5*betainc(v./(v+x.ˆ2),v/2,0.5)) + ... (x>G_est= pem(Zdata,'na',2,'nb',2,'nc',2,'nk',1);% Estimate A(q −1 ), B(q −1 ) & C(q −1 ) >>G_est= armax(Zdata,'na',2,'nb',2,'nc',2,'nk',1)% Alternative to using pem.m 4

9

>>present(G_est) % present results G_est = Discrete-time ARMAX model: A(z)y(t) = B(z)u(t) + C(z)e(t) A(z) = 1 - 1.416 zˆ-1 + 0.514 zˆ-2 B(z) = 1.209 zˆ-1 + 0.2935 zˆ-2 C(z) = 1 + 0.7703 zˆ-1 - 0.1181 zˆ-2

14

>>yp = sim(G_est,[u e]); % form prediction >>plot([y yp]) % check prediction performance in Fig. 6.53(a).

Fig. 6.53(a) compares the true and predicted output data. In this case the fit is not perfect even though we used the correct model structure which is partly due to the iterative nature of the nonlinear regression, but mostly the poor fit is due to the fact that we used only 100 input/output samples. If we used 10,000 samples for the fitting, we will estimate a far superior model as illustrated in Fig. 6.53(b). It is interesting to note just how many input/output samples we need to estimate a relatively modest sized system of only 6 parameters. Listing 6.22 repeats this estimation, but this time does it recursively in M ATLAB. Listing 6.22: Recursively identify an ARMAX process. 1

A = [1 -0.4 0.5]; B = [1.2, 0.3]; C = [1, 0.8 -0.1]; % True plant to be estimated

CHAPTER 6. IDENTIFICATION OF PROCESS MODELS

304 10

Actual Estimated

output

5 0

estimated

−5 −10 actual −15

0

20

40

60

80

100

(a) Identification using only 100 data points 10 Actual Estimated

5

output

0 −5 −10 −15 −20

0

10

20

30

40 50 60 sample interval

70

80

90

100

(b) Identification using 10,000 data points

Figure 6.53: A validation plot showing the actual plant output (solid) compared to the model predictions (dashed line) of an ARMAX model using nonlinear parameter estimation. Note that to obtain good results, we need a long data series.

na = length(A); nb = length(B); nc = length(C); % Order of the polynomials+1 d = na-nb; % deadtime 6

11

Npts = 5e4; u = randn(Npts,1); a = randn(Npts,1); y = zeros(Npts,1); err = y; thetaAll = [];

% dummy

np = na+nb+nc - 2; % # of parameters to be estimated theta = randn(np,1); P = 1e6*eye(np); % initial guess of θ lambda = 1; % forgetting factor, λ ≤ 1 for i=na:Npts; y(i)= -A(2:end)*y(i-1:-1:i-na+1)+ B*u(i-d:-1:i-nb+1-d)+ C*a(i:-1:i-nc+1);

16

phi = [-y(i-1:-1:i-na+1)', u(i-d:-1:i-nb+1-d)', err(i-1:-1:i-nc+1)']'; err(i,1) = y(i) - phi'*theta; % estimated noise sequence

21

K = P*phi/(lambda + phi'*P*phi); % update gain P = (P-(P*phi*phi'*P)/(lambda + phi'*P*phi))/lambda; % covariance update theta = theta + K*err(i,1); % update θ thetaAll(i,:) = theta';

6.10. ONLINE ESTIMATING OF NOISE MODELS

305

end 26

Aest = [1, thetaAll(end, 1:na-1)]; Best = thetaAll(end, na:na+nb-1); Cest = [1, thetaAll(end,na+nb:end)]; % See Fig. 6.54.

As shown in Fig. 6.54, the estimates do eventually converge to the correct values without bias, and furthermore, the step response of the final estimate compares favourably with the true step response.

RELS: λ=0.9990 2

Model at k=4e4 5

0

1.5

Estimated Actual −5 0

1

5

10

15

20

25

(seconds)

c2 b Parameter estimates

2

0.5 a3 b3 b1 c

0

3

−0.5 Model at k=2e4

−1

3

a

2

2

−1.5

1

Estimated Actual

0 0

−2

5

10

15

20

25

(seconds)

0

1

2

3 sample time [k]

4

5 4

x 10

Figure 6.54: Recursive extended least-squares estimation where there is an abrupt model change at time k = 2 · 104. The inserted figures compare a step response of the true plant with the current estimate.

6.10.2 Recursive identification using the SI toolbox The System Identification toolbox can also calculate the parameter estimates recursively. This essentially duplicates the material presented in §6.7.1. However in this case there are many more options to choose from regarding type of method, numerical control, starting point etc. The toolbox has a number of recursive algorithms (See [125, p 1–64]) but they all work in the same way. For most demonstration purposes, we will recursively estimate the data pseudo online. This means that we will first generate all the data, and then estimate the parameters. However we will make sure that when we are processing element i, the data ahead in time, elements i + 1 . . ., are not available. This pseudo online approach is quite common in simulation applications. The Toolbox command that duplicates the recursive least squares estimation of a ARMAX process with a forgetting factor is rarmax(z,nn,’ff’,0.95).

CHAPTER 6. IDENTIFICATION OF PROCESS MODELS

306

6.10.3 Simplified RLS algorithms The standard recursive least squares (RLS) algorithm such as presented in §6.7.1 requires two update equations;– one for the update gain, and one for the covariance matrix. But for implementation in a small computer, there is some motivation to simplify the algorithm, even at the ˚ om expense of the quality of parameter estimates. Astr ¨ and Wittenmark, [17, p69-70] describe one such method known as Kaczmarz’s projection algorithm. The input/output relation is assumed yk = ϕk θk where θ is the parameter vector and ϕ is the row data vector, and the correction to the estimated parameter vector is ˆk = θ ˆ k−1 + α ϕ⊤ θ k ˆ k which gives the full updating formula in our now familiar where α is chosen such that yk = ϕk θ form as   T ˆk = θ ˆ k−1 + ϕ ˆ θ (6.78) y − ϕ θ k k k−1 ϕk ϕT

Note that in [17], there is some nomenclature change, and that the data vector is defined as a column vector, where here I have assumed it is a row vector. This update scheme (Eqn 6.78) is sometimes modified to avoid potential problems when the parameter vector equals zero.

The script in listing 6.23 first generates data from an ARX plant, and then the data is processed pseudo-online to obtain the estimated parameters. Listing 6.23: Kaczmarz’s algorithm for identification u = randn(50,1); 3

8

% random input

A = [1 -1.25 0.8]; B = 0.3; % G = 0.3/(1 − 1.25q −1 + 0.8q −2 ) G = idpoly(A,B,1); y = sim(G,u); theta = randn(3,1);% Initial parameter estimate, θ 0 , is random Param = []; % estimated parameters so far for i=4:length(u); phi= [-y(i-1:-1:i-2)', u(i)]'; % regressor vector, ϕk   ˆk ← θ ˆ k−1 + ϕTk yt − ϕT θ ˆ theta=theta+phi*(y(i)-phi'*theta)/(phi'*phi); % θ k k−1 ϕk ϕ Param= [Param; theta']; % collect parameters end %

13

Param_x = ones(size(Param(:,1)))*([A(2:3) ,B(1)]); % true parameters plot([Param_x, Param]) % have they converged ?

The input/output data (top) and parameters from this data are shown in Fig. 6.55. The estimated parameters converge relatively quickly to the true parameters, although not as quickly as in the full recursive least-squares algorithm. Problem 6.3 The following questions use input/output data from the collection of ‘classic’ time series data available from the time series data library maintained by Rob Hyndman at: www-personal.buseco.monash.edu.au/˜hyndman/TSDL/ or alternatively from the DAISY: D ATABASE FOR THE I DENTIFICATION OF S YSTEMS collection maintained by De Moor, Department of Electrical Engineering, ESAT/SISTA, K.U.Leuven, Belgium at www.esat.kuleuven.ac.be/sista/daisy/.

Input & output

6.11. CLOSED LOOP IDENTIFICATION

307

5

0

−5 1 Estimated & true parameters

a2 0.5 b

0

0

−0.5

−1 a

1

−1.5

0

10

20 30 sample time

40

50

Figure 6.55: The performance of a simplified recursive least squares algorithm, Kaczmarz’s algorithm. Upper: The input/output data. Lower: The estimated parameters (solid) eventually converge to the true parameters (dashed).

These collections are useful to test and verify new identification algorithms. Original sources for this data include [32] amongst others. 1. The data given in /industry/sfbw2.dat shows the relationship in a paper making machine between the input stock flow (gal/min) and basis weight (lb/3300 ft2 ), a quality control parameter of the finished paper. Construct a suitable model of this time series. Ref: [156, pp500–501]. 2. This problem is detailed and suitable for a semester group project. An alternative suite of programs to aid in model development and parameter identification is described in [32, Part V]. The collection of seven programmes closely follows the methodology in the text, and are outlined in pseudo-code. Construct a T IME S ERIES A NALYSIS toolbox with graphics based around these programs. Test your toolbox on one of the time series tabulated in the text. A particularly relevant series is the furnace data that shows the percentage of carbon dioxide output from gas furnace at 9 seconds intervals as a function of methane input, (ft3 /min), [32, Series J, pp532–533]. This input/output data is reproduced in Fig. 6.56, although the input methane flowrate is occasionally given as negative which is clearly physically impossible. The original reference footnoted that the unscaled data lay between 0.6 and 0.04 ft3 /min.

6.11 Closed loop identification The identification techniques described this far assume that the input signal can be chosen freely and that this signal has persistent excitation. However if you are trying to identify while controlling, you have lost the freedom to choose an arbitrary input since naturally, the input is now constrained to give good control rather than good estimation. Under good control, the input will probably be no longer exciting nor inject enough energy into the process so that there is sufficient information available for the identification. Closed loop identification occurs when the process is so important, or hazardous, that one does not have the luxury of opening the control loop simply for identification. Closed loop identification is also necessary, (by definition), in many adaptive control algorithms.

308

CHAPTER 6. IDENTIFICATION OF PROCESS MODELS 65

% CO2

60 55 50 45

0

500

1000

1500

2000

2500

3000

0

500

1000

1500 time [s]

2000

2500

3000

Methane flow

4

Figure 6.56: The percent CO2 in the exhaust gas from a furnace as a function of the methane input (scaled). Data from [32, p532–533].

2 0 −2 −4

If we use a low order controller, then the columns of the data matrix X in Eqn. 6.20 become linearly dependent. This is easy to see if we use a proportional controller, ut = kyt , then this in turn creates columns in X that only differ by the constant controller gain k. In reality, any noise will destroy this exact dependency, but the numerical inversion may still be a computationally difficult task. One way to ensure that u(t) is still persistently exciting the process is to add a small dither or perturbation signal on to the input u. This noisy signal is usually of such a small amplitude, that the control is not seriously effected, but the identification can still proceed. In some cases there may be enough natural plant disturbances to make it unnecessary to add noise to u. With this added noise, added either deliberately or otherwise, the estimation procedure is the same as described in § 6.7. The above arguments seems to suggest that closed loop identification is suboptimal, and that if possible, one should always try to do the identification in open loop, design a suitable controller, then close the loop. This avoids the possible ill-conditioning, and the biasing in the estimated parameters. However Landau in a series of publications culminating in [112] argues that in fact closed loop control, with suitable algorithms, actually develops better models since the identification is constrained to the frequencies of interest for good closed loop control. It all depends in the final analysis on whether we want a good model of the plant for say design in which case we do the identification in open loop, or if we want good control in which case closed loop identification may be better. A very readable summary of closed loop identification is given in [93, pp517–518], [17, p82] and especially [200]. Identification in the closed loop is further discussed in chapter 7.

6.12. SUMMARY

309

6.11.1 Closed loop RLS in Simulink Implementing recursive identification using S IMULINK is not as straight forward as writing raw M ATLAB code because of the difficulty in updating the parameters inside a transfer function block. Under normal operation these are considered constant parameters within the filter block, so it is not a problem. Fig. 6.57 shows the closed loop estimation using the same RLS blocks as those used in Fig. 6.42 on page 289. In this example the identified parameters are not used in the controller in any sort of adaptive manner, for that we need an adaptive controller which is the subject of the following chapter.

theta

5

phi

5

P

y(k)

phi generator

Plant i/o data

y

u

uy

theta

phi1

5

5 5

[5x5]

theta Parameters

P Covariance

RLS

3

u

Signal Generator

PID

Gd

PID Controller

Unknown plant

y

y

Figure 6.57: Closed loop estimation using RLS in S IMULINK. See also Fig. 6.42.

6.12 Summary System identification is where we try to regress or fit parameters of a given model skeleton or structure to fit input/output data from a dynamic process. Ideally we would obtain not only the values of the parameters in question, but also an indication of the “goodness of fit”, and the appropriateness of the model structure to which the parameters are fitted. Identification methodologies usually rely on a ‘trial & error’ approach, where different model structures are fitted, and the results compared. The S YSTEM I DENTIFICATION T OOLBOX within M ATLAB, [125], is a good source of tools for experimentation in this area, because the model fitting and analysis can be done so quickly and competently. Identification can also be attempted online, where the current parameter estimate is improved or updated as new process data becomes available in an efficient way without the need to store all the previous historical data. We do this by re-writing the least-squares update in a recursive algorithm. Updating the parameters in this way enables one to follow time-varying models or even nonlinear models more accurately. This philosophy of online estimation of the process model is a central component of an adaptive control scheme which is introduced in chapter 7. However there are two key problems with the vanilla recursive least-squares algorithm which become especially apparent when we start to combine identification with adaptive control. The first is the need to prevent the covariance matrix P from being illconditioned. This can, in part be solved by ensuring persistent excitability in input. The second problem is that given non-white noise or coloured noise, the RLS scheme will deliver biased estimates. However, there are many extensions to the standard schemes that address these and other identification issues. Succinct

310

CHAPTER 6. IDENTIFICATION OF PROCESS MODELS

summaries of system identification with some good examples are given in [22, pp422–431] and [148, p856], while dedicated texts include [124, 188, 200].

6.12. SUMMARY

311

Problems Problem 6.4 An identification benchmark problem from [109]. 1. Simulate the second-order model with external disturbance vt , yt =

2 X

ai yt−i +

i=1

2 X

bi ut−i +

2 X i=1

i=0

di vt−i + e(t), e(t) ∼ N (0, σ 2 )

(6.79)

where the parameter values are: a1 0.98

a2 −0.9

b0 0.5

b1 −0.25

b2 0.1

d1 0.8

d2 0.2

σ 0.1

The input ut is normally distributed discrete white noise, and the external disturbance is to be simulated as a rectangular signal alternating periodically between the values +1 and −1 at t = 100, 200, . . . Run the simulation for 600 time steps, and at t = 300, change a1 to −0.98. 2. This is a challenging identification problem, because the rarely varying external disturbance signal gives little information about the parameters d. Identify the parameters in Eqn. 6.79 ˆ 1|0 = 0, P1|0 = 50I and using an exponential forgetting factor, λ = perhaps starting with θ 0.8. Problem 6.5 1. Run through the demos contained in the S YSTEM I DENTIFICATION toolbox for M ATLAB. 2. Investigate the different ways to simulate a discrete plant with a disturbing input. Use the model structure A(q −1 )yt = B(q −1 )ut + C(q −1 )et Choose a representative stable system, say something like A(q −1 ) = 1 − 0.8q −1 ,

B(q −1 ) = 0.5,

C(q −1 ) = 1 + 0.2q −1

and choose some sensible inputs for ut and et . Simulate the following and explain any differences you find. (a) Write your own finite difference equation in M ATLAB, and compare this using filter. (b) Use the transfer function object, tf, in MISO (multiple input/single output) mode. Hint: Use cell arrays as >>G = tf( {B ,C} , {A,A},T); % discrete version >>G.variable = ’q’;

(c) Use idpoly and idmodel/sim from the S YSTEM I DENTIFICATION toolbox. (d) Build a discrete S IMULINK model Hint: You may find problems due to the differing lengths of the polynomials. Either ensure all polynomials are the same length, or swap from z −1 to z, or introduce delays. 3. Repeat problem 2 with an unstable model (A is unstable.) 4. What is the difference in S IMULINK when you place the A polynomial together with the B and C polynomials? Particularly pay attention to the case where A is unstable.

312

CHAPTER 6. IDENTIFICATION OF PROCESS MODELS

5. Identification of plants that include coloured noise inputs is considerably more complex than just using arx. The following illustrates this. (a) Create a ‘truth’ plant with polynomials, A, B, C. (Use idpoly). (b) Simulate this plant using idmodel/sim for the following two cases: i. A noise-free version: i.e. random u(t) and no e(t) ii. A version with coloured noise: i.e. random u(t), e(t). (c) Estimate an ARX model (i.e. only A, B polynomials) using both data sets. ‘Present’ the model with uncertainty bounds on the estimated parameters using present. What was the problem with the coloured noise version and how can we avoid it? (d) Estimate the A, B and C polynomials using an extended-LS scheme such as armax or pem. Has the identification improved significantly? How did the computational time change from using to arx to armax?

6. The D AISY (Data Base for the Identification of Systems), [135], located at www.esat.kuleuven.ac.be/sist and contains a number of simulated and experimental multivariable data sets. Down load one of these data sets, preferably one of the real industrial data trends, and make an identification. 7. RLS with modified forgetting factors Construct a simulation to estimate the parameters in a dynamic model (as in tident.m) to test various extensions to the forgetting factor idea. Create a simulation with output noise, and step change the model parameters part way through the run. (For more information on these various extensions, see [200, pp140–160].) (a) Use a start-up forgetting factor of the form 

λ1 (t) = λ0 + (1 − λ0 ) 1 − exp



−t τf



(6.80)

where λ0 is the initial forgetting factor, (say 0.9–0.95), and τf is the time constant that determines how fast λ(t) approaches 1.0. Note that Eqn. 6.80 can be re-written in recursive form as λ1 (t) = αλ1 (t − 1) + (1 − α) where α = e−1/τf and λ1 (0) = λ0 . (b) Combine with the start-up forgetting factor, an adaptive forgetting factor of the form   τf ǫ2 (t) λ2 (t) = 1− (6.81) τf − 1 τf sf (t) where sf (t) is a weighted average of past values of the squared error ǫ2 . [200, p159] suggest using the filter sf (t) =

ǫ2 τf − 1 sf (t − 1) + τf τf

Combine both the start-up and the adaptive forgetting factor to get a varying forgetting factor λ(t) = λ1 (t)λ2 (t). (c) A directional forgetting factor tries to update in only those directions in parameter space where there is information available. The covariance update with directional forgetting is " # xt x⊤ t Pt−1 Pt = Pt−1 I − −1 (6.82) rt−1 + x⊤ t Pt−1 xt

6.12. SUMMARY

313

where the directional forgetting factor r(t) is rt = λ′ −

1 − λ′

x⊤ t+1 Pt xt+1

(6.83)

and the scalar λ′ is like the original fixed forgetting factor.

What ever happened to elegant solutions? 8. Compare the operation count of the RLS scheme with square root updates with the normal update. Construct a sufficiently ill-conditioned example where you can demonstrate a significant difference. Summary of the RLS square root update scheme for y = ϕT θ. Define the square root of P as def

P = SST Update St by following f t = STt−1 ϕt βt = 1 + f T f 1 √ αt = βt + βt Lt = St−1 f t St = St−1 − αt Lt f Tt Update the parameter estimates using θ t+1 = θt +

 Lt yt − ϕT θt βt

9. Modify the square root RLS scheme to incorporate a forgetting factor.

314

CHAPTER 6. IDENTIFICATION OF PROCESS MODELS

10. Construct an RLS update algorithm in S IMULINK, perhaps using the matrix/vector blocks in the DSP blockset. Use the following update equations: " # ϕk+1 ϕTk+1 Pk Pk ϕk+1 Kk+1 = , Pk+1 = Pk I − 1 + ϕTk+1 Pk ϕk+1 1 + ϕTk+1 Pk ϕk+1  θk+1 = θk + Kk+1 yk+1 − ϕTk+1 θ k Note that as of Matlab R12, there is considerable support for vector/matrix manipulations in raw S IMULINK.

11. Construct a square root update algorithm (from Problem 8) in S IMULINK, perhaps using the matrix/vector blocks in the DSP blockset. 12. Wellstead & Zarrop, [200, p103], develop an expression for the bias as a function of the model parameters for a simple 1-parameter model yt = ayt−1 + et + cet−1 ,

|a| < 1,

|c| < 1

where et is white noise with variance σe2 , as a ˆ−a≈

c(1 − a2 ) 1 + c2 + 2ac

(a) Validate with simulation the expression for the size of the bias, a − a ˆ.

(b) The size of the bias should not be a function of the size of the variance of et . Is this a surprising result? Verify this by simulation. What happens if you drop the variance of the noise, σe2 , to zero? Do you still observe any bias? Should you? 13. Starting with the S IMULINK demo rlsest which demonstrates an adaptive pole-placement of a discrete plant do the following tasks. (a) Modify the rlsest simulation to use a continuous plant of your choice and, for the moment, a fixed (non-adaptive) PID controller. (I.e. disconnect the closed-loop adaption part of the controller.) Use Fig. 6.58 as a guide to what you should construct. Explain in detail how the state generator works and how the RLS estimator works. Modify the blocks so that you can identify a different number of A terms from the B terms, (such as say two B(q −1 ) and three A(q −1 ) polynomials terms). (b) Run the estimation routine under closed-loop conditions. What do you observe especially as you change the noise level? (To be realistic, you should add at least one more noise source, where ?) (c) Modify the RLS estimator s-function to export the covariance matrix as well as the updated parameters. Do these confirm your findings from part 13b? (d) Modify your RLS scheme to better handle noise and the closed loop conditions. You may like to use some simple heuristics based on the trace of the covariance matrix, or use a directional and/or variable forgetting factor. 14. Read the M ATLAB Technical support note #1811 How Do I Create Time Varying Matrix Gain and State-space Blocks as C MEX S-functions?. Download the relevant files and implement an adaptive controller. 15. Model identification in state-space with state information. The English mathematician Richardson has proposed the following simple model for an arms race between two countries: xk+1 = axk + byk + f

(6.84)

yk+1 = cxk + dyk + g

(6.85)

6.12. SUMMARY

315

theta To Workspace1 RLS Estimator parameters Recursive least squares Parameter Estimator phi Clock1

t time

State Generator

yr To Workspace

ZOH

ZOH1

Mux spt/plant

Setpoint

+ −

PID

u[n]

PID Controller

3(s+0.3) (s+2)(s+1)(s+0.4) plant

y[n] + + Sum1

distrurbance

Figure 6.58: A modified version of rlsest in Simulink. where xk and yk are the expenditures on arms of the two nations and a, b, c, d, f and g are constants. The following data have been compiled by the Swedish International Peace Research Institute, (SIPRI yearbook 1982). Millions of U.S. dollars at 1979 prices and 1979 exchange rates

year 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981

Iran 2891 3982 8801 11230 12178 9867 9165 5080 4040

Iraq 909 1123 2210 2247 2204 2303 2179 2675

NATO 216478 211146 212267 210525 205717 212009 215988 218561 225411 233957

WTO 112893 115020 117169 119612 121461 123561 125498 127185 129000 131595

(a) Determine the parameters of the model and investigate the stability of this model. (b) Determine the estimate of the parameters based on 3 consecutive years. Look at the variability of the estimates. (c) Create a recursive estimate of the parameters. Start with 1975 with the initial values determined from 1972–74.

316

CHAPTER 6. IDENTIFICATION OF PROCESS MODELS

Chapter 7

Adaptive Control Adopt, adapt and improve . . . Motto of the round table. John Cleese whilst robbing a lingerie boutique.

7.1 Why adapt? Since no one yet has found the “holy grail” of controllers that will work for all conceivable occasions, we must not only select an appropriate class of controller, but also be faced with the unpleasant task of tuning it to operate satisfactorily in our particular environment. This job is typically done only sporadically in the life of any given control loop, but in many cases owing to equipment or operating modifications, the dynamics of the plant have changed so as to render to controller sub-optimal. Ideally the necessary re-tuning could be automated, and this is the idea behind an adaptive controller. In a control context, adaption is where we adjust the controller as the process conditions change. The problem is that for tight control we essentially want to have a high feedback gain, giving a rapid response and good correction with minimal offset. However if the process dynamics subsequently change due to environmental changes for example, the high feedback gain may create an unstable controller. To prevent this problem, we adapt the controller design as the process conditions change, to achieve a consistently high performance. Adaptive control was first used in the aerospace industry around the late 1950s where automatic pilots adapted the control scheme depending on external factors such as altitude, speed, payload and so forth. One classic example was the adaptive flight control system (AFCS) for the X-15 in the late 1960s described in [7]. The adaptive control system was developed by Honeywell and was fundamentally a gain scheduler that adapted the control loop gains during the flights that ranged from sea level to space at 108 km. Unfortunately the crash of X-15-3 and loss of pilot Michael Adams in 1967 somewhat terminated the enthusiasm of adaptive flight control, and the research program was terminated shortly afterwards. In the past couple of decades however, adaptive control has spread to the processing industries with several commercial industrial adaptive controllers now available. Some applications where adaptive control is now used are: 317

CHAPTER 7. ADAPTIVE CONTROL

318

Aeronautical control As the behaviour of high performance fighter aircraft depends on altitude, payload, speed etc, an adaptive control is vital for the flight to be feasible. Tanker steering The dynamics of oil supertankers change drastically depending on the depth of water, especially in relatively shallow and constricted water-ways. Chemical reactions Chemical processes that involve catalytic reactions will vary as the catalyst denatures over time. Often coupled to this, is that the heat transfer will drop as the tubes in the heat exchanger gradually foul. Medical The anesthetist must control the drug delivery to the patient undergoing an operation, avoiding the onsets of either death or consciousness.1 Some further examples of adaptive control are given in a survey paper in [180]. Adaptive control is suitable:

Adaptive control is not suitable if:

• if the process has slowly varying parameters

• PID control is already satisfactory

◦ if clean measurements are available

• The system output is essentially constant

• for batch processes or startup/shut down of continuous processes

• The system is essentially linear and time invariant

• for widely changing operating conditions (such as in pH controlled processes)

• If the system is nonlinear, but easy to model

7.1.1 The adaption scheme When faced with tuning a new control loop, the human operator would probably do the following steps: 1. Disturb the plant and collect the input/output data. 2. Use this data to estimate the plant dynamics. 3. Using the fitted model, an appropriate controller can be designed. 4. Update the controller with the new parameters and/or structure and test it. If the scheme outlined above is automated, (or you find an operator who is cheap and does not easily get bored), we can return to step 1, and repeat the entire process at regular intervals as shown in Fig. 7.1. This is particularly advantageous in situations where process conditions can change over time. The process and feedback controller are as normal, but we have added a new module in software (dashed box) consisting of an on-line identification stage to extract a process model M(θ), and given this model information, a controller design stage to find suitable controller tuning constants. Of course there will be some constraints if we were to regularly tune our controllers. For example, it is advisable to do the the estimation continuously in a recursive manner, and not perturb the plant very much. We could adapt the three tuning constants of a standard PID controller, or we could choose a controller structure that is more flexible such as pole-placement. The adaption module could operate continuously or it could be configured to adapt only “on demand”. In the latter case, once the tuning parameters have converged, the adaption component of the controller turns itself off automatically, and the process is now controlled by a constant-tuning parameter controller such as a standard PID controller. 1 One

particularly ambitious application is described in [52, p429].

7.2. GAIN SCHEDULING

319

Adaptive module

Control design 

Identify M(θ) *

Y

Update controller if necessary Measure input & output

? r(t) setpoint

+ -+

-

6−

-

controller u(t)

Plant, S

- y(t) output

Figure 7.1: The structure of an indirect adaptive controller

7.1.2 Classification of adaptive controllers As one may expect, there are many different types of adaptive control, all possessing the same general components, and an almost equal number of classification schemes. To get an overview of all these similar, but subtly different controllers, we can classify them according to what we adapt; Parametric adaption Here we continually update the parameters of the process model, or even controller, or Signal adaption where we vary a supplementary signal to be added directly to the output of the static controller. Alternatively we can classify them as to how we choose a performance measure, Static A static performance measure is one such as overall efficiency, or maximising production. Dynamic A dynamic performance measure is to optimise the shape of a response to a step test. Functional of states and inputs This more general performance index is discussed more generally in chapter 9.

7.2 Gain scheduling The simplest type of adaptive control is gain scheduling. In this scheme, one tries to maintain a constant overall loop gain, K by changing the controller gain, Kc in response to a changing process gain Kp . Thus the product Kc Kp is always constant.

CHAPTER 7. ADAPTIVE CONTROL

320

An example where gain scheduling is used is in the control of a liquid level tank that has a varying cross sectional area. Suppose we are trying to control the level in a spherical tank by adjusting a valve on the outlet. The exiting flow is proportional to the square root of height of liquid above the valve, which in turn is a nonlinear function of the volume in the tank. Fig. 7.2 shows how this gain varies as a function of material in the tank, illustrating why this is a challenging control problem. No single constant controller setting is optimal for both operating in the middle and the extremes of the tank.

1

p

Plant gain K ∝ h1/2

1.5

0.5 Vmax

Figure 7.2: The plant gain, Kp is proportional to the square toot of the hydraulic head which in turn is a nonlinear function of volume in the tank. Consequently the controller gain, Kc , should be the inverse of the plant gain.

Controller gain Kc

0 8 6 4 2 0

0

1

2 3 Volume

4 Vmax

5

A way around this problem is to make the controller parameter settings a function of the level (the measured variable, y). Here the controller first measures the level, then it decides what controller constants (Kc , τi , τd ) to use based on the level, and then finally takes corrective action if necessary. Because the controller constants change with position, the system is nonlinear and theoretical analysis of the control system is more complicated. To do this in practice one must: 1. Determine the open loop gain at the desired operating point and several points either side of the desired operating point. 2. Establish good control settings at each of these three operating points. (This can be done by any of the usual tuning methods such as Ziegler-Nichols, Cohen-Coon etc) 3. Generate a simple function (usually piecewise linear) that relates the controller settings to the measured variable (level). The gain scheduling described above is a form of open-loop or feedforward adaption. The parameters are changed according to a pre-set programme. If the tank is in fact different from the tank that was used to calculate the parameter adaption functions such as having a △ cross section, then the controller will not function properly. This is because the controller is not comparing its own system model with the true system model at any time. However despite this drawback, gain scheduling is an appropriate way to control things like tanks of varying cross sectional area. It is unlikely that the tank’s cross sectional area will change significantly with time, so the instrument engineer can be quite confident that the process once tuned, will remain in tune.

7.3. THE IMPORTANCE OF IDENTIFICATION

321

7.3 The importance of identification The adaptive controller (with feedback adaption) must be aware of the process, or more accurately it must be aware of changes in process behaviour — hence the importance of system identification covered in the previous chapter. Central to the concept of controllers that adapt, is an identification algorithm that constantly monitors the process trying to establish if any significant changes have occurred. In the gain schedular given in §7.2, the identification component was trivial, it was simply the level reading. The purists will argue that the gain schedular is not a true adaptive controller, because if the dynamics of the system change (such as the cross section of the tank suddenly varies), the controller is unaware of this change, and cannot take appropriate corrective action. There are two popular adaptive control techniques used currently in industry. The first approach is to use a controller with auto-tuning. Normally these controllers are operating in just the same manner as a traditional PID controller, but if the operator requests, the controller can be tuned automatically. This is sometimes called “tuning on demand”. Once the auto-tuning part is complete, the tuning procedure switches itself off and the controller reverts back to the traditional PID mode. These types of “adaptive controllers” are used where adaptive control is required, but the loop may be too sensitive or critical to have constant adaptation. The second approach to adaptive control is called true adaptive control. This is where the controller will adapt itself to the changing process without operator demand. Unlike the auto-tuners, the “true adaptive” control remains continuously identifying the process and updating the controller parameters. Many use variants of the least-squares identification that was described in §6.7. Industrially auto-tuners have been successful and are now accepted in the processing industries. Most of the major distributed computer control companies provide an adaptive control in the form of a self-tuner as part of their product (Satt Control, Bailey, ABB, Leeds-Northrup, Foxboro). ˚ om Astr ¨ and H¨agglund describe some of these auto-tuning commercial products in chapter 5 of [15, 105-132]. However the true adaptive control has not been accepted as much as the self-tuner. This is due to the fact that true adaptive control requires a higher level of expertise than self-tuning regulators. In addition, because the adaptive control is continuous, it requires a much larger safety network to guarantee correct operation. Even though the adaptive controller does not require “tuning”, the correct operation still requires estimates of values before the estimator can correctly function. These types of parameters are things such as expected model order, sampling period and expected dead time. If these values are significantly different from the true values, then poor adaption and hence control will result. Section 7.4 will consider self-tuning regulators.

7.3.1 Polynomial manipulations The controller design strategies in this section will use the so-called polynomial approach. In this design technique, we will need to be able to add and multiply polynomials, of possibly differing lengths. The two routines given in Appendix B on page 507 add and multiply polynomials and are used in the following controller design scripts in this chapter. An alternative programming methodology is to create a polynomial object and then overload the plus and times operators.

CHAPTER 7. ADAPTIVE CONTROL

322

7.4 Self tuning regulators (STRs) A better adaptive controller than a gain schedular is one where the controller parameters are continually updated as the process characteristics change with time in an undetermined manner. These are called self tuning regulators and an early application was in the pulp and paper industry controlling a paper machine cited in [9]. Further development culminating in the self tuning regulator is described in the classic reference, [12]. Self tuning regulators are more flexible than gain scheduling controllers, which to be effective, the relation between the input and output must be known beforehand and is assumed constant. A textbook covering many aspects of the design and use of self tuning regulators is [200]. The basic elements of a self tuning regulator are: 1. Identify the model online using input-output data. Usually the model is estimated by using a recursive least squares parameter estimation. 2. A relation between the model parameters estimated in step 1 and the controller parameters. 3. The control algorithm. Many different types of control algorithms exist, but many are functions that try to adjust the controller parameters, given the continually changing process parameters in such a way that the closed loop response is constant. Because the controller is being continuously updated to the new varying conditions, these control algorithms can be quite vigorous. Step 1, the identification phase, was covered in chapter 6. Steps 2 and 3 are the controller tuning and the controller structure sections and are discussed further in this chapter. Suppose an ARX model has been previously identified with the form A(q)yk = B(q)uk + ek

(7.1)

Then what should the control law be? The simplest control law is a direct model inversion. We choose u such that y = ek which is the best possible result given the unknown noise. This results in the control law A(q) uk = yk (7.2) B(q) which is called minimum variance control, [9, 12, 14]. Expanding this control law gives the manipulated input at sample time k as uk =

1 ∗ (y + a1 yk−1 + a2 yk−2 + · · · + an yk−n − b1 uk−1 − · · · − bm uk−m ) b0 k

(7.3)

where yk∗ is the setpoint. Clearly for this type of controller to be realisable, the b0 term in Eqn. 7.3 must be non-zero, or in other words, the plant must have no dead time. This means that we can calculate the present control action ut that will drive yt to the desired yt∗ . Even without deadtime however, this type of control law will exhibit extremely vigorous action in an attempt to bring the process back to the setpoint in a single sample time. While the simulated results look very impressive, (see for example Fig. 7.3), in practice we will need to alter the structure of the control law, relax it somewhat, to account for imperfect modelling and manipulated variable constraints. These problems are partly circumvented in §7.6.4 and summarised in §7.7.

7.4. SELF TUNING REGULATORS (STRS)

323

7.4.1 Simple minimum variance control The algorithm to construct an adaptive minimum variance controller consists of two parts: the identification of the model parameters, θ, in this instance using recursive least-squares, and the implementation of the subsequent minimum variance control law. Algorithm 7.1 Simple minimum variance control for plants with no delay

1. Measure the current output yt . 2. Form the new input/output data matrix X. 3. Calculate the prediction yˆt from ϕ and θt−1 . 4. Apply the control law, Eqn. 7.3, to obtain the current input, ut , using the estimated parameters. 5. Update the estimated parameters θk using a recursive least-squares algorithm such as Algorithm 6.2 or equivalent. A simple minimum variance controller is demonstrated in Listing 7.1 To test the simulation, we will construct a siumulation where we abruptly swap between two different plants: 0.2 + 0.05q −1 , 1 − 0.78q −1 − 0.65q −2 + 0.2q −3 0.3 + 0.15q −1 , G2 (q −1 ) = 1 − 0.68q −1 − 0.55q −2 + 0.1q −3

G1 (q −1 ) =

for 0 ≤ t < 100

(7.4)

for t > 100

(7.5)

For this simulation we will assume no model/plant structural mismatch and we will use the recursive estimation with the forgetting factor option. Listing 7.1: Simple minimum variance control where the plant has no time delay t = [0:200]'; yspt = square(t/18); y=zeros(size(yspt)); u=zeros(size(y)); nr=0.02; 5

10

15

% Create time & setpoint % noise or dither sigma

n1 = [0.2 0.05]; d1 = [1 -0.78 -0.65 0.2]; % system #1, Eqn. 7.4 n2 = [0.3 0.15]; d2 = [1 -0.68 -0.55 0.1]; % system #2, Eqn. 7.5, for t > 100 thetatrue = [ones(t(1:100))*[d1 n1]; ones(t(101:length(t)))*[d2 n2]]; na = 4;nb = 2; dead=0; nt=na+nb; % Estimated model parameter orders, na , nb & nk . lam = 0.95; P=1000*eye(nt); % Identification parameters: λ, P0 thetaest=rand(nt,1); % random start guess for θ 0 Param=rand(na,nt);Pv = ones(na,1)*diag(P)'; for i=na+1:length(yspt) theta = thetatrue(i,:)'; thetar=[thetaest(1:na); thetaest(na+2:nt)]; b0 = thetaest(na+1); yv=y(i-1:-1:i-na); uv=u(i-1:-1:i-nb+1); u(i)=(yspt(i)-[yv; uv]'*thetar)/b0;

% Actual plant, G ˆ % Estimated plant, G % old output & input data % Min. Var. control law

20

c = [yv', u(i:-1:i-nb+1)'];

% Now do identification

CHAPTER 7. ADAPTIVE CONTROL

324

25

y(i) = c*theta(2:end) + 0.01*randn(1)*nr; % true process with noise [thetaest,P] = rls(y(i),c',thetaest,P,lam); % RLS with forgetting Param = [Param; thetaest']; Pv = [Pv;diag(P)']; end % for loop

Initially we will set the forgetting factor λ to 0.99, and we will introduce a small amount of noise so the estimation remains reasonable even under closed loop conditions, nr=0.02. We will aim to follow the trajectory given as the dashed line in the upper figure of Fig. 7.3. Our minimum variance controller will both try to estimate the true plant and control the process to the setpoint, y ⋆ . The lower trend in Fig. 7.3 shows the parameter values for the estimated model. Minimum variance control output & setpoint

4 G2 (q −1 )

G1 (q −1 )

2

0

−2 20

input

10 0 −10 −20

λ = 0.99

θ

1 0 −1

0

50

100

150 time

200

250

300

Figure 7.3: Simple minimum variance control with an abrupt plant change at t = 100. (See also Fig. 7.4.) In this unrealistically ideal situation with no model/plant mismatch, the controlled response looks practically perfect, despite the plant change at t = 100 (after of course the converging period). Fig. 7.4 shows an enlarged portion of Fig. 7.3 around the time of a setpoint change. Note how the response reaches the setpoint in one sample time, and stays there. This is as expected when using minimum variance control since we have calculated the input to force y exactly equal to the desired output y ⋆ in one shot. In practice this is only possible for delay-free plants with no model-plant mismatch. Of course under industrial conditions (as opposed to simulation), we can only view the controlled result, and perhaps view the trends of the estimated parameters, we don’t know if they have converged to the true plant parameters. However if the estimates converge at all to steady values, and the diagonal elements of the covariance matrix are at reasonable values, (these are application dependent), then one may be confident, but never totally sure, that a reasonable model has been identified.

7.5. ADAPTIVE POLE-PLACEMENT

325

Minimum variance control

output & setpoint

1 0.5 0 −0.5 −1

input

10 0 −10 −20 35

40 time

45

Figure 7.4: A zoomed portion of Fig. 7.3 showing the near-perfect response around a setpoint change when using simple minimum variance control on a plant with no delay.

7.5 Adaptive pole-placement Clearly the problem with the simple minimum variance control is the excessive manipulated variable demands imposed by the controller in an attempt to reach the setpoint in 1 sample time. While our aim is to increase the speed of the open-loop response, we also need to reduce the sensitivity to external disturbances. Both these aims should be addressed despite changes in the process. Fig. 7.5 shows a generalised control structure given in shift polynomial form. If the controller polynomials G = H, then we have the classic controlled feedback loop, otherwise we have a slightly more general configuration. Our aim as controller designers is to select polynomials F, G, H given process polynomials B, A such that our performance aims are met. The closed loop transfer function is HB y(t) = r(t) F A + GB where clearly the stability is given by the denominator, F A + GB. Rather than demand the onestep transient response used in the minimum variance case, we can relax this criterion, and ask only that the controlled response follow some pre-defined trajectory.

Controller pre-compensator r(t) setpoint

- H(q −1 )

Process

-+ 6−

-

1 F (q−1 )

u(t) -

B(q−1 ) A(q−1 )

G(q −1 ) 

Figure 7.5: Adaptive pole-placement control structure

- y(t)

CHAPTER 7. ADAPTIVE CONTROL

326

Suppose that we restrict the class of dynamic systems to the form, Ay(t) = Bu(t − 1)

(7.6)

where we have assumed a one sample time delay between u and y. This is to leave us enough time to perform any controller calculations necessary. We will use the controller structure given in Fig. 7.5, F u(t) = Hr(t) − Gy(t)

(7.7)

where the polynomials F, G, H are of the form: F = 1 + f1 q −1 + f2 q −2 + · · · + fnf q −nf

G = g0 + g1 q −1 + g2 q −2 + · · · + gng q −ng

H = h0 + h1 q −1 + h2 q −2 + · · · + hnh q −nh With the computational delay, the closed-loop is (F A + q −1 BG)y(t) = q −1 BHr(t)

(7.8)

and we desire the closed-loop poles to be assigned to specified locations specified in the polynomial T , T = 1 + t1 q −1 + t2 q −2 + · · · + tnt q −nt

(7.9)

Assigning the closed-loop poles to given locations is called pole-placement or pole assignment. (In practice, the closed loop polynomial T will be a design requirement given to us perhaps by the customer.) Note that some authors such as [21] use a slightly different standard nomenclature convention for the controller polynomials. Rather than use the variable names F, G, H in the control law Eqn. 7.7, the variable names R, S, T are used giving a control law of Ru(t) = T r(t) − Sy(t).

7.5.1 The Diophantine equation and the closed loop To assign our poles specified in T , we must select our controller design polynomials F, G such that the denominator of the actual closed-loop is what we desire, F A + q −1 BG = T

(7.10)

The polynomial equation Eqn. 7.10 is called the Diophantine equation, and may have many solutions. To obtain a unique solution, A, B must be coprime (no common factors), and we should select the order of the polynomials such that nf = nb ng = na − 1, (na 6= 0) nt ≤ na + nb − nc One way to establish the coefficients of the design polynomials F, G and thus solve the Diophantine equation is by expanding Eqn. 7.10 and equating coefficients in q −i giving a system of linear

7.5. ADAPTIVE POLE-PLACEMENT equations.



 1    a1    a  2   ..  .   a  na    0   .  ..   .  .  .  0 |

0

···

1 a1

..

.

0 .. . .. . .. .

b0 b1 .. .

327

0 b0

··· ..

.

b1

. a2 . . bnb .. . . . 1 0 bnb . . .. 0 ··· ana . a1 .. .. .. . a2 . · · · · · · 0 .. . · · · · · · ana 0 {z A

··· ···

 0    ..  f1  .   f2  ..   .   .  ..   ..  .    fnf   0    g0   b0   g1    b1    ...  ..   .  gng  bnb | {z } θc



                   =                 | }

t1 − a 1 t2 − a 2 .. . tnt − ant −ant+1 .. . −ana 0 .. . {z b

                

(7.11)

}

The matrix A in Eqn. 7.11 has a special structure, and is termed a Sylvester matrix and will be invertible if polynomials A, B are co-prime. Solving Eqn. 7.11 θ c = A−1 b gives us the coefficients of our controller polynomials, F, G. Now the dynamics of the closed-loop requirement are satisfied, BH r(t − 1) y(t) = T but not the steady-state gain, which ideally should be 1. We could either set H to be a scalar, T H= (7.12) B q=1

which forces the steady-state gain to 1, or preferably cancel the zeros H=

1 B

(7.13)

which improves the transient response in addition to keeping the steady-state gain of unity. Cancelling the zeros should only be attempted if all the zeros of B are well inside the unit circle. Section 7.6.1 describes what to do if the polynomial B does has poorly damped or unstable zeros. This scheme has now achieved our aim of obtaining a consistent dynamic response irrespective of the actual process under consideration. Since we cannot expect to know the exact model B, A ˆ Aˆ in the controller design. we will use an estimated model, B,

7.5.2 Solving the Diophantine equation in Matlab Since solving the Diophantine equation is an important part of the adaptive pole-placement regulator, the following functions will do just that. Listing 7.2 solves for the polynomials F and G such that F A + BG = T . If a single time delay is introduced into the B polynomial such as in Eqn. 7.10, then one needs simply to pad the B polynomial with a single zero. Note that the expression AF + BG is optionally computed using the polyadd routine given in Listing B.1, and this polynomial should be close to the T polynomial specified.

CHAPTER 7. ADAPTIVE CONTROL

328

Listing 7.2: A Diophantine routine to solve F A + BG = T for the polynomials F and G.

5

function [F,G,Tcheck] = dioph(A,B,T); % [F,G] = dioph(A,B,T); % Solves the Diophantine equation by setting up the Sylvester matrix, % AF + BG = T and subsequently solves for polynomials F & G. % See [18, p175] (follows nomenclature of except R=F, S=G). if abs(A(1)-1) > 1.0e-8; error('Error: Polynomial A not monic A(1) = %g\n',A(1)); end % if

10

15

20

na = length(A)-1; nb = length(B)-1; % Order of polynomials A(q −1 ), B(q −1 ) nf = nb; ng = na-1; n = nf+ng+1; n = nf+ng+1; % Required orders for F & G D = zeros(n,n); % construct Sylvester matrix for i=1:nf D(i:i+na,i) = A'; % fill in columns end % for i for i=1:ng+1 D(i:i+nb,nf+i) = B'; % fill in columns end % for i rhs = [A(2:na+1), zeros(size(na+1:n))]'; % right-hand side rhs = [T(2:length(T)), zeros(size(length(T):n))]' - rhs; FG= D\rhs; % Find solution for polynomials F & G F= FG(1:nf)'; G= FG(nf+1:n)';% Monic polynomial F has leading 1 dropped.

25

if nargout >2 % then check that AF + BG = T as required Tcheck = polyadd(conv(A,[1,F]), conv(B,G)); end return

An alternative Diophantine scheme An alternative, and somewhat more elegant, scheme for solving the Diophantine equation is given in Listing 7.3 which uses matrix convolution to construct the Sylvester matrix. Listing 7.3: Alternative Diophantine routine to solve F A + BG = T for the polynomials F and G. Compare with Listing 7.2. 1

6

11

function [F,G,Tcheck] = dioph_mtx(A,B,T); % Alternative version for polynomial Diophantine equation solving % Solves AF + BG = T for F & G. da = length(A)-1; db=length(B)-1; T = [T, zeros(1,da+db-length(T)+1)]; dt=length(T)-1; dg =da-1; df=dt-da ; B = [ zeros(1, df-db+1), B];

% da = deg(A) etc. % pad with zeros % Convert to full length % assuming for RAB to be square % pad with leading zeros

Rac = [convmtx(A,df+1);convmtx(B, dg+1)]; % Construct RAB = [RA ; RB ] FG = T/Rac; % [F, G] = T R−1 AB F = FG(1:df+1); G = FG(df+2:df+dg+2);% Note F & G are row vectors.

16

Tcheck = polyadd(conv(A,F), conv(B,G)); % Verify solution

7.5. ADAPTIVE POLE-PLACEMENT

329

return

The alternative scheme in Listing 7.3 is slightly different from the one presented earlier in that this time the F polynomial contains the leading unity coefficient. A third method to construct the Sylvester matrix is to use the lower triangle of a Toeplitz matrix in M ATLAB say with the command tril(toeplitz(1:5)).

Example of a Diophantine problem Suppose we only want to place one pole, T = 1 + t1 q −1 , given a na = 3, nb = 2 model. The recommended orders of the controller polynomials are nf = nb = 2 ng = na − 1 = 2 nt = 1 ≤ na + nb − nc = 5 and expanding the closed-loop equation Eqn. 7.10, (1 + f1 q −1 + f2 q −2 )(1 + a1 q −1 + a2 q −2 + a3 q −3 )+ q −1 (b0 + b1 q −1 + b2 q −2 )(g0 + g1 q −1 + g2 q −2 ) = 1 + t1 q −1 which by equating the coefficients in q −i , i = 1, . . . , 5 gives the linear system following Eqn. 7.11      1 0 b0 0 0 f1 t1 − a 1  a1 1 b1 b0 0   f2   −a2        a2 a1 b2 b1 b0   g0  =  −a3        a3 a2 0 b 2 b 1   g 1    0 0 a3 0 0 b 2 g2 0 An example of solving the Diophantine equation In this example we start with some known polynomials, and then try to reconstruct them using the Diophantine routines presented previously. Suppose we start with some given plant polynomials, say A(q −1 ) = 1 + 2q −1 + 3q −2 + 3q −3 ,

B(q −1 ) = 5 + 6q −1 + 7q −2

where the orders are na = 3 and nb = 2. This means we should choose orders nf = nb = 2, and ng = na − 1 = 2, so let us invent some controller polynomials F (q −1 ) = 1 + 8q −1 + 9q −2 ,

G(q −1 ) = 10 + 11q −1 + 12q −2

noting the A and F are monic. We can now compute the closed loop, AF + BG using convolution and polynomial addition as shown in Listing 7.4 Listing 7.4: Constructing polynomials for the Diophantine equation example >> A = [1 2 3 4]; B = [5 6 7]; >> F = [1 8 9]; G = [10 11 12]; 3

% Note nf = nb & ng = na − 1.

>> T = polyadd(conv(A,F),conv(B,G)) % Compute T (q −1 ) = A(q −1 )F (q −1 ) + B(q −1 )G(q −1 ) T = 1 60 143 242 208 120

CHAPTER 7. ADAPTIVE CONTROL

330

which gives T (q −1 ) = 1 + 60q −1 + 143q −2 + 242q −3 + 208q −4 + 120q −5 . We are now ready to essentially do the reverse. Given the polynomials A(q −1 ), B(q −1 ), and T (q −1 ), we wish to reconstruct F (q −1 ) and G(q −1 ) using the Diophantine routines given in Listings 7.2 and 7.3. Listing 7.5: Solving the Diophantine equation using polynomials generated from Listing 7.4.

4

9

14

>> [F1,G1,Tcheck1] = dioph(A,B,T) F1 = 8.0000 9.0000 G1 = 10.0000 11.0000 12.0000 Tcheck1 = 1 60 143 242 208 120

% Use Listing 7.2

>> [F2,G2,Tcheck2] = dioph_mtx(A,B,T) % Use Listing 7.3 F2 = 1 8 9 G2 = 10.0000 11.0000 12.0000 Tcheck2 = 1 60 143 242 208 120

Note that in both cases we manage to compute the polynomials F (q −1 ) and G(q −1 ) which reconstruct back to the correct T (q −1 ), although the routine in Listing 7.2 drops the leading 1 in the monic F polynomial.

7.5.3 Adaptive pole-placement with identification We have now all the components required for an adaptive controller. We will use an RLS module for the plant identification, and then subsequently solve the Diophantine equation to obtain a required closed loop response. Algorithm 7.2 describes the algorithm behind this adaptive controller. Algorithm 7.2 Adapting pole-placement algorithm We will follow Fig. 7.6 which is a specific case of the general adaption scheme given in Fig. 7.1.

1. At each sample time t, collect the new system output, y(t). 2. Update the polynomial model estimates A, B using recursive least-squares on Ay(t) = Bu(t − 1) + e(t) 3. Synthesize the controller polynomials, F, G by solving the identity, F A + q −1 BG = T where T is the desired closed-loop response. (You could use the dioph routine given in Listing 7.2.) 4. Construct H using either Eqn. 7.12 or Eqn. 7.13.

7.5. ADAPTIVE POLE-PLACEMENT

331

Pole-placement controller design Performance requirements T

-

Diophantine

identify plant ˆ B ˆ A,



RLS 1



Structure

Y

F, G & H ???

r(t)

- H

setpoint

-+

-

6−

1 F (q −1 )

u(t)

−1 - B(q ) −1 A(q )

- y(t) output

Unknown plant G(q

−1

)

2 DOF controller

Figure 7.6: Adaptive pole-placement control structure with RLS identification 5. Apply control step F u(t) = −Gy(t) + Hr(t) 6. Wait out the remainder of the sample time & return to step 1.

An adaptive controller with RLS identification example In this example will attempt to control three different plants in the configuration as shown in Fig. 7.7. The open loop step tests of the plants are compared in Fig. 7.8. Of the three plants, G1 is stable and well behaved, G2 has open-loop unstable poles, and G3 has unstable zeros.

In practice we must estimate the process model and if the plant changes, we redesign our controller such that we obtain the same closed loop response. The customer for this application demands a slight overshoot for the controlled response as shown in Fig. 7.9. We can translate this requirement for the denominator of the closed-loop transfer function to be T = 1 − 1.4685q −1 + 0.6703q −2

Listing 7.6 and Fig. 7.10 show the impressive results for this combined identification and adaptive control simulation when using the three plants from Fig. 7.8. Note that the controller design computation is done in the dioph.m routine given in Listing 7.2 while the identification is done using the rls routine. Here I assume a model structure where na = 5, nb = 3, and I add a small amount of noise, σ = 0.005, to keep the estimation quality good. A forgetting factor of λ = 0.95 was used since the model changes were known a priori to be rapid.

CHAPTER 7. ADAPTIVE CONTROL

332

Plant alternatives }| { z setpoint

-

r

Gc

-

G1

-

G2

current active plant ? switch

-

- y

6 Adaptive controller

-

G3

current inactive plant models

Figure 7.7: Control of multiple plants with an adapting controller. We desire the same closed loop response irrespective of the choice of plant.

Open−loop plant step responses

Pole−Zero Map

6000 1.5

G

5000

1

G2 (q−1 )

G

3

G1 (q

−1

Imaginary Axis

output

4000

)

3000

2000

0.5 0 −0.5

G3 (q−1 )

1000

0

G2

1

−1 −1.5

0

20

40

60 time

80

100

120

−1

−0.5

0 0.5 Real Axis

1

1.5

Figure 7.8: Step responses of the 3 discrete open-loop plants (one of which is unstable), and the corresponding pole-zero maps. Note that G3 has zeros outside the unit circle.

Desired closed loop response 1.4 1.2

output

1 0.8

1 T(q −1 )

0.6 0.4 0.2

Figure 7.9: The desired closed loop response, 1/T .

0

0

5

10

15

20 time

25

30

35

7.5. ADAPTIVE POLE-PLACEMENT

333

Listing 7.6: Adaptive pole-placement control with 3 different plants Gx=struct('b',[3 0.2 0.5],'a',poly([0.95 0.9 0.85])); % 3 different plants Gx(2) = struct('b',[2,2,1],'a',poly([1.1 0.7 0.65])); Gx(3) = struct('b',[0.5 0.2 1],'a',poly([0.6 0.95 0.75])); 5

10

na = 3; nb = 3; % order of polynomials, na , nb a = randn(1,na); b = randn(1,nb); % model estimates np = length([a,b]); % # of parameters to be estimated P = 1.0e4*eye(np); % Large initial co-variance, P0 = 104 I lambda = 0.95; % Forgetting factor, 0 < λ < 1 param_est = [a,b]'; % Design a reasonable CLTF response with τ = 2 and ζ = 0.4 tau=2; zeta = 0.4; Grc = tf(1,[tauˆ2 2*tau*zeta 1]); Grd = c2d(Grc,1); T = cell2mat(Grd.den);

15

dt = 1; t = dt*[0:700]'; r = square(t/10); % sample time & setpoint y = zeros(size(t)); u = y; noise = 0.005*randn(size(t)); Param = zeros(length(t),np); trP = zeros(size(t));% plot holder tG2 = 150; tG3 = tG2+200; k=1; % Swap over times for the different plants 20

for i=10:length(t) if t(i) == tG2, k=2; end % Swap over to model #2 if t(i) == tG3, k=3; end % Swap over to model #3 25

30

35

40

45

% Plant response y(i) = Gx(k).b*u(i-1:-1:i-length(Gx(k).b)) - ... Gx(k).a(2:end)*y(i-1:-1:i-length(Gx(k).a)+1); % Model identification x = [-y(i-1:-1:i-na)', u(i-1:-1:i-length(b))']; % shift register [param_est,P] = rls(y(i),x',param_est,P,lambda); % update parameters, Listing 6.18. ˆ B ˆ a=[1 param_est(1:na)']; b=param_est(na+1:na+nb)';% extract estimates: A, Param(i,:) = param_est'; trP(i) = trace(P); % Controller design [F,G] = dioph(a,b,T); % Solve Diophantine polynms, Listing 7.2. %[F,G] = dioph_mtx(a,b,T); F(1)=[]; % Alternative Diophantine, Listing 7.3. H = sum(T)/sum(b); % Get steady-state correct, H = T /B|q=1 . % Control law, F u = −Gy + Hr u(i) = H*r(i) - G*y(i:-1:i-length(G)+1) - F*u(i-1:-1:i-length(F)); end % for i %% Check the results G = tf(sum(T),T,1); % desired closed loop yref = lsim(G,r);

Fig. 7.10 shows the impressive results of this adaptive controller. When the plant changes, unbeknown to the controller, the system identification updates the new model, and the controller consequently updates to deliver a consistent response. If the pole-placement controller is doing its job, then the desired closed loop response should match the actual output of the plant. These two trajectories are compared in Fig. 7.11 which shows an enlarged portion of Fig. 7.10. Here it can be seen that apart from the short transients when the plant does change, and the identification routine is struggling to keep up, the adaptive pole-placement controller is satisfying the requirement to follow the reference trajectory.

CHAPTER 7. ADAPTIVE CONTROL

334

3

output & setpoint

2 1 0 −1 −2 −3 0.1

input

0.05 0 −0.05

θ

−0.1 5 0 −5 5

10

0

10

0

50

100

150

200

250 time

300

350

400

450

500

Figure 7.10: Adaptive pole-placement with RLS identification. After a period for the estimated parameters to converge (lower trends), the controlled output response (upper trend) is again reasonably consistent despite model changes. Results from Listing 7.6.

y

1.8

Reference, y* 1.6 1.4 1.2 1 0.8 0.6 0

50

100

150

200

250 time

300

350

400

450

500

Figure 7.11: An enlarged portion of Fig. 7.10 showing the difference between the actual plant output y(t), and the reference output, y ∗ (t).

7.6. PRACTICAL ADAPTIVE POLE-PLACEMENT

335

7.6 Practical adaptive pole-placement Some problems still remain before the adaptive pole-placement algorithm is a useful and practical control alternative. These problems include: • Poor estimation performance while the system is in good control, and vice-versa, (poor control during the periods suitable for good estimation). (This is known as the dichotomy of adaptive control, or dual control). • Non-minimum phase systems possessing unstable zeros in B which must not be cancelled by the controller. • Dead time where at least b0 = 0. We must try to solve all these practical problems before we can recommend this type of controller.

An example of bursting If our controller does its job perfectly well, then the output remains at the setpoint. Under these circumstances we do not have any identification potential left, and the estimated model starts to drift. The model will continue to drift until the controller deteriorates so much that there is a period of good excitation (poor control), that the model re-converges again. This Fig. 7.12 shows the experimental results from using an adaptive controller, (in this case an adaptive LQR regulator) on the blackbox over a substantial period of time. The controller sampling at T = 1 second was left to run over night for 10 hours (36,000 data points), and for a 3 hour period in the middle we had no setpoint changes, and presumably no significant disturbances. During this time, part of which is shown in Fig. 7.12, the adaptive controller oscillated into, and out of, good control. This is sometimes known as “bursting”.

7.6.1 Dealing with non-minimum phase systems If we use the steady-state version for H, def

H =

T B q=1

then we do not cancel any zeros, and we avoid the problem of inadvertently inverting unstable model zeros. However we can achieve a better transient response if we cancel the zeros with the pre-compensator H, 1 H= B giving the closed loop transfer function, y(t) =

1 HB r(t − 1) = r(t − 1) T T

which looks fine until we investigate closer what is likely to happen if B has zeros outside the unit circle. In fact, we will have problems not only if the zeros are unstable, but even if they are stable but poorly damped. Fig. 7.13 shows the adaptive pole-placement response of a plant with stable, but

CHAPTER 7. ADAPTIVE CONTROL

336

Adaptive LQR of the blackbox ∆ t=1.00 (sec) 0.4

output & setpoint

0.3 0.2 0.1 0 −0.1 −0.2 −0.3 2.5

3

3.5

4

3.5

4

RLS: λ=0.995 1

Input

0.5

0

−0.5

−1 2.5

3 time (hours)

Figure 7.12: Bursting phenomena exhibited by the black box when using an adaptive controller. With no setpoint changes or external disturbances, the adaptive controller tends to oscillate between periods of good control and bad estimation and the reverse. ◦

input

output & setpoint

poorly damped zeros when using H = 1/B. In fact the zeros are 0.95e±j130 indicating that they are close to, but just inside the unit circle. While the output response looks fine, it is the ringing behaviour of the input that should cause concern. 2

0

−2 0.5

0

−0.5 sample time

Figure 7.13: Adaptive pole-placement with a poorly damped B polynomial. The poorly damped zeros cause the ringing behaviour in the input. The results in Fig. 7.13 were obtained by using the modified controller given in Listing 7.7 in Listing 7.6.

7.6. PRACTICAL ADAPTIVE POLE-PLACEMENT

337

Listing 7.7: The pole-placement control law when H = 1/B if

4

any(abs(roots(b))>1) % Use H = T /B|q=1 if any zeros of B are unstable.

H = polyval(T,1)/polyval(b,1); % Simple scalar pre-filter, H = T /B|q=1 . u(i) = H*r(i) - G*y(i:-1:i-ng) - F*u(i-1:-1:i-nf); else % Alternatively, use dynamic compensation, H = 1/B. v(i) = 1/b(1)*(-b(2:end)*v(i-1:-1:i-nb+1)+sum(T)*r(i)); u(i) = v(i) - G*y(i:-1:i-ng) - F*u(i-1:-1:i-nf); % control action end

Suppose we have estimated a B polynomial possessing an unstable zero at say q −1 = +2/3, or B = 1 − 1.5q −1 and we desire T = 1 − 0.7q −1 . Then the closed-loop transfer function is y(t) =

BH q −1 (1 − 1.5q −1 ) Hr(t) r(t − 1) = F A + q −1 BH 1 − 0.7q −1

Now suppose we use a dynamic pre-compensator, H = 1/B, H=

1 q(1 − 1.5q −1 )

which has a time-advance term, q +1 , meaning that the control law is a non-causal function of the setpoint. In other words, we need to know r(t + 1) at time t. In fact since we need to know only future values of setpoint, and not output, this type of control law is easily implemented. The main drawback stems, however, not from the acausality, but from the ill-advised cancellation. In all practical cases, we will experience some small numerical round-off error such as where the pole is represented in a finite-word length computer as 1.50001 rather than exactly 1.5. Consequently the pole will not completely cancel the zero, y(t) =

q q −1 (1 − 1.5q −1 ) × r(t) 1 − 0.7q −1 (1 − 1.50001q −1) | {z } small error

leaving an unstable controller.

The remedy is that if we discover unstable modes in B, we simply do not cancel them, although we continue to cancel the stable modes. We achieve this by separating the B polynomial into two groups of factors; the stable roots, B + , and the unstable roots, B − , def

B = B+B−

(7.14)

and then set H = 1/B + only. A simple M ATLAB routine to do this factorisation is given in Listing 7.8 in section 7.6.2. So given the model and control law, Ay(t) = Bu(t − 1) F u(t) = −Gy(t) + Hr(t) we modify the pole assignment to AF + q −1 BG = T B +

(7.15)

CHAPTER 7. ADAPTIVE CONTROL

338 so closed-loop transfer function is y(t) =

HB HB − r(t − 1) = r(t − 1) T B+ T

(7.16)

We solve the modified pole-assignment problem, Eqn. 7.15, by noting that B + must be a factor of F, F = B + F1 so we solve the reduced problem using the Diophantine equation, AF1 + q −1 B − G = T in the normal manner. We should do this when using RLS, because we can never be sure when we will identify an unstable B since the RLS is automatic. Even in a situation where we know, or reasonably suspect a stable B, we may stumble across an unstable B while getting to the “correct” values. As an example, we can apply the adaptive pole-placement controller where we cancel the stable B polynomial zeros, but not the unstable ones, using the three plants from page 331. Fig. 7.14 shows the result of of this controller where we note that the performance of plant #3 is also acceptable exhibiting no ringing. For diagnostic purposes, we can also plot the instantaneous poles and zeros of the identified model, and perhaps display this information as a movie. This will show how the poles and zeros migrate, and when zeros, or even poles, leap outside the unit circle. Fig. 7.15 shows these migrations from the simulation presented in Fig. 7.14. If you rotate the pole-zero map in Fig. 7.15(a) you may see the dreaded V¨armland lynx.

7.6.2 Separating stable and unstable factors When applying pole-placement in the case with unstable zeros, we need to be able to factor B(q) into stable and unstable factors. Listing 7.8 does this factorisation, and additionally it also rejects the stable, but poorly damped factors given a user-specified damping ratio, ζ. (If you want simply stable/unstable, use ζ = 0.) Fig. 7.16 illustrates the region for discrete well-damped poles where ‘well-damped’ is taken to mean damping ratios greater than ζ = 0.15. This algorithm is adapted from [148, p238]. Listing 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 defined as monic. 2

7

12

function [Bp,Bm] = factorBz(B,zeta); % Factorise B(q) = B + (q)B − (q) where B + are factors inside the unit circle and B − (q) are outside. % The optional parameter, ζ defines the cutoff. Use ζ = 0 for inside/outside circle. % Note B + (q) or Bp is defined as monic. if ¬(exist('zeta') == 1) zeta = 0.15; % default reasonable cut-off is ζ = 0.15. end zeta = max(min(zeta,1),0); % Ensure ζ ∈ [0, 1]. tol = 1e-6; r = roots(B); % Now separate into poorly damped & good poles mag_r = abs(r); rw = angle(r)/2/pi; % See equations in [148, p238].

7.6. PRACTICAL ADAPTIVE POLE-PLACEMENT

339

output & setpoint

3 2

G1 (q −1 )

G2 (q −1 )

Unstable zeros: G3 (q −1 )

1 0 −1 −2 0.2

input

0.1 0 −0.1 −0.2

λ=0.99

4

θ

2 0 −2 −4 5

10

0

10

0

500

1000

1500

time def

Figure 7.14: Adaptive pole-placement control with H = 1/B and an unstable B polynomial in Plant #3.

mz = exp(-2*pi*zeta/sqrt(1-zetaˆ2)*rw); % magnitude of z idx = mag_r < mz; 17

22

Bp = poly(r(idx)); % Set B + (q) to contain all the zeros inside unit circle Bm = poly(r(¬idx))*B(1); % All the others if norm(conv(Bp,Bm)-B) > tol % Check B = B + B − warning('Problem with factorisation') end % if return

CHAPTER 7. ADAPTIVE CONTROL

340

1.5

1

0.5

0

−0.5

−1

−1.5

−2

−1.5

−1

−0.5

0

0.5

1

1.5

2

(a) Pole-zero map for an adaptive controller

(b) If you rotate the pole-zero map, you find a disturbing similarity to the V¨armland lynx.

Figure 7.15: A pole-zero map at each sampling instance of the adaptive pole-placement simulation given Fig. 7.14. Note how at times not only the zeros, but also the poles jump outside the unit circle leading to an unstable identified model.

Figure 7.16: The boundary of the shaded area is the loci of constant damping ratio with ζ = 0.15. Inside this region, the poles are considered well damped. (Figure plotted with zgrid.)

7.6.3 Experimental adaptive pole-placement Actually running an adaptive pole-placement scheme on a real plant, even a well behaved one in the laboratory is considerably more difficult than the simulation examples presented so far. Our desire is to test an adaptive pole-placement controller on the black-box to demonstrate the following: 1. To follow a specified desired trajectory (as quantified by the T polynomial), 2. under both the ‘NORMAL’ and ‘SLOW’ positions on the black box, and 3. to run stably for at least 10 minutes following both disturbances and servo changes. The first design decision is to choose a desired response (closed loop poles) and suitable sampling interval. We shall select a second-order prototype response with a time constant of τ = 2.1

7.6. PRACTICAL ADAPTIVE POLE-PLACEMENT

341

seconds and some overshoot, ζ = 0.6. With a sampling time of T = 0.6 seconds, the desired discrete closed loop transfer function is G⋆cl (s) =

4.41s2

1 + 2.52s + 1



G⋆cl (q −1 ) =

from which follows that T = 1 − 1.641q −1 + 0.7097q −2.

0.03628 + 0.03236q −1 1 − 1.641q −1 + 0.7097q −2

Fig. 7.17 shows the results from one experiment where the characteristics of the plant are changed at t = 128 by manually switching over from 7 cascaded low-pass filters to 9. This increases the effective time constant of the plant. It is important to verify that the output from the blackbox did in fact follow the intended trajectory once the model parameters have converged. An enlarged portion of Fig. 7.17 is repeated in Fig. 7.18 comparing the intended trajectory, y ⋆ , (dashed line) with the actual trajectory, y. This shows that the response converged to the desired trajectory even after the plant subsequently changed. Fig. 7.17 shows clearly that the shape of the input must vary considerably to force the same output if the plant itself changes.

7.6.4 Minimum variance control with dead time The minimum variance control formulation of §7.4.1 is not very useful not the least due to its inability to handle any dead time and unstable process zeros. Even without the dead time, practical experience has shown that this control is too vigorous and tends to be over-demanding causing excessive manipulator variable fatigue. Moreover when using discrete time models, delay between input and output is much more common, and typically the deadtime is at least one sample period. The best we can do in these circumstances is to make the best prediction of the output we can for d samples times ahead, and use this prediction in our control law as done above. This introduces the general concept of minimum variance control which combines prediction with control. Further details are given in [22, pp367–379]. Suppose we start with the ARMAX canonical model written in the forward shift operator q, A(q)yk = B(q)uk + C(q)ǫk

(7.17)

and we assume that A and C are monic. We can always divide out the coefficients such that A is monic, and we can choose the variance of the white noise term so that C is monic. For this simplified development we will also need to assume that all the zeros of both C and B are inside the unit circle. The pole excess of the system d, is the difference in the order of the A and B polynomials and is equivalent to the system time delay. The output d steps ahead in the future is dependent on the current and past control actions, u, which are known, and the current, past and future disturbances, the latter which are not known. To avoid using the unknown disturbance values we need to make an optimal prediction.

Optimal prediction If we have a process driven by white noise ǫ, zk =

C(q) ǫk A(q)

(7.18)

then the minimum variance predictor over d steps is zˆk+d|k =

qG(q) zk C(q)

(7.19)

CHAPTER 7. ADAPTIVE CONTROL

342

Adaptive pole−placement with RLS

output & setpoint

0.4 Normal

0.3

Slow

0.2 0.1 0 −0.1 −0.2

∆ t=0.6, 1

input

0.5 0 −0.5 −1 λ=0.99, na=4, nb=3 2

parameters

1 0 −1 −2

5

tr(P)

10

4

10

3

10

0

50

100

150

200 time (sec)

250

300

350

400

Figure 7.17: Adaptive pole-placement of the black-box showing consistent output response behaviour despite the plant change when the switch was manually activated at t = 128 seconds. Plot (A): black-box output (solid), intended trajectory (dashed) and setpoint point (dotted). (Refer also to Fig. 7.18 for an enlarged version.) Plot (B): Controller input to the plant, Plot (C): Plant parameter estimates, and Plot (D): Trace of the covariance matrix.

7.6. PRACTICAL ADAPTIVE POLE-PLACEMENT

343

0.28

Normal

0.26

actual y setpoint intended y*

Slow

output & setpoint

0.24

0.22

0.2

0.18

0.16 60

80

100

120

140

160 180 time (sec)

where G(q) is defined from

200

220

240

260

280

Figure 7.18: A comparison of the intended trajectory, y ⋆ (dashed line) with the actual trajectory y (solid line) for the black box from Fig. 7.17. Even after the plant change, the actual response gradually converges to the desired trajectory.

q d−1 C(q) = A(q)F (q) + G(q)

(7.20)

We can calculate the quotient F and remainder G polynomials in Eqn. 7.20 from polynomial division in M ATLAB using the deconv function, or alternatively, one could calculate them by equating the coefficients in Eqn. 7.20.

Minimum variance control law Once we can make an optimal prediction using the formulation of Eqn. 7.20, we can predict the output d samples times into the future and then calculate the control action required to equate this with the setpoint. This will give the desired minimum variance control law as, uk = −

G(q) yk B(q)F (q)

(7.21)

The closed loop formulation by combining Eqn. 7.17 and Eqn. 7.21 is G yk + C ǫk BF AF yk = −Gyk + CF ǫk CF yk = ǫk = F ǫk AF + G Ayk = −B

(7.22)

where the last equation is simplified using Eqn. 7.20. Eqn. 7.22 indicates that the closed loop response is a moving average process of order d − 1. This provides us with a useful check in that the covariance of the error will vanish for delays larger than d − 1. Listing 7.9 designs the F (q) and G(q) polynomials required in the control law, Eqn. 7.21, by using deconvolution. Note this routine uses stripleadzeros to strip any leading zeros from the B(q) polynomial from Listing B.3 given in Appendix B. Listing 7.9: Minimum variance control design 2

function [F,G,BF] = minvar_design(A,B,C) % Design a minimum variance controller for plant B(q)/A(q) with noise polynomial C(q).

CHAPTER 7. ADAPTIVE CONTROL

344

% Control law, Eqn. 7.21, is uk = −G(q)/(B(q)F (q))yk B = stripleadzeros(B); % Remove any leading zeros from the B polynomial n = length(A); % order of plant 7

12

17

if length(C) 6= n C = [C,zeros(1,1:n-length(C))]; % Force C(q) the same length as A(q) end % if d0 = length(A)- length(B); % Time delay is na − nb = d0 qd0 = [1,zeros(1,d0-1)]; qd0C = conv(qd0,C); [F,G] = deconv(qd0C,A);

% Construct q d0 −1 % Construct q d0 −1 C(q)

BF = conv(B,F); return

% Construct B(q)F (q)

Unstable process zeros As in the adaptive pole-placement case outlined in section 7.6.1, if we have a non-minimum phase plant with unstable zeros, then the resulting controller given by Eqn. 7.21 will be unstable since essentially we are attempting to cancel right-hand plane zeros with right-hand plane poles. Again the solution is to factor B into two factors, one containing all the stable modes, B + , and one containing all the unstable modes, B − , and using only B + in the control law. (See Listing 7.8 to do this.) The F and G polynomials are obtained from solving the Diophantine equation which is a generalisation of Eqn. 7.20. Refer to [22, pp380-385] for further details. Moving average example Consider the following plant system with a noise term, (q − 0.9)(q − 0.8)(q − 0.2)yk = −2(q − 1.25)(q − 0.4)uk + (q 3 − 0.7q 2 + 0.14q − 0.2) ek noting the unstable plant zero at q = 1.25.

2

Plant = zpk([1.25 0.4],[0.9 0.8 0.2],-2,1); % Plant poles & zeros Ptf = tf(Plant); B = stripleadzeros(Ptf.num{:}); A = Ptf.den{:}; C = [1 -0.7 0.14 -0.2]; % Noise polynomial var_e = 1; % Variance of noise

The step response and pole-zero plot in Fig. 7.19 illustrates the potential difficulties with this plant. We can design a moving average controller for this NMP plant as follows. B = stripleadzeros(B); [Bp,Bm] = factorBz(B); 4

% Remove the leading zeros, (if any) % Factorise B(q) into well-damped and unstable zeros

n = length(A); % order of plant C = [C,zeros(1,n-length(C))]; % Back-pad with zeros to get same length as A(q) (if necessary)

7.7. SUMMARY OF ADAPTIVE CONTROL Pole−Zero Map

345

Step Response 20

1 15

Amplitude

Imaginary Axis

0.5

0

10

5 −0.5 0 −1 −1

−0.5

0 0.5 Real Axis

1

1.5

−5

0

20

40 Time (seconds)

60

80

Figure 7.19: A non-minimum phase plant with an unstable zero which causes an inverse step response.

d = length(A)- length(Bp); % # of process zeros to cancel 9

14

19

% Now solve Diophantine eqn AR + BS = q d−1 CB + to compute control law qd = [1,zeros(1,d-1)]; % Construct q d−1 qdCBp = mconv(qd,C,Bp); % Evaluate q d−1 CB + using (multiple) convolution [R,S] = dioph_mtx(A,B,qdCBp) % Listing 7.3. [R1, R1rem] = deconv(R,Bp) % Check that R/B + has no remainder G = S; BF = R; F=R1; % relabel B = [zeros(1,length(A)-length(B)), B]; % Make B(q) same length as A to prevent AE loops sim('sminvarctrl',[0 1e5]) % Now run the Simulink simulation variance = var(ey); varR1 = var_e*sum(R1.*R1); disp([variance, varR1]) % Note that var{y} ≈ var{(F e)}

Note that this controller does not attempt to cancel all two process zeros since that would result in an unstable controller giving rise to unbounded internal signals. However instead we cancel the one stable process zero giving rise to a moving average controller. In this example shown in Fig. 7.20, F (q) = q+5.0567 which indicates that the expected covariance of the output is σy2 = (12 + 5.062 ) = 26.6 which, provided we take enough samples as shown in Fig. 7.20(b), it is.

7.7 Summary of adaptive control Adaptive control is where the controller adjusts in response to changing external conditions. This is suitable for plants that are time varying, severely nonlinear or perhaps just unknown at the controller design stage. The general adaptive controller has two parts; an identification part and a controller design part although in some implementations these two components are joined together. The main styles of adaptive control are: ◦ Where the controller parameters are some static function of the output. The simplest example is gain scheduling. This has the advantage that it is easy to implement, but it is really only open loop adaption, and may not perform as expected if the conditions change in an unpredictable manner. ◦ Where the classical PID controller is augmented with a “self-tuning” option. This can be based on the Ziegler-Nichols design, using a relay feedback to extract the ultimate frequency and gain.

CHAPTER 7. ADAPTIVE CONTROL

346

Random Number

F(z)

ey

1 To Workspace

F C

C(z) 1

B(z)

1

1

A(z)

Add

B

Scope

A

Gain G(z)

−1

den(z) Min var ctrlr

(a) A minimum variance moving average controller implementation in S IMULINK . 30 25

Variance

20

variance of output

15 10

variance of noise

5 0 3 10

4

5

10 10 Experiment duration

6

10

(b) The variance of the output should converge to σy2 = 26.6.

Figure 7.20: Minimum variance moving average control. If the controller is designed correctly, then the output variance should be approximately equal to the variance of the noise signal filtered through F , which in this case it is, provided we take enough samples. • Where the parameters of the plant transfer function model are estimated online using the techniques described in chapter 6, and the controller is designed to control this model. If the controller is approximately the inverse of the process model, this leads to minimum variance control, but is usually too severe, and even tends to instability for many actual applications. A better alternative is adaptive pole-placement, where reasonable closed loop poles are specified by the control engineer, and the controller is varied to provide this performance as the identified model changes. As with all high performance control schemes, there are some open issues with adaptive controllers. For the simple schemes presented here we should be aware of the following issues: 1. The structure (order and amount of deadtime) of the plant must be known beforehand, and typically is assumed constant. 2. Minimum variance control, while simple to design, attempts to force the process back to

7.7. SUMMARY OF ADAPTIVE CONTROL

347

the desired operating point in one sample time. This results in overly severe control action. 3. There are potential numerical problems when implementing recursive estimators, particularly in fixed point or with short word lengths. 4. If dead time is present, and usually “dead time” of at least one sample time is always present, then the controller will be unrealisable since future values of y are needed to calculate current values of u. In this case, a sub-optimal controller is used where the dead time is simply ignored, or the future output is predicted. However the real problem of adaptive control is that when the plant is in control, there is little or no information going to the estimator. Hence the controller parameters begin to oscillate wildly. This is not normally noticed by the operator, because the process is in control. However as soon as a disturbance enters the plant, the controller will take extra action attempting to correct for the upset, but now based on the wildly inaccurate plant model. During this time of major transients however, the widely changing process conditions provide good information to the estimator which soon converges to good process parameters, which in turn subsequently generate appropriate controller parameters. The adaptive controller then brings the process back under control and the loop starts all over again. This results in alternating periods of very good control and short periods of terrible control. One solution to this problem is to turn off the estimator whenever the system is at the setpoint. In summary when applying adaptive control, one wants: • A constant output for good control, but • a varying input and output for good estimation (which is required for good control)! This conflict of interest is sometimes called the dichotomy of adaptive control.

CHAPTER 7. ADAPTIVE CONTROL

348

Problems Problem 7.1 1. Construct a S IMULINK diagram to simulate the general linear controller with 2-degrees of freedom controller. That is, with the R, S and T controller polynomials. Follow [18, Fig3.2, p93]. Hint: Use the discrete filter blocks in z −1 , since these are the only blocks that you can construct S(z − )/1 in. 2. Simulate the controlled response in problem 1 using the polynomials from [18, Ex3.1], repeated here B(q) 0.1065q + 0.0902 = 2 A(q) q − 1.6065q + 0.6065 and

R(q) = q + 0.8467,

S(q) = 2.6850q − 1.0319,

T (q) = 1.6530q

3. Verify that the closed loop is the same as the expected model, Bm BT = AR + BS Am in the example 3.1, [18, Ex3.1, p97–98]. Hint: You may like to use the M ATLAB symbolic toolbox. 4. Construct an m-file to do the minimum degree pole-placement design. (a) Do an ‘All zeros cancelled’ version (b) Do an ‘No zeros cancelled’ version (c) Do an general version, perhaps with some automated decider which zeros to cancel. 5. For the minimum variance controller we need to be able to compute the variance of the output of a FIR filter, refer [18, chapter 4]. (a) What is the theoretical output variance of a FIR filter with input variance of σe2 ? i. In S IMULINK you have the choice of the DSP format z −1 or the transfer function version z. What would be the natural choice for q? ii. Test your answer to part (1) by constructing a simulation in S IMULINK. (b) Approximately how many samples do you need to obtain 2, 3 and 4 decimals accuracy in your simulation? (c) Using the hist function look at the distribution of both the input, e, and output, y. Is the output Gaussian and how could you validate that statistically? 6. For stochastic control and for regulatory control topics we want to be able to elegantly simulate models of the form A(q)y(t) = B(q)u(t) + C(q)e(t)

(7.23)

where A, B, C are polynomials in the forward shift operator q. Note that the deadtime is defined as deg(A)-deg(B). (a) For the standard model in Eqn. 7.23 what are the constraints on the polynomials A, B, C? i. Choose sensible polynomials for A, B, C with at least one sample of deadtime. Create a model object from the System Identification toolbox using the idpoly command.

7.7. SUMMARY OF ADAPTIVE CONTROL

349

ii. Simulate this model either using idmodel/sim or the idsim command. What is the difference between these two commands? Choose a square wave for u(t) and say random noise for e(t). (b) Create a S IMULINK model and compare the simulated results with above. Use the same random input. (c) Write a raw M ATLAB script file to run the simulation and compare with the two alternatives above. (They should give identical results.)

350

CHAPTER 7. ADAPTIVE CONTROL

Chapter 8

Multivariable controller design As our engineering endeavors became more sophisticated, so did our control problems. The oil crises of the mid 1970s gave impetus for process engineers to find ways to recycle energy and materials. Consequently the plants became much harder to control because they were now tightly coupled to other plants. As the plants became multivariable, it made sense to consider multivariable controllers. If we have a dynamic system with say 3 states and 3 inputs, then assuming that our system is controllable, we can feedback the three states directly to the three inputs, state 1 to input 1, state 2 to input 2 etc. This is termed de-centralised control, and our first dilemma is which state should be paired with which input. We then have the problem of tuning the three loops, especially if there are some interactions. Alternatively we could feedback each state to all the inputs, which is termed centralised control. In matrix form, the two alternative control laws look like     ⋆ • • ⋆ x ⋆ or u =  • ⋆ •  x u= • • ⋆ ⋆ {z } {z } | | centralised

de-centralised

Exploiting the off-diagonals of the gain matrix K tends to be more efficient and is often what is meant by multivariable control. While centralised or multivariable control structures typically give better results for similar complexity, they are harder to design and tune since we have more controller parameters (9 as opposed to 3) to select. Not surprisingly, decentralised control remains popular in industry, none the least for the following reasons given by [89]: 1. Decentralised control is easier to design and implement than a full multivariable controller, and also requires fewer tuning parameters. 2. They are easier for the operators to understand and possibly retune. 3. Decentralised controllers are more tolerant of manipulated or measurement variable failure. 4. Startup and shutdown operating policies are easier with decentralised controllers, since the control loops can be gradually brought into service one by one. Despite these application style advantages of decentralised controllers, it is useful to study what is possible with a full multivariable controller. This is the purpose of this chapter. 351

352

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

Finally a one-step optimal controller that is applicable for nonlinear processes called GMC (Generic Model Control) is presented in §8.5. Exact feedback nonlinearisation is a generalisation of the GMC controller follows in §8.6.

8.1 Controllability and observability This section will introduce in a descriptive manner the concept of controllability, observability and other “abilities”. For a more formal treatment see for example [150, §9–4, p699-713] or [148, p627 §6–2]. The criteria of controllability is given first in §8.1.1 followed by the related property of observability (which is the dual of controllability) in §8.1.2. These conditions are necessary for some of the multi-variable controller and estimator design that follow. Methods to compute the controllability matrix, and establishing the condition are given in §8.1.3.

8.1.1 Controllability When designing control systems, we implicitly assume that we can, at least in principle influence the system to respond in some desired manner. However, it is conceivable, perhaps due to some structural deficiency, that we cannot manipulated independently all the states of the system. The controllability criteria tells us if this is the case. Formally defined, a system is controllable if it is possible to transfer from any arbitrary initial state x0 to any other desired state x⋆ in a finite time by using only an uncompensated control signal u. Note that while the transformation is allowed to take place over more than one sample time, it must be achieved in a finite time. In addition, even if the above controllability requirement is satisfied, you may not be able to keep the state x at the desired position, the guarantee is only that x could pass through x⋆ at some time in the future. Nevertheless, it is instructive to know ˚ om if a given system is controllable or not. Some care is needed with these terms. Astr ¨ and Wittenmark, [22, p127], define reachability as I have defined controllability above, and then define controllability as a restricted version where x⋆ = 0. These two definitions are equivalent if A or Φ is invertible. First consider a continuous dynamic system matrix,  ∗ 0  0 ∗  x˙ =   0 0 0 0

that has a diagonal A matrix and an arbitrary B  ··· 0 ··· 0    x + Bu .. . 0  ··· ∗

where an ∗ indicates the presence of a non-zero value. Now suppose u(t) = 0 for all time, then the steady state is xss = 0. Since A is a diagonal matrix, there is no interaction between the states. This means that if one particular state xi , is 0 at some time t, then it will always remain at zero since u= 0. Now consider the full system (u 6= 0), but suppose that the ith row of B are all zeros such as the second row in the following control matrix, 

∗  0 B=  0 ∗

∗ 0 ∗ ∗

0 0 0 0

 0 0   ∗  ∗

8.1. CONTROLLABILITY AND OBSERVABILITY

353

Then if xi happens to be zero, it will remain at zero for all time irrespective of the value of the manipulated variable u. Quantitatively this is due to the following two points: 1. No manipulated variable can modify the value of xi because they are all multiplied by zero. 2. No other states can influence xi because in this special case the system matrix A is diagonal. Hence if xi is zero, it will stay at zero. The fact that at least one particular state is independent of the manipulated vector means that the system is uncontrollable. We cannot influence (and hence control) all the states by only changing the manipulated variables. In summary, a system will be uncontrollable if the system matrix A is diagonal, and any one or more rows of B are all zero. This is sometimes known as Gilbert’s criteria for controllability. If the matrix A is not diagonal, then it may be transformed to a diagonal form (or Jordon block form), and the above criteria applied. We can easily transform the system to a block diagonal form using the canon function in M ATLAB. However a more general way to establish the controllability of the n × n system is to first construct the n × (m ∗ n) controllability matrix C, def

C=

h

. B ..

AB

.. .

A2 B

.. . . · · · ..

An−1 B

i

(8.1)

and then compute the rank of this matrix. If the rank of C is n, then all n system modes are controllable. This is proved in problem [148, A-6-6 p753]. The discrete controllability matrix is defined in a similar manner; h

def

C=

.. . Φ∆



.. .

2

Φ ∆

.. . . · · · ..

Φ

n−1



i

(8.2)

and also must be of rank n for the discrete system to be controllable. An often less restrictive controllability requirement is output controllability. This is where we wish only to control the outputs y, rather than the full state vector x. The output controllability matrix C y is defined as def

Cy =

h

. CB ..

CAB

.. .

2

CA B

.. .

. · · · ..

n−1

CA

B

i

(8.3)

Output controllability is given in Example A-9-11 Ogata, [150, p756], and [148, p636]. The rank of a matrix is defined as the number of independent rows (or columns) in a matrix, and is a delicate numerical computation using a finite precision computer. The presence of a non-zero determinant is not a good indication of rank because the value of the determinant scale so poorly. By the same argument, a very small determinant such as say 10−6 is also not a reliable indication of dependence. Numerically the rank is computed reliably by counting the number of non-zero singular values, or the number of singular values above some reasonable threshold value. See also §8.1.3. The controllability matrix for the submarine system in §2.8.2 is

C=

h

B

.. .

AB

.. . A2 B

i



  0 −0.095 0.0192 0 −0.095 0.0192 0.0192 −0.0048   −0.095 0.0192 −0.0048  =  −0.095 0.072 −0.0283 0.0098 0.072 −0.0283 0.0098

which has a rank of 3. Hence the submarine system is controllable.

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

354

8.1.2 Observability Observability is a related property to controllability.

A system is observable if one can evaluate x0 by recording only the output yt over a finite time interval. In other words, the system is observable if all the states eventually “effect” the outputs. Note that the observation is allowed to take place over more than one sample time. Once we have back calculated x0 , we can use the history of the manipulated variable ut to forward calculate what the current state vector xt is. It is clear that this condition of observability is important in the field of estimation. As a trivial example, suppose we had a 3 state system and we have three outputs which are related to the states by   1 0 0 y = Cx =  0 1 0  x 0 0 1 Here the outputs (measurements) are identically equal to the states (C= I). It is clear that we can evaluate all the states simply by measuring the outputs over one sample time and inverting the measurement matrix x = C−1 y = Iy = y since C−1 = I in this trivial example. This system is therefore observable. Suppose, however, we only measure two outputs where C is the non-square matrix y = Cx =



1 0

0 0 0 1



x

Now, obviously, if we recorded only one output vector (2 measurements), we could not hope to reconstruct the full 3 state vector. But the observability property does not require us to estimate x in one sample time, only in a finite number of sample times. Hence it may be possible for a system with fewer outputs than states to be still observable. To get a feel for the observability of a system, we will use a similar line of argument to that used for the controllability. Suppose we have a diagonal system and an arbitrary output matrix 

∗  0  x˙ =   0 0

y = Cx

 0 ··· 0 ∗ ··· 0   x .. . 0  0 0 ··· ∗

(8.4)

(8.5)

Note that any system can be converted into the above form, and for observability criteria we are not interested in the manipulated variable effects. Now if any of the columns of the C matrix are all zeros, then this is equivalent to saying that that a particular state will never influence any of the outputs, and since the system matrix is diagonal, that same state is never influenced by any of the other states. Therefore none of the outputs will ever influence that state variable. Note the symmetry of this criterion to the controllability criteria.

8.1. CONTROLLABILITY AND OBSERVABILITY

355

Formally for a continuous time system (Eqn 2.37), the n-state system is observable if the np × n observability matrix O is of rank n where 

   O=    def

C CA CA2 .. .

CAn−1



   ,  

or in the discrete case



   O=    def

C CΦ CΦ2 .. .

CΦn−1

      

(8.6)

Some authors, perhaps to save space, define O as a row concatenation of matrices rather than stacking them in a column as done above. Problem 8.1 1. What are the dimensions of the observability and controllability matrices? What is the maximum rank they can achieve? 2. Establish C and O for the Newell & Lee evaporator. 3. Examples B-9-13, B-9-10, B-9-11, [150, p771] 4. Examples B-6-6, B-6-7, [148, p805] 5. [155] gives some alternative mathematical definitions for controllability and observability: A system is controllable if and only if rank(B, A − λi I) = n, for i = 1, · · · , n

(8.7)

and observable if and only if rank(C⊤ , A⊤ − λi I) = n, for i = 1, · · · , n

(8.8)

where λ are the eigenvalues of A. Construct a M ATLAB m-file implementation using these algorithms. Test your routines on various systems, perhaps using the rmodel command.

8.1.3 Computing controllability and observability The M ATLAB functions ctrb and obsv create the controllability and observability matrices respectively, and the rank function can be used to establish the rank of them. While the concept of observability and controllability applies to all types of dynamic systems, Eqns 8.1 and 8.6 are restricted to linear time invariant systems. Read problem A-6-1 [148, p745] for a discussion on the equivalent term “reachable”. The algorithms given above for computing controllability or observability, (equations 8.1 and 8.6 or the discrete equivalents), seem quite straight forward, but are in fact often beset by subtle numerical errors. There exist other equivalent algorithms, but many of these are also susceptible to similar numerical problems. Issues in reliable numerical techniques relevant to control are discussed in a series of articles collected by [157]. An example quoted in [155] illustrates common problems to which these simple algorithms can fall prey. Part of the problem lies in the reliable computation of the rank of a matrix which is best done by computing singular values.

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

356

Problem 8.2 Write a M ATLAB m-file to compute the exponential of a matrix using the Taylor series formula, ∞ X 1 k eAt = A k! k=0

Test your algorithm on

A=



−49 24 −64 31



and comment on the expected accuracy of your result. Problem 8.3 1. When using good (in the numerical reliability sense) software, we tend to forget one fundamental folklore of numerical computation. This folklore, repeated in [157, p2], states

If an algorithm is amenable to “easy” hand calculation, then it is probably a poor method if implemented in the finite floating point arithmetic of a digital computer. With that warning in mind, calculate the singular values of   1 1 A= µ 0  0 µ √ where µ is a real number such that |µ| < ǫ where ǫ is the machine precision. (Note that this effectively means that 1 + µ2 = 1 where as 1 + µ > 1 when executed on the computer.) Calculate the singular values both analytically, and using the relationship between singular values and the eigenvalues of A⊤ A. 2. Calculate the controllability of the system     1 µ 1 A= , B= 0 1 µ √ with |µ| < ǫ. Solve this both analytically and numerically.

8.1.4 State reconstruction If a system is observable, we should in principle, be able to reconstruct the states based only on the current, and perhaps historical outputs. So, supposing we have collected the following input/output data, time (k) 0 1 2

u(k) 4 5 –

y(k) −4 4 36

x1 (k) ? ? ?

x2 (k) ? ? ?

we should be able to reconstruct the states assuming a model of the form     0 1 0 xk+1 = xk + uk −3 2 1   yk = 4 0 x k

8.1. CONTROLLABILITY AND OBSERVABILITY

357

Note that we cannot simply invert the measurements back to the states, partly because the measurement matrix is not square. However we can see that y(k) = 4x1 (k) from the measurement relation, so we can immediately fill in some of the blank spaces in the above table, in the x1 (k) column; x1 (0) = −1, x1 (1) = 1, x1 (2) = 9. From the model relation, we can see that x1 (k + 1) = x2 (k), so we can set x2 (0) = x1 (1) = 1. Now we have established the initial condition  ⊤ x(0) = −1 1

and with the subsequent manipulated variable history u(t), we can calculate x(t) simply using the recursive formula, Eqn. 2.38. This technique of estimation is sometimes called state reconstruction and assumes a perfect model and no measurement noise. Furthermore, the estimation reconstruction takes, at most, n input-output sample pairs. As a check, we can construct the observability matrix,        4 0  C = 4  0 1 O= =  CΦ 4 0 × 0 −3 2

0 4



which clearly has a rank of 2 indicating that the state reconstruction is in fact possible.

We can generalise this state reconstruction scheme outlined above, following [19, p315], for any observable discrete plant xk+1 = Φxk + ∆uk yk = Cxk where we wish to reconstruct the current state, xk , given past values of input and output, uk , uk−1 , . . . and yk , yk−1 , . . . Our basic approach will be to use the outputs from the immediate past n samples, to develop linear equations for the n unknown states at the point n samples in the past. We will then use the knowledge of the past inputs to roll this state forwards to the current sample k. For the present development, we will just consider SISO systems. Listing the immediate previous n values finishing at the current sample k gives yk−n+1 = Cxk−n+1 yk−n+2 = CΦxk−n+1 + C∆uk−n+1 yk−n+3 = CΦ2 xk−n+1 + CΦ∆uk−n+1 + C∆uk−n+2 .. . yk = CΦn−1 xk−n+1 + CΦn−2 ∆uk−n+1 + · · · + C∆uk−1 To make things clearer, we can stack the collected input and output values in a vector,     yk−n+1 uk−n+1  yk−n+2    uk−n+2       .. , U = Yk =     .. k−1 .     .  yk−1  uk−1 yk

(8.9)

(8.10)

and we note that the input vector collection Uk−1 is one element shorter than the output vector collection Yk . Now we can write Eqn. 8.9 more succinctly as Y k = Oxk−n+1 + Wu Uk−1

(8.11)

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

358 with matrices defined as  C  CΦ  2  O =  CΦ  ..  .

CΦn−1





   Wu =   

   ,  

0 C∆ CΦ∆ .. .

0 0 C∆ .. .

CΦn−2 ∆ CΦn−3 ∆

··· ··· ··· .. .

0 0 0 .. .

· · · C∆

      

(8.12)

and we may recognise O is the observability matrix defined in Eqn. 8.6. Solving Eqn. 8.11 for the states (in the past at sample time k − n + 1) gives xk−n+1 = O −1 Y k − O −1 Wu Uk−1

(8.13)

provided O is non-singular. This is why we require the observability condition to be met for state reconstruction. The minor problem with Eqn. 8.13 is that it delivers the state n sample times in the past, rather than the current state, xk , which is of more immediate interest. However, it is trivial to use the plant model and knowledge of the past inputs to ‘roll the states onwards’ to current time k. Repeated forward use of the model gives xk = Φn−1 xk−n+1 + Φn−2 ∆uk−n+1 + Φn−3 ∆uk−n+2 + · · · + ∆uk−1 The entire procedure for state reconstruction is summarised in the following algorithm. Algorithm 8.1 State reconstruction assuming a perfect observable model and no noise. Given xk+1 = Φxk + ∆uk ,

yk = Cxk

then the current state, xk , is given by the linear equation xk = Ay Yk + Bu Uk−1 where the matrices are Ay = Φn−1 O +  Bu = Φn−2 ∆

Φn−3 ∆ · · · ∆



− Φn−1 O+ Wu

and Y k , Uk−1 are defined in Eqn. 8.10 and O, Wu are defined in Eqn. 8.12. We should note: • To reconstruct the state (at the current time k), we need to log past input and output data, and the minimum number of data pairs required is n, where n is the number of states. Any more will gives a least-squares fit. • Since we invert O, this matrix must not be singular. (Alternatively we require that the system must be observable.) For the multivariable case we should use the pseudo-inverse, O+ , as written above. • We use in the algorithm, but do not invert, the controllability matrix. A simple state reconstructor following Algorithm 8.1 is given in Listing 8.1.

8.2. STATE SPACE POLE-PLACEMENT CONTROLLER DESIGN

359

Listing 8.1: A simple state reconstructor following Algorithm 8.1. function x_est = state_extr(G,Yk,Uk) % Back extract past state from outputs & inputs (assuming observable) 4

9

14

19

24

29

Phi = G.a; Del = G.b; C = G.c; error(ABCDCHK(Phi,Del,C)) % bullet proofing [p,n] = size(C); [n,m] = size(Del); Wo = obsv(G); % same as: O = obsv(Phi,C) Ay = Phiˆ(n-1)/Wo; % similar to Φn−1 O −1 S = C*Del; for i=1:n-2 S = [S; C*Phiˆi*Del]; % Building Wu end % for zC = zeros(p,m); % or zeros(size(C*Del)); Wu1 = [zC;S]; Wu = Wu1; for i=n-3:-1:0 Wu1 = [zC; Wu1]; Wu1(end-p+1:end,:) = []; Wu = [Wu, Wu1]; end % for Co = Del; % Reversed controllability matrix for i=1:n-2 Co = [Phiˆi*Del,Co]; end % for Bu = Co - Ay*Wu; x_est = Ay*Yk + Bu*Uk; return

Fig. 8.1 illustrates the results of the state reconstruction algorithm in the case where there is no model/plant mismatch, but there is noise on the input and output. Given that the algorithm has the wrong u(t) and y(t) trends, then the reconstructed states (⋆ in Fig. 8.1) are slightly different from the true states.

8.2 State space pole-placement controller design This section describes how to design a controller to control a given process, using state space techniques in the discrete domain. When a process engineer asks the control engineer to design a control system, the first question that the control engineer should ask back, is ‘what sort of performance is required?’ In this way, we start with some sort of closed loop specification, which, for example, may be that we demand that the system return to setpoint after a disturbance with no offset, or rise to a new setpoint in a reasonable time, perhaps one open-loop time constant. If the loop is a critical one, then we may wish to tighten this requirement by specifying a smaller time to reach control, or conversely if we have a non-critical loop we could be satisfied with a more relaxed settling time requirement. It is our job as control engineers to translate these vague verbal requirements into mathematical constraints, and if possible, then design a controller that meets these constraints. When we talk about a response, we are essentially selecting the poles (or eigenvalues) of the closed loop transfer function, and to some lesser degree, also the zeros. Specifying these eigenvalues by

360

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN 0.3 y actual y

Output

0.2 0.1 0 −0.1

0

1

2

3

4

5

6

7

1 x 1

0.5

1

estimate

x

0 −0.5 −1

0

1

2

3

4

5

6

7

2 x

2

estimate

2

1 x

Figure 8.1: Reconstructing states. Since the state reconstructor is given the undisturbed input and a noisy output, then it is no surprise that the estimated states ⋆ are slightly different from the true states (solid lines in the lower two trends).

0 −1

0

1

2

3 4 time [s]

5

6

7

changing the controller parameters is called controller design by pole placement. In order to design a controller by pole placement, we must know two things: 1. A dynamic model of the process, and 2. what type of response we want (i.e. what the closed loop eigenvalues should be). However choosing appropriate closed loop poles is non-trivial. Morari in [136] reminds us that “poles are a highly inadequate measure of closed loop performance”, and he continues to assert that because of the lack of guidance to the control designer, “pole placement techniques have been abandoned by almost everybody today”. Notwithstanding this opinion, it is still instructive for us to understand how our closed loop response is affected by different choices of eigenvalues, and how this forms the basis for more acceptable tuning methods such as linear quadratic controllers discussed in the following chapter. Suppose we have a single input–multiple output (SIMO) system such as xk+1 = Φxk + ∆uk

(8.14)

where u is a scalar input and we wish to control all n states by using a proportional feedback control law such as u = −Kx (8.15) where K is called the state feedback gain matrix. (Actually in this SIMO case, the gain “matrix” collapses to a row vector). Substituting Eqn 8.15 into Eqn 8.14 gives the closed loop response as xk+1 = (Φ − ∆K) xk

(8.16)

8.2. STATE SPACE POLE-PLACEMENT CONTROLLER DESIGN

361

Now we desire (Φ − ∆K) to have the n eigenvalues at arbitrary positions µ1 , µ2 , · · · , µn To achieve this, we must check that arbitrary pole placement is achievable. In other words, the system must be controllable. This means that the controllability matrix Co , must be of rank n. If this condition is satisfied, we can design the feedback gain matrix K, by using Ackermann’s formula i−1  h . . . K = 0 0 ··· 0 1 α(Φ) (8.17) ∆ .. Φ∆ .. · · · .. Φn−1 ∆ where α is the matrix characteristic equation of the desired closed loop transfer function. Note that the matrix to be inverted in Eqn 8.17 is the discrete controllability matrix Co , hence the need for full rank. A quick way to calculate α(Φ) is to use poly and polyvalm. For instance we can verify the Cayley-Hamilton theorem, (any matrix satisfies its own characteristic equation), elegantly using >> A = rand(3) % take any test matrix A = 0.0535 0.0077 0.4175 0.5297 0.3834 0.6868 0.6711 0.0668 0.5890 >> polyvalm(poly(A),A) % Cayley-Hamilton theorem, should = 0 ans = 1.0e-016 * 0.1388 0.0119 0.1407 0.1325 0 0.7412 -0.0496 0.0073 0.5551

Algorithm 8.2 SIMO state-space pole-placement Given a system model, x˙ = Ax + Bu, or discrete version, xk+1 = Φxk + ∆uk , and design requirements for the closed loop poles, µ, then 1. Check the controllability of the system, ctrb(A, B), or ctrb(Φ, ∆). If not all the states are controllable, then terminate the algorithm, otherwise carry on. 2. Compute the characteristic polynomial, α, and substitute either matrix A or Φ. 3. Compute the row-vector state feedback gain using Eqn. 8.17. Example Pole placement of the double integrator system. In this example, we wish to design a controller for the discrete double integrator system sampled at T = 1 that has closed loop eigenvalues at µ = 0.5 ± 0.5i. In this case we will assume a zeroth-order hold on the discretisation. >> Gc = tf(1,[1 0 0]); >> G = ss(c2d(Gc,1));

giving matrices  2 Φ= 2

−0.5 0



,

∆=



1 0



To use Ackermann formula, Eqn. 8.17, we need to both compute the controllability matrix and the matrix characteristic equation α.

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

362 >> mu = [0.5+0.5i; 0.5-0.5i]; >> alpha = polyvalm(poly(mu),G.a) >> Cb = ctrb(G.a,G.b) Finally the gain is given by

def

Note that as α(z) = (z − µ1 )(z − µ2 ) = z 2 − z + 0.5, then   1 −0.5 α(Φ) = Φ2 − Φ + 0.5I = 2 −0.5 and that the controllability matrix   1 2 C= 0 2

>> K = [0 1]/Cb*alpha

has full rank. Finally the feedback gain is   K = 1 −0.25

We can easily check that the closed loop poles are as required with >> eig(G.a-G.b*K) ans = 0.5000 + 0.5000i 0.5000 - 0.5000i

Rather than constructing Ackermann’s equation by hand, M ATLAB can design a pole placement controller using the acker or the preferred place function. The latter gives an estimate of the precision of the closed loop eigenvalues, and an optional error message if necessary. [K,PREC] = place(G.a,G.b,mu) K = 1.0000 -0.2500 PREC = 15

Eqn 8.15 assumes that the setpoint is at x=0. (We can always transform our state variables by subtracting the setpoint so that this condition is satisfied, but this becomes inefficient if we are likely to change the setpoint regularly.) In these cases, it is better to modify our control law from Eqn 8.15 to u = K(r − x) (8.18) where r is a vector of the state setpoints or reference states, now assumed non-zero. Consequently the closed loop response is now modified from Eqn 8.16 to xk+1 = (Φ − ∆K) xk + ∆Krk

(8.19)

8.2.1 Poles and where to place them While pole-placement seems an attractive controller design strategy, the problem lies in deciding where the closed loop poles out to be. Listing 8.2 designs a pole-placement controller for the blackbox, G(s) = 0.98/(2s + 1)(s + 1), with discrete closed loop poles specified, somewhat arbitrarily, at µT = [0.9, 0.8]. Listing 8.2: Pole-placement control of a well-behaved system 1

>> Gc = tf(0.98,conv([2 1],[1,1])) % Blackbox model >> G = ss(c2d(Gc,0.1)) % Convert to discrete state-space with sample time Ts = 0.1 >> [Phi,Delta,C,D] = ssdata(G);

8.2. STATE SPACE POLE-PLACEMENT CONTROLLER DESIGN T

T

2

µ = [0.9, 0.8]

µ = 0.6e

6

6

6

4

4

4

2

2

2

°

± j80

T

µ = [−0.9, −0.8]

1

States x & x

363

0

0

0

−2

−2

−2

input

0

2

0

2

4

100

100

100

50

50

50

0

0

0

−50

−50

−50

−100

0

2

1 2.2

0.5 ℑ

4

2.7

0

1.7 1.2 0.2 0.40.7 0.6 0.8 0.2 0.2

2.7

−0.5 −1

−100

4

2.2 −1

1

2

1 2.2

0.5

2.7

0

−1

−100

4 1.7 1.2 0.2 0.40.7 0.6 0.8 0.2 0.2

2.7

−0.5

0.7 1.2 1.7 0 ℜ

0

2.2 −1

2

4

0

2

4

1 2.2

0.5

2.7

0

1

−1

1.7 1.2 0.2 0.40.7 0.6 0.8 0.2 0.2

2.7

−0.5

0.7 1.2 1.7 0 ℜ

0

2.2 −1

0.7 1.2 1.7 0 ℜ

1

Figure 8.2: Pole-placement of the black box for three different pole locations. From left to right: ◦ (a) µT = [0.9, 0.8], (b) µT = [−0.9, −0.8], and (c) µ = 0.6e±j80 .

6

>> lambda = [0.9 0.8]'; % Desired closed loop discrete poles µT = [0.9, 0.8] >> K = place(Phi,Delta,lambda)% Compute controller gain K K = 2.4971 -2.2513

Now we can check the closed loop performance from a non-zero initial condition with Gcl = ss(Phi-Delta*K,zeros(size(Delta)),eye(size(Phi)),0,Ts); 2

x0 = [1; -2]; % start position initial(Gcl,x0)

The results of a controlled disturbance recovery is given in the left hand plot of Fig. 8.2. However an obvious question at this point is where exactly should I place the poles. The three trends in Fig. 8.2 illustrate the difference. A conservative choice is as given above is where we place the poles in right-hand side of the origin, on on the real axis close to the +1 point. In this case I chose µT = [0.9, 0.8]. The second choice is the mirror image of those poles µT = [−0.9, −0.8], and the third choice is a pair of complex conjugates at 0.66 ±80◦ . Clearly there is a trade off between the speed of the disturbance rejection, the amount of input energy, and the degree of oscillation. If we can quantify these various competing effects, then we can design controllers systematically. This is the subject of optimal control given in the next

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

364 chapter.

8.2.2 Deadbeat control If the system is controllable such that any arbitrary poles are allowable, one is naturally inclined to extrapolate the selection to poles that will give a near perfect response? Clearly a perfect response is one when we are always at the setpoint. If a step change in reference value occurs, then we instantaneously apply a corrective measure to instantaneously push the system to the new desired point. A system that rises immediately to the new setpoint has a closed loop time constant of τ = 0 or alternatively a continuous pole at s = −∞. This corresponds to a discrete pole at e−∞T or the origin. If we decide to design this admittedly rather “drastic” controller, we would select all the desired closed loop poles at µ = 0. Such a controller is feasible in the discrete domain and is called a deadbeat controller. The design of a deadbeat controller is the same as for an arbitrary pole placement controller. However it is better to use the acker function rather than the place function, because the place function will not allow you to specify more multiple eigenvalues than inputs. This restriction does not apply for the Ackermann algorithm. Suppose we design a deadbeat controller for the continuous plant    3 −0.3 0 0 0 −0.5 2  x +  −2  u x˙ =  5 0 −2 −0.5 

(8.20)

To design a deadbeat controller, we specify the desired discrete closed loop eigenvalues as µ = 0 and select a sample time of T = 4, we obtain K=



3.23 · 10−2

The closed loop transition matrix is

−3.69 · 10−4

1.98 · 10−2





 0.075 0.003 −0.139 0.095  Φcl = Φ − ∆K =  −0.063 −0.019 −0.060 −0.133 −0.056

and we could also compute that all the elements in Φ3cl are in the order of 10−19 and all the eigenvalues of eig(Φ − ∆K) are in the order of 10−7 as required. Such a matrix where An−1 6= 0, but An = 0 is called a Nilpotent matrix. Fig. 8.3 shows the impressive controlled response of the plant (Eqn. 8.20) under deadbeat control. The top half of the diagram shows the states which converge from the initial condition, ( x0 =  ⊤ −2 −3 1 ), to the setpoint x=0 in only three sample times (3T = 12 s). It takes three sample times for the process to be at the setpoint, because it is a third order system. The deadbeat controlled response looks almost perfect in Fig. 8.3. In fact, the states are only guaranteed to be at the setpoint (after t > 12s) at the sample times. In between these times anything can happen. We can investigate this by repeating the simulation at a smaller time interval (say T = 0.05 s) but with the same input as before, to see what happens between the sample intervals. (This is how I evaluated the smooth state curve in Fig 8.3 between the states at the controller sample time denoted with a • in Listing 8.3.) Note that the states are oscillating between the samples, but quickly die out after 10 seconds.

8.2. STATE SPACE POLE-PLACEMENT CONTROLLER DESIGN

365

Deadbeat controller 3 2

states

1 0 −1 −2 −3

input

0.04 0.02 0 0

5

10 15 time (s), sample time T=4

20

Figure 8.3: The states (top) and the manipulated variable (bottom) for the deadbeat controlled response. The states at the controller sample times are denoted with a • and after the third sample time, t ≥ 12, the states remain exactly at the setpoint at the sample times.

Listing 8.3: A deadbeat controller simulation 1

6

x0 = [-2 -3 1]'; % initial condition dt =4; tf =dt*5;t =[0:dt:tf]'; % time vector A = [-0.3,0,0;0,-0.5,2;0,-2,-0.5];% continuous plant B = [3;-2;5]; Gc = ss(A,B,eye(3),0); % create continuous model Gd = c2d(Gc,dt,'zoh'); % discrete model mu = [0;0;0]; % desired closed loop eig K = acker(Gd.a,Gd.b,mu); % construct deadbeat controller

11

Gd_cl = Gd; Gd_cl.a = Gd.a-Gd.b*K; % closed loop [y,t,x]= LSIM(Gd_cl,zeros(size(t)),[],x0); U = [-K*x']'; % back extract input 16

21

% reduce sample time at same conditions to see inter-sample ripple dt = dt/100; t2 = [0:dt:tf]'; % new time scale [ts,Us] = stairs(t,U); % create new input ts = ts + [1:length(ts)]'/1e10; ts(1) = 0; U2 = interp1(ts,Us,t2); % approx new input [y2,t2,x2]= LSIM(Gc,U2,t2,x0);% continuous plant simulation subplot(2,1,1);plot(t,x,'o',t2,x2); % plot results subplot(2,1,2);plot(ts,Us);

Naturally under practical industrial conditions, the plant will not be brought under control so rapidly owing to either model–plant mismatch, or to manipulated variable constraints. This type of controller can be made more robust by specifying a larger sample time, which is in fact the only tuning constant possible in a deadbeat controller. Ogata gives some comments and cautions about deadbeat control in [148, pp670-71].

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

366

Problem 8.4 Create a system with eigenvalues of your choice; say v=



−0.2 −0.3 −0.1

T

and design a deadbeat controller. Simulate this using the dlsim function. (Try a sample time of ≈ 7.) Investigate the same controller, but at a higher sampling rate and plot the intersample behaviour of the states. Investigate the effect on the gain when using different sample rates.

8.3 Estimating the unmeasured states The pole-placement control design strategies as developed in § 8.2 utilises all the states in the control law u = −Kx so implicitly assumes that all the states are measurable. In many cases this is not practically possible, so the only alternative then is to estimate the states. The states can be reconstructed using the outputs, the inputs, and the model equations. In fact we need not restrict ourselves to just estimating states, we could also estimate derived quality control variables, or even estimate the outputs themselves. The quantities that we estimate are known as observers, and offer cost and reliability advantages over actual sensors in many applications. The simplest state estimator is where we use a model and subject it to the same input u that is ˆ is the estimate for the true state x. applied to the true process. The resultant x ˆ k+1 = Φˆ x xk + ∆uk

(8.21)

If we know the true model (Φ,∆) and the manipulated variable history u(k), then this estimator ˆ 0 . Since we have no feedback inforwill work provided we select the correct initial condition x mation as to how well we are doing, this estimator is called an “open loop” estimator. If the conditions stated above are not met, and they will rarely be satisfied in practice, then the estimator will provided estimates that will probably get worse and worse. The error of the estimate is ˆk ǫk = xk − x (8.22) Ideally, we would like to force this error vector to zero. This is actually still a control problem, although while we are not controlling the plant, we are controlling the error of the estimate scheme. We introduce a feed back error scheme such as ˆ k+1 = Φˆ x xk + ∆uk + L (yk − Cˆ xk )

(8.23)

which is called a prediction error observer since the prediction is one sample period ahead of the observation. L is a (n × 1) column vector and is called the observer gain matrix and is a design parameter. Now the error model is ǫk+1 = (Φ − LC) ǫk

(8.24)

We must select the matrix L such that the observer system Φ − LC is stable and has eigenvalues (observer poles) that are suitably fast. This means that even if we were to get the initial condition wrong for x0 , we can still use the estimator since any initial error will eventually be forced to zero. Typically we would choose the poles of the observer system (Eqn 8.24) much faster than the openloop system. To be able to solve for L, the system must be observable. For many chemical process applications, the sampling rate is relatively slow, since the processes are generally quite slow, so the basic estimator of Eqn 8.23 can be modified so that the prediction

8.4. COMBINING ESTIMATION AND STATE FEEDBACK

367

of xk+1 uses the current measurement yk+1 rather than the previous measurement yk as is the case in Eqn 8.23. This is only possible if the computational time is short, compared with the sample time, but if this is the case, then the sample period is better utilised. This type of formulation is termed a current estimator and both are described in [70, pp147–8] and in terms of the Kalman filter in [148, pp873–75]. The current estimator is ¯ k+1 = Φˆ x xk + ∆uk

(8.25)

ˆ k+1 = x ¯ k+1 + L yk+1 − C¯ x xk+1



(8.26)

In practice for most systems, the two forms (current and prediction estimators) are almost equivalent. The design of the observer gain L by pole-placement is similar to the controller gain K given in §8.2, but in the observer case we have the closed loop expression eig(Φ − LC) rather than However we note that

eig(Φ − ∆K)

eig(Φ − LC) = eig(ΦT − CT LT )

since eig(A) = eig(AT ), so we can use the M ATLAB functions place or acker for the observer problem by using the dual property L = place(ΦT , CT , λ)T Table 8.1 shows the equivalent relationships between the matrices used for observation and regulation and make the relevant substitution. Table 8.1: The relationship between regulation and estimation

Control Φ B K Co eig(Φ − ∆K)

Estimation Φ⊤ C⊤ L⊤ Ob eig(Φ − LC)

8.4 Combining estimation and state feedback We can combine the state feedback control from §8.2 with the state estimation from §8.3 into a single algorithm. This is useful because now we can use the estimator to provide the states for our state feedback controller. For linear plants, the design of the state feedback controller is independent from the design of the observer. The block diagram shown in Fig. 8.4, which is adapted from [19, p438], shows the configuration of the estimator and controller. Remember that in this example, we have no model plant mis-match, the plant is linear, but we do not know the initial conditions of the states x0 . The equations are summarised below. The true process is xk+1 = Φxk + ∆uk (8.27) and the measurement is yk = Cxk

(8.28)

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

368

- ∆

-+ 6

- q −1

- C

-+

Φ 

Plant ǫ

L  input, u

- ∆

? ˆ - + - q −1 x 6

output, y

- −C

-+

Φ  Estimator

−K 

State feedback

Figure 8.4: Simultaneous control and state estimation but we do not know x, so we estimate it with ˆ k+1 = Φˆ x xk + ∆uk + L (yk − Cˆ xk )

(8.29)

uk = −Kˆ xk

(8.30)

xk+1 = Φxk − ∆Kˆ xk

(8.31)

and the scalar control law is Combining Eqns 8.30 and 8.27 gives

and combining Eqns 8.29 to 8.30 gives ˆ k+1 = (Φ − LC − ∆K) x ˆ k + LCxk x Concatenating Eqns 8.27 and 8.32 together gives the homogeneous equation      xk+1 xk Φ −∆K = zk+1 = ˆ k+1 ˆk x x LC Φ − ∆K − LC

(8.32)

(8.33)

I will call the transition matrix for Eqn 8.33 the closed loop observer transition matrix (Φcl−ob ). Ogata gives a slightly different formulation of the combined observer–state feedback control system as Eqn 6-161 in [148, p714]. Ogata also recommends choosing the observer poles 4–5 times faster than the system response. Example: Combined state-feedback and observer Suppose we are given a continuous plant G(s) =

0.98 , (3s + 1)(2s + 1)

T = 0.1

8.5. GENERIC MODEL CONTROL

369

which we will sample at T = 0.1. The design specifications are that the estimator poles are to be relatively fast compared to the controller poles     0.8 0.92 def def λest = and λctrl = 0.85 0.93 We can design the controller and estimator gains as follows Listing 8.4: Pole placement for controllers and estimators 1

6

G = tf(0.98,conv([2 1],[3 1])); % Blackbox plant Gss = ss(G); % convert to state-space % Now special version with full outputs Gss1 = Gss; Gss1.c = eye(2); Gss1.d = [0;0]; T = 0.1; % seconds Gssz = c2d(Gss,T); % convert to discrete state-space

11

16

p = [0.92 0.93]'; % Now design controller gain L = place(Gssz.a, Gssz.b, p); % eig(Φ − ∆K) pe = [0.80 0.85]'; % Now design estimator gain K = place(Gssz.a', Gssz.c', pe)'; % eig(Φ − LC) eig(Gssz.a-K*Gssz.c) - pe % Test results should be zero

which gives controller and observer gains as L=



1.3848 1.6683



,

and K =



0.2146 0.4109



Fig. 8.5(a) gives the S IMULINK configuration for the controller which closely resembles the block diagram given in Fig. 8.4. To test the estimation and control, we will simulate a trend where the actual and estimated starting conditions are different, namely     1 1.6 ˆ0 = x0 = , which is not the same as x 1 2 The trends shown in Fig. 8.5(b) show the (discrete) estimated states converging rapidly to the true continuous states, and that both converge, slightly less rapidly, to the setpoint.

8.5 Generic model control Control of multivariable nonlinear processes such as x˙ = f (x, u, d, θ, t)

(8.34)

is in general, much harder than that for linear processes. Previously we discussed the simple state feedback control law; u = −K(x∗ − x) where x∗ is the desired state vector or setpoint. We showed that we could augment this simple proportional only law to incorporate integral action to ensure zero offset to get a control law such as 9.71. Now suppose that we wish to control not x, ˙ ⋆ . We now wish to but the derivative of x, dx/dt, to follow some desired derivative trajectory (x)

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

370

yv

states

4

To Workspace

4 4

Mux1 2

states

K*u

2

input output

ctrl Gain

plant BB

output

C model 2

K*u

estimator Gain1

K* u 2

K*u

2

1

2

2

z

2

Delta

Unit Delay K*u

Phi

2

(a) S IMULINK configuration

2 x1 x2

1.5

xe1 xe2

1 states

2

2

0.5

0

−0.5

−1

0

1

2

3 4 time, [s]

5

6

(b) Estimated and true states

Figure 8.5: Simultaneous control and estimation

7

8.5. GENERIC MODEL CONTROL

371

find u(t) such that x˙ = r(t) where r(t) is some reference function that we can specify and where dx∗ /dt is given by Eqn 8.34. For any controller, when the process is away from the desired state, x∗ , we want to force the rate of change of the states, x˙ to be such that it is moving in the direction of the desired setpoint, and in addition, we would like the closed loop to have zero offset. The control law Z t ∗ ∗ ˙ = K1 (x − x) + K2 (x) (x∗ − x) dτ (8.35) 0

˙ ∗ = x, ˙ so substicombines these two weighted ideas. Ignoring any model-plant mistmatch, (x) tuting in the plant dynamics Eqn. 8.34 to Eqn. 8.35, we get the control law Z t ∗ f (x, u, t) − K1 (x − x) − K2 (x∗ − x) dτ = 0 (8.36) 0

Solving Eqn. 8.36 for u is the control law and this scheme is called “Generic Model Control” or GMC and was developed by Lee and Sullivan in [116]. Note that solving Eqn 8.36 for u is in effect solving a system of m nonlinear algebraic equations. This must be done at every time step. Actually, the solution procedure is not so difficult since the previous solution ut−1 can be used as the initial estimate for ut .

8.5.1 The tuning parameters The GMC control law (Eqn 8.36) imbeds a model of the process, and two matrix tuning parameters, K1 and K2 . Selecting different tuning parameters changes the type of response. Assuming we have a perfect model, the control law (Eqn 8.36) is Z t ∗ x˙ = K1 (x − x) + K2 (x∗ − x) dτ (8.37) 0

If we differentiate once the control law Eqn 8.37, we get ¨ = K1 (x˙ ∗ − x) ˙ + K2 (x∗ − x) x ∗ ¨ + K1 x˙ + K2 x = K1 x˙ + K2 x∗ x

(8.38)

and taking Laplace transforms of 8.38 gives s2 x + sK1 x + K2 x = sK1 x∗ + K2 x∗ K1 s + K2 x(s) = 2 x∗ (s) s + K1 s + K2 2τ ξs + 1 = 2 2 τ s + 2τ ξs + 1 where

1 τ=√ , k2

k1 ξ= √ 2 k2

(8.39)

(8.40)

or alternatively 2ξ 1 (8.41) , k2 = 2 τ τ Note that Eqn 8.39 is a modified second-order transfer function. The time domain solution to Eqn 8.39 for a step change in setpoint, X ∗ (s), is given by   √  √ p  −ξt 1−ξ 2 t 1−ξ 2 t 2 sin + ξ 1 − ξ 1 + ξ 2 cos 1 − ξ2 − e τ τ τ , ξ 6= 1 (8.42) x(t) = 2 1−ξ k1 =

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

372 1.6 1.4

response

1.2 1 0.8 0.6 ξ=0.2 ξ=0.5 ξ=1 ξ=3

0.4 0.2 0

0

2

4 6 Normalised time, τ=1

8

10

(a) Various choices for shape factor. ξ = 0.2, 0.5, 1 and ξ = 3.

(b) A 3-dimensional plot of the same relation.

Figure 8.6: The normalised (τ = 1) response curve for a perfect GMC controller for various choices of shape factor ξ. For the limiting case where ξ = 1, the solution to Eqn. 8.39 simplifies to just x(t) = 1 + e

−t τ



t −1 τ



(8.43)

Fig. 8.6 shows the response for a perfectly GMC controlled process for different ξ. Note that as ξ ⇒ ∞, the output response approaches a step response at t = 0, and as ξ ⇒ 0, the output tends to x(t) = sin(2πt) + 1. This improvement comes, naturally, at the expense of decreased robustness. Fig. 8.7 shows the comparison between the overshoot, decay ratio and the ξ tuning value. These values are easily obtained from Fig. 8.6 or analytically starting with Eqn 8.42. Note that for ξ > 1, there is no oscillation in the response, and that a ξ ≈ 0.22 gives a quarter decay ratio. overshoot decay ratio

overshoot & decay ratio

1

Figure 8.7: The relation between the shape factor ξ, the maximum overshoot (solid) and decay ratio (dashed) for the perfectly controlled GMC response when τ = 1

0.8 0.6 0.4 0.2 0 0

0.2

0.4 0.6 0.8 shape factor ξ

1

1.2

8.5. GENERIC MODEL CONTROL

373

Algorithm 8.3 Designing the GMC controller To choose appropriate values for K1 and K2 , do the following: 1. For each state to be controlled, choose an appropriate shape from Fig. 8.6 for the response. In other words, choose a ξ value. For tight control with little overshoot, choose a shape corresponding to ξ ≈ 3 or higher , or if the loop is not so important, choose a more conservative response such as ξ ≈ 1. 2. Specify the time scale by choosing an appropriate value for τ . Often it is convenient to specify the rise time. For distillation column control, you may choose a cross over time of 30 minutes, or for a flow controller you may wish to cross the setpoint after only 5 seconds. The time scale is application dependent. 3. From the specified ξ and τ , evaluate the scalars k1 and k2 using Eqn. 8.41. 4. The diagonal matrices K1 and K2 are formed by collecting the k scalars into diagonal n × n matrices.

8.5.2 GMC control of a linear model Since GMC can be applied to a nonlinear process, one would expect it to work especially well given a linear process x˙ = Ax + Bu. Now the GMC control law simplifies from the general Eqn. 8.36 to   Z t −1 ∗ ∗ K1 x − (K1 + A)x + K2 u=B (x − x) dτ (8.44) 0

−1

noting that B must exist and hence at least should be square. This means that we must have the same number of manipulated variables as state variables. It is easy to test such a controller using a stable random model using rmodel. Hopefully our randomly generated control matrix B is inevitable. (If it is not, just re-run the script file.) To tune the response, I will select a slightly different shape factor and time constant for each state, namely ξ1 = 0.7, τ1 = 1.5 ξ2 = 0.8, τ2 = 2.6 Running the script file in Listing 8.5 gives results much like Fig. 8.8. Listing 8.5: GMC on a Linear Process dt = 0.5; n = 2;% sample time & # of states m = n; p = 1; % ensure square system & 1 output 3

[A,B,C,D]=rmodel(n,p,m); % generate random continuous model D = zeros(size(D)); C = eye(size(C)); % not interesting [Phi,Del] = c2dm(A,B,C,D,dt,'zoh'); % discretise 8

13

x0 = round(3*randn(n,1)); % nice starting position t = [0:dt:80]'; % simulation lifetime Xspt = [square(t/8), 0.75*square(t/8*0.7)+3]; % setpoint % GMC tuning rules zeta=[0.7 0.8]'; tau=[1.5 2.6]'; % Shape factor ζ, & time constant τ , for each state.

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

374

K1 = 2*diag(zeta./tau); K2 = diag(1.0./tau./tau); % Diagonal K1 , K2 . Ie = zeros(size(x0)); % reset integrator

18

x= x0; X = []; Uc = []; for i=1:length(t) % start simulation err = (Xspt(i,:)-x); % current error (x∗ − x). Ie = Ie + err*dt; % update integral Rt rhs = K1*err + K2*Ie - A*x; % K1 x∗ − (K1 + A)x + K2 0 (x∗ − x) dτ u = B\rhs; % Solve (linear) control law, Eqn. 8.44.

23

x = Phi*x + Del*u; % Do 1-step integration X = [X; x']; end % for

Uc = [Uc;u']; % collect input for plotting

28

plot(t,[Xspt, X],t,Uc,'--')

% Refer Fig. 8.8.

Linear GMC

Outputs & setpoints

6 4 2 0 −2

0

20

40

60

80

0

20

40 time

60

80

20

inputs

15

Figure 8.8: The response of a randomly generated linear process controlled by GMC. Top: state (—) and setpoint (dotted) trajectories; Bottom=manipulated variables). See also Fig. 8.9.

10 5 0 −5

We would expect the GMC controller to perform well, but what should really convince us is if the actual response y(t) follows the analytical & desired trajectory, y ⋆ (t) since GMC is really a model reference controller. These two curves are compared in Fig. 8.9 which shows an enlarged portion of Fig. 8.8. The differences between the actual response and the specified trajectory are due to sampling discretisation. This demonstration of the GMC controlling a linear process does not do the algorithm justice, since the controller really is intended for nonlinear processes. This is demonstrated in the following section.

8.5. GENERIC MODEL CONTROL

375

2

output & reference output

1.5 1 0.5 0 −0.5

Actual y *

Reference y setpoint

−1 48

50

52

54 time

56

58

60

62

Figure 8.9: Comparing the actual response, y, (solid line) to a setpoint change with the expected response, y ⋆ , (– · –). This response is a zoomed part of the response given in Fig. 8.8.

8.5.3 GMC applied to a nonlinear plant Section 8.5.2 did not show the true power of the GMC algorithm since the plant was linear and any linear controller such as an LMR would work. However this section introduces a nonlinear model of a continuously stirred tank reactor, CSTR, from [123]. The CSTR model equations are Fa Ta Uar Fb Tb (Fa + Fb )T ∆H T˙ = r− (T − Tc ) + − − V V V ρCp ρV Cp (Fa + Fb )Ca Fa Cai − −r C˙a = V V Fc Uar T˙c = (Tci − Tc ) + (T − Tc ) Vc ρVc Cp

(8.45) (8.46) (8.47)

where the reaction kinetics are second order E

r = Ke− RT Ca2

(8.48)

The state, manipulated and disturbance variables as explained in Table 8.2 are defined as1 def

x=



T

Ca

Tc

T

,

def

u=



Tci

Cai

Fb

The model parameters are also given in Table 8.2.

T

,

def

d=



Ta

Fa

Tb

Fc

T

(8.49)

The plant dynamics defined by Eqns 8.45 to 8.47 are nonlinear owing to the reaction rate r, being an exponential function of the temperature T . This type of nonlinearity is generally considered significant.

Designing the GMC controller First we note that have n states and n manipulated variables. Thus the B matrix, or at least a linearised version of the nonlinear control function will be square. We also note that the GMC algorithm assumes that the process states (x) are measured, hence the measurement relation must 1 The original reference had only one manipulated variable T . This was changed for this simulation so the GMC is ci now a true multivariable controller.

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

376

Table 8.2: The state, manipulated and disturbance variables and parameter values for the Litchfield nonlinear CSTR, [123]. (a) State, input and disturbance variables

variable T Ca Tc Tci Cai Fb Ta Fa Tb Fc

description reactor temperature concentration of A temperature of jacket temperature of cooling inlet inlet concentration of A inlet flow of stream B inlet temp. of stream A inlet flow of stream A inlet temp. of stream B cooling flow

units K kgmol m−3 K K kgmol m−3 m3 s−1 50◦ C (333K) 3.335 · 10−6 m3 s−1 50◦ C (333K) 3 · 10−4 m3 s−1

(b) Model parameters

parameter V Vc ρ Cp

value 0.0045 0.0074 1000 4.187

units m3 m3 kg/m3 kJ/kg/K

parameter K E/R ∆H Uar

value 16.6 · 106 5.6452 · 103 −74.106 · 103 0.175

units m3 /kmol/s K kJ/kg kW/K

be C = I. The GMC control law, Eqn. 8.36, for this case is    Fa   Uar ∆H (T − Tc ) 0 0 TbV−T Tci V (Ta − T ) − ρCp r − ρC p    0 Fa − Ca   Cai  +  − FaVCa + r  − V V Fc Uar Fc Tc F 0 0 + (T − T ) − b c Vc Vc ρVc Cp Z t K1 (x∗ − x) − K2 (x∗ − x) dτ = 0 0

Now you will notice that the control law is a system of algebraic equations unknown in u. For this case, the control law is linear in u because I had the freedom of choosing the manipulated variables carefully. If, for example, I had chosen Fa rather than Fb as one of the manipulated variables, then the system would be control nonlinear, and hence more difficult to solve. But in this case, the system is control linear, the GMC control law is a linear system of algebraic equations, and that the 3 × 3 matrix to be inverted is in a lower diagonal form already making the computation straight forward.

Simulating GMC with a nonlinear process We will use a GMC controller to drive the states to follow a setpoint as follows:   ⊤  0 ≤ t < 5 min.   300 0.03 290  ⊤ x∗ = 310 0.03 290 5 ≤ t < 10 min.  ⊤   310 0.025 295 t > 10 min.

 ⊤ starting from an initial condition of x0 = 290 0.035 280 and with a relatively coarse sample time of T = 10 seconds. We set the shape factor ξ = 0.5, and the time constant for the

8.5. GENERIC MODEL CONTROL

377

1 1 response to τ = 20 seconds. This gives k1 = 20 and k2 = 400 . The disturbance variables (d) are assumed constant for this simulation and are taken from Table 8.2.

The state derivative x˙ as a function of x, u, d, θ, t is evaluated using Eqns 8.45 to 8.47 and is given in listing 8.7 which is called by the integrator ode45 in listing 8.6. Listing 8.6: GMC for a batch reactor 1

6

11

16

21

26

31

% GMC CSTR simulation % Ref: Litchfield, Campbell & Locke Trans I Chem E Vol 57 1979 x0 = [290, 0.035, 280]'; % dt = 10; t = [0:dt:15*60]'; % Xspt = [300+10*square(t/150,70), 295-5*square(t/150,30)]; % d = [333 3.335e-6 333 3e-4]'; % Ta = d(1); Fa = d(2); Tb = d(3);

initial condition sample time (seconds) 0.03+0.05*square(t/150), ... setpoint disturbance vector constant Fc = d(4);

k1 = 1/20; k2=1/400; % GMC tuning constants K1 = eye(3)*k1; K2 = eye(3)*k2; %Parameters for the CSTR V = 0.0045; Vc = 0.0074; rho = 1000.0; K = 16.6e6; ER = 5.6452e3; dH = -74.106e3; Cp = 4.187; %kJ/Kg.K Uar = 0.175; % kW/K rCp = rho*Cp ; x=x0;Ie=zeros(size(x)); X=[]; U=[]; for i=1:length(t) % start simulation xspt = Xspt(i,:)'; % current setpoint T = x(1); Ca = x(2); Tc = x(3); % state variables Ie = Ie+(xspt-x)*dt; % update integral error r = K*exp(-ER/T)*Ca*Ca; % reaction rate R = [Fa/V*(Ta-T)-dH*r/rCp-Uar*(T-Tc)/rCp;-(Fa*Ca/V+r); ... -Fc*Tc/Vc+Uar/rCp/Vc*(T-Tc)]; A = [0 0 (Tb-T)/V; 0 Fa/V -Ca/V; Fc/Vc 0 0]; u = A\(K1*(xspt-x)+K2*Ie - R); % solve for u GMC control law % u = max(zeros(size(u)),u); % ensure feasible [ts,xv] = ode45('fcstr',[0,dt/2,dt],x,[],u, ... V, Vc, K, ER, dH, rCp, Uar, Ta, Fa, Tb ,Fc); % integrate nl ODEs x = xv(3,:)'; % keep only last state

36

X(i,:) = x'; U(i,:) = u'; end %for plot(t,[X,U]); % will need to rescale

Listing 8.7: The dynamic equations of a batch reactor 1

6

function x_dot = fcstr(t,x,flag,u, ... V, Vc, K, ER, dH, rCp, Uar, Ta, Fa, Tb ,Fc); % CSTR dynamic model, called from gmccstr.m T = x(1); Ca = x(2); Tc = x(3); % states Tci = u(1); % Inputs, Coolant temp in Kelvin Cai = u(2); Fb = u(3);

378

11

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

r = K*exp(-ER/T)*Caˆ2; % reaction rate kmol/m3/s x_dot(1,1)=(Fa*Ta+Fb*Tb-(Fa+Fb)*T)/V - dH*r/rCp - Uar/V/rCp*(T-Tc); x_dot(2,1)=(Fa*Cai - (Fa+Fb)*Ca)/V - r ; x_dot(3,1)=Fc*(Tci-Tc)/Vc+Uar*(T-Tc)/rCp/Vc; return % fcstr.m

Physically the manipulated variables are constrained to be positive, and unless these constraints are added explicitly to the GMC optimisation control law, negative values for some of the inputs will occur. In the above example I simply clamp the input when these violations occur. If you removed the u=max(zeros(size(u)),u); line from the control law, you will have the unconstrained version that ignores the physically realistic constraints which is the case shown in the simulations given in Fig. 8.10. Fig 8.10 shows the response of the CSTR controlled by the GMC. The upper plots show the state trajectories and the lower plots give the manipulated variables used. Note that the controlled response is good, but not perfect as we can still see some interaction between the states. The reaction concentration Ca particularly seems strongly coupled to the other states, and this coupling is not completely removed by the GMC controller. We could improve on this response both by decreasing the sample time, or tightening the controller design specifications. Temp T,T (deg C)

40

C

30 20 10

0

5

10

15

0

5

10

15

0

5

10

15

0

5

10

15

Conc C

A

0.4

0.2

40 30 20 10 40

b Ai

Figure 8.10: The nonlinear CSTR controlled by a GMC controller where ξ = 0.5 and τ = 20 seconds and sample time T = 10 seconds. Upper: The state trajectories (temperatures T and Tc , and reaction concentration Ca ). Lower: The manipulated variable trajectories Tci and Cai and 5 · 104 Fb .

Conc C , Flow F * 5e4

Ci

Temp T (deg C)

0

20 0 −20

time (min)

Just for fun, we can plot a three dimensional plot of the trajectory of the state variables from the CSTR example under GMC control. Fig. 8.11 shows the actual state trajectory (solid line) converging to the 4 distinct setpoints, (∗), in state space. Note that the independent variable time

8.5. GENERIC MODEL CONTROL

379

is removed in this illustration.

Temperature T

c

35 30 25 20 15 10 0.5 0.4 40

0.3

35 30

0.2 Conc C

A

25 0.1

20 15

Temperature T

Figure 8.11: A phase plot of T, Tc and Ca for the GMC controlled CSTR example. The state trajectory is the solid line, and the setpoints are ∗.

Alternative manipulated variables choices Manipulating the inlet concentration of A or the inlet temperature of the cooling fluid is not very practical. It is much easier to manipulate flow rates rather than temperatures of concentrations. Therefore in this situation, a better manipulated variable vector would be u = [Fa , Fb , Fc ]⊤ rather than that used above. Note however that if we had chosen Fa , Fc and Tci as u, we would have a control problem that is not only nonlinear, but one that is also degenerate. If you construct the GMC control law of Eqn. 8.36, you will get a structure such as    Z ⋆ 0 0 Fa  ⋆ 0 0   Fc  = g(x) + K1 (x⋆ − x) + K2 (x⋆ − x) (8.50) 0 ⋆ ⋆ Tci

where we know everything on the right hand side of Eqn. 8.50, (it is a constant for the purposes of this calculation) and wish to solve for u. Unfortunately, however, we can see from the structure matrix on the left hand-side of Eqn. 8.50, that Fa appears alone in two equations, and the remaining two manipulated variables appear together in one equation. Thus this nonlinear algebraic system is degenerate since in general we cannot expect a single unknown Fa to satisfy two independent conditions. Note that even though we do not have an overall degree of freedom problem, (we have three unknowns and three equations), we do have a sub-structure that has a degree of freedom problem. Problem 8.5 1. Re-run this simulation and test the disturbance rejection properties of the GMC controller. You will need to choose some suitable disturbance profile. 2. Re-run the simulation for different choices of GMC tuning constants. For each simulation, verify that the response is the linear response that you actually specified in the GMC design. (You may need to decrease the sampling interval to T ≈ 2 seconds to get good results.) Try for example; (a) τ = 20, ξ = 1.5

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

380 (b) τ = 5, ξ = 0.5 (c) any other suitable choice.

8.6 Exact feedback linearisation For certain nonlinear systems, we can derive controllers such that the closed loop input/output behaviour is exactly linear. This is quite different from our traditional approach of approximating the linearities with a Taylor series approximation and then designing a linear controller based on the approximate model. Designing exact feedback linearisation uses nonlinear results from the field of differential geometry, which, to say the least, is somewhat abstract to most engineers. Lie algebra for nonlinear systems will replace matrix algebra for linear systems, and Lie brackets and Lie derivatives will be extensions to normal matrix operations. A good tutorial of this topic with applications of interest to the process industry, and one from where most of this material was taken, is [105] and the follow up, [106]. A review of nonlinear control for chemical processes which includes a section on exact feedback linearisation is [28] and the classic text book for this and other topics in nonlinear control is [187]. Extensions for when the process is not affine in input, and for systems where the relative degree is greater than unity are discussed in [83].

8.6.1 The nonlinear system We will only deal with SISO nonlinear systems of the form: x˙ = f (x) + g(x)u

(8.51)

y = h(x)

(8.52)

where f , g are vector functions, or vector fields, h(x) is a scalar field and the input u, and output y are scalars. Note that the system described by Eqn 8.51 is written in affine form, that is the manipulated variable enters linearly into the system. It is always possible to transform an arbitray system into affine form by introducing a new variable. For example, given the non-affine system x˙ = f (x, u) we can define a new input, ν, which is the derivative of our original input, u˙ = ν, so now our augmented system becomes       x˙ f (x, u) 0 = + ν (8.53) u˙ 0 1

which is now in affine form. Whether creating a new variable ν which requires differentiating the input is practical, or even feasible under industrial conditions is a different matter.

8.6.2 The input/output feedback linearisation control law Given the nonlinear system in Eqn 8.51 and 8.52, we will try to construct a control law of the form u = p(x) + q(x)v

(8.54)

where v is the command signal or setpoint, such that the closed loop system (obtained by substituting Eqn 8.54 into Eqns 8.51 and 8.52) is x˙ = f (x) + g(x)p(x) + g(x)q(x)v

(8.55)

y = h(x)

(8.56)

8.6. EXACT FEEDBACK LINEARISATION

381

and is linear from reference variable v to output y. The dashed box in Fig. 8.12 contains the nonlinearity, but as far as we are concerned, viewing the system from the outside, it may as well be a linear black box.

command v(t)



6

-+

u(t) -Π

6

-+

6

6

x˙ -

1 s

x(t) - h(·)

-

output y(t)

f (·)  q(x)

p(x)

6

6

g(·) 

Nonlinear plant

Figure 8.12: The configuration of an input/output feedback linearisation control law Note that for a controller in this configuration, the internal states will still be nonlinear. Notwithstanding, once we have a linear relation from reference, v(t), to outputs, y(t), it is much easier to design output-based controllers to control this now linear system, rather than the original nonlinear system. It is also clear from Fig. 8.12, that the controller requires state information to be implemented. The control design problem is to select a desired linear response, perhaps by specifying the time constants of the desired closed loop, and then to construct the p(x) and q(x) functions in the control law, Eqn. 8.54. These are given by the following relations: −(Lrf h(x) + β1 Lr−1 h(x) + · · · + βr−1 Lf h(x) + βr h(x)) f Lg Lr−1 h(x) f 1 q(x) = Lg Lr−1 h(x) f

p(x) =

(8.57) (8.58)

where the Lie derivative, Lf h(x), is simply the directional derivative of the scalar function h(x) in the direction of the vector f (x). Here, the Lie derivative is calculated by n

Lf h(x) = f (x)⊤ ·

∂h(x) X ∂h(x) fi (x) · = ∂x ∂xi i=1

(8.59)

One can apply the Lie derivative operator repeatedly, L2f = Lf Lf either to the same function, or to different functions as in Lg L2f . The relative order of a system such as Eqns 8.51–8.52 is the smallest integer r such that Lg Lr−1 h(x) 6= 0 f

(8.60)

An alternative interpretation of relative order is that r is the smallest order of derivatives of y that depends explicitly on u. For linear systems, the relative order is simply the difference between the number of poles and the number of zeros of the system, i.e. na − nb .

382

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

Finally, the βi in Eqn 8.57 are the user-chosen tuning constants that determine how our output will respond to the command v. They are defined by dr y dr−1 y dy + β + · · · + βr−1 + βr y = v 1 r r−1 dt dt dt

(8.61)

Typically it is convenient to choose Eqn. 8.61 as some sort of stable low-pass filter, such as a Butterworth filter. Algorithm 8.4 Exact feedback linearisation design procedure:

1. We are given a single-input/single-output nonlinear model (which may need to be transformed into affine form), Eqn 8.51–8.52. 2. Find the relative order, r, of the system using Eqn. 8.60. This will govern the order of the desired response differential equation chosen in the next step. (If r = 1, perhaps a GMC controller is easier to develop.) 3. We choose a desired linear response, which we consider reasonable, in the form of Eqn 8.61, that is, we need to choose r time constants or equivalent. 4. We create our exact linearising nonlinear controller, Eqn 8.54 using the relations Eqns 8.57 and 8.58 by constructing Lie derivatives. (A symbolic manipulator such as M APLE may be useful here.) 5. Closing the loop creates a linear input/output system, which can be controlled by a further controller sitting around this system, designed by any standard linear controller design technique such as LMR or pole placement.(However this is hardly necessary since we have the freedom to choose any reasonable response in step 3.)

Cautions and restrictions This technique is not applicable if the “zero dynamics” are unstable. This is analogous to the linear case where we are not allowed to cancel right-hand plane zeros with unstable poles. Technically, it works, but in practice, the slightest model mis-match will cause an unstable pole which in turn will create an unstable controller. This then excludes process systems with dead time. Clearly also owing to the nature of the cancellation of the process nonlinearities, exact feedback linearisation is very sensitive to modelling errors. The technique demands state feedback, but only delivers output linearisation. Full state linearisation techniques do exist, but exist only under very restrictive conditions.

8.6.3 Exact feedback example Building an exact feedback controller is relatively easy for well behaved smooth nonlinear systems. The only calculus operation required is differentiation, and this poses few problems for automated computer tools. This example shows how to build such a controller using a simple program written for a symbolic manipulator. With this program, we can subsequently change the system, and regenerate the new nonlinear control law. This is a departure from all the other simulations presented so far, since here we can change the entire structure of the process in our program, not just the order or the values of the parameters, and subsequently re-run the simulation.

8.6. EXACT FEEDBACK LINEARISATION

383

Suppose we have a simple 3-state nonlinear SISO system,       x˙1 0 sin(x2 ) + (x2 + 1)x3  x˙2  =  x51 + x3 + 0 u x˙3 1 x21 | {z } | {z } g(x) f (x)   y= 1 0 0 x | {z } h(x)

(8.62)

(8.63)

which is already in the form of Eqn. 8.51–Eqn. 8.52 or affine form, and we wish to construct an exact feedback linearised system following Eqn. 8.54. To do this we will follow Algorithm 8.4. Since we will need to compute some Lie derivatives analytically, Lf h(x) = f (x)⊤ ·

∂h(x) ∂x

to establish the relative order r, it may help to write a small procedure to do this automatically. Listing 8.8 gives an example using the Symbolic toolbox. Listing 8.8: Find the Lie derivative for a symbolic system 2

function L = lie_d(F,h,x) % Find the Lie derivative Lf h(x) % Note jacobian returns a row vector L = F'*jacobian(h,x)'; % f (x)⊤ · return

∂h(x) ∂x

First we define the actual nonlinear functions f (x), h(x), and g(x) for our particular problem. % define : must be real or will have conjugate problems syms x1 x2 x3 real x = [x1 x2 x3]'; 4

F = [sin(x2)+(x2+1)*x3; x1ˆ5+x3; x1ˆ2]; % Eqn. 8.62 h = [1 0 0]*x g = [0 0 1]'

The Lie derivatives are easy to construct, Lf h(x) = f (x)⊤ · =



∂h(x) ∂x

sin(x2 ) + (x2 + 1)x3 , x51 + x3 , x21

= sin(x2 ) + (x2 + 1)x3 and check in M ATLAB using the routine giving in Listing 8.8

3

>> lie_d(F,h,x) ans = sin(x2)+(x2+1)*x3





 1 × 0  0

384

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

To find the relative degree, we simply repeatedly call the function in Listing 8.8 starting at r = 1 and incrementing r until Lg Lr−1 h(x) 6= 0 at which point we have established the relative order. f Listing 8.9: Establish relative degree, r (ignore degree 0 possibility) 2

Lfn = h % Dummy start LgLfnh = lie_d(g,h,x) % Lg L1f h(x) case. r = 1; % # relative degree counter

7

while LgLfnh == 0 r =r+1; % increment relative degree counter Lfn = lie_d(F,Lfn,x) % need to build-up LgLfnh = lie_d(g,Lfn,x) % stop when non-zero end % while

Now that we know the relative degree r, we can design our desired response filter Listing 8.10: Design Butterworth filter of order r. 1

[z,p,K] = buttap(r) % Low-pass Butterworth filter analogue prototype beta = real(poly(p)); %[B,beta] = butter(r,2,'s') % Alternative: but must scale with B(end).

and now construct the controller components p(x) and q(x) to form the closed loop. Listing 8.11: Symbolically create the closed loop expression 2

7

qx = 1/LgLfnh; % Controller components q(x), p(x) , Eqn. 8.57, Eqn. 8.58. px = beta(r+1)*h; Lfn = h; for i=r-1:-1:0 Lfn = lie_deriv(f,Lfn,x); px = px+ beta(i+1)*Lfn; end px = -px*qx; xdot = f+g*(px+qx*v) % Closed loop, Eqn. 8.55, hopefully linear.

In practice, we are only interested in the control law >> (px+qx*v) % Control law, u = p(x) + q(x)v ans = (-4*x1-2*2ˆ(1/2)*(sin(x2)+(x2+1)*x3)-(x1ˆ5+x3) *(cos(x2)+x3)-x1ˆ2*(x2+1))/(x2+1)+1/(x2+1)*v

which could, in principle, now be implemented on the plant. A good test for this controller is to see if the closed loop response is indeed indistinguishable from the specified linear filter. As demonstrated in Fig. 8.13, there is no discernable difference indicating that the nonlinear controller design worked as intended in this instance. Problem 8.6 Create an exact nonlinear feedback controller for a penicillin fermentation process.

8.6. EXACT FEEDBACK LINEARISATION

4

3

385

1 s

3

MATLAB Function xdot

3 3

Integrator

u(1)

3

h(x)

Signal Generator

Scope butter

Analog Filter Design

(a) S IMULINK configuration 1.5 output

1

linear filter

y=x

1

0.5 0 −0.5 −1 −1.5

0

10

20

30

40

50 time

60

70

80

90

100

(b) The closed loop response of the controlled nonlinear system compared to the desired linear response

Figure 8.13: This example of exact feedback linearisation shows that there is no practical difference between the output of the nonlinear system and the desired linear filter. The system dynamics are: dX = µ(S, X)X − DX dt dS = −σ(S, X)X + D(Sf − S) dt y=X

(8.64) (8.65) (8.66)

where X, S are the cell mass and glucose concentration, D is the dilution rate and manipulated variable, and Sf is the feed glucose concentration, considered constant in this example. The empirical growth rate expressions are: µx S Kx X + S σ(S, X) = µ(S, X)/Yxs + π(S)/Yps + m µp S π(S) = Kp S(1 + S/Ki ) µ(S, X) =

and for simulation purposes, use parameters values as µx µp Yxs Ki

1.5 3.45 0.45 0.89

Kx Kp Yps m

2.34 1.56 0.78 0.34

(8.67) (8.68) (8.69)

CHAPTER 8. MULTIVARIABLE CONTROLLER DESIGN

386

and manipulated, disturbance and initial conditions as

manipulated disturbance initial conditions

D Sf X0 S0

0> x0 = [0.2, 0.1]'; % Start guess for Kc and τi . >> x = fminunc(@foptslink_pi,x0) % See function in Listing 9.3. 3

8

Optimization terminated successfully: Current search direction is a descent direction, and magnitude of directional derivative in search direction less than 2*options.TolFun x = 66.5402 25.6549

The optimisation routine found that a gain of Kc = 66.5 and an integral time of τi = 25.7 minimised our integral-time squared error performance index.

9.2.4 An optimal batch reactor temperature policy This example illustrates how to establish an optimal input profile u(t) for a given system and initial conditions. In this section we are going to approximate the smooth profile with a small number of constant variables and we are going to use parametric optimisation. Later in section 9.3.3 we will repeat this optimisation problem, but solve for the continuous profile using functional optimisation. Suppose we have a batch reactor as shown in Fig. 9.7 in which two chemical reactions are carried out in series, k2 k1 A → B → C

(9.5)

The first reaction produces the desired product (B) which is what we wish to maximise after two hours reaction duration, but the second reaction consumes our valuable product, and produces a byproduct C, which naturally we wish to minimise.

A

Open reactor after 2 hours ? - product (at end) - condensate (cold)

steam (hot) heating coil

Figure 9.7: Production of a valuable chemical in a batch reactor.

def

In this case, the only manipulated variable is the jacket temperature, u = T and we will consider def

the concentrations of A and B to be the two states, x = [ca , cb ]T . As the jacket temperature varies, so does the reaction temperature which in turn affects the Arrhenius rate constants (k1 , k2 ), which changes the ratio of desired product to by-product. The plant dynamics are given by the reaction

9.3. THE GENERAL OPTIMAL CONTROL PROBLEM

397

kinetics and initial conditions are dx1 = −2e−6/u x1 , x1 (t = 0) = 0.9 dt dx2 = 2e−6/u x1 − 5e−11/u x2 , x2 (t = 0) = 0.1 dt Our objective for the operation of this reactor is to maximise the amount of B after a given reaction time, in this example t = 2 hours, by adjusting the temperature over time as the reaction progresses, or Z t=2 0 dt (9.6) J = x2 (t = 2) + 0

If we decide to operate at a constant temperature, then Fig. 9.8(a) shows us which temperature is the one to maximise the amount of B at the end of the reaction. Alternatively, if we decide to run the batch reactor for 1 hour at one temperature, and the second hour for another then we would expect the optimum to improve. Fig. 9.8(b) shows the three dimensional response surface for this case. 2 Temperatures

0.5 0.45

0.5

0.4

0.4 b

final C

C final

0.35 0.3

0.3 0.2

0.25

0.1

0.2

0 10

0.15 0.1

5

0

1

2

3 4 Temperature

5

6

(a) Optimisation of a single constant temperature

5 0 10

7

T

1

T

2

(b) The response surface of the objective function when using two temperatures

Figure 9.8: By using two temperatures, we can improve (slightly) the final product concentration. We could in principle continue this discretisation of the input profile. Fig. 9.9 shows the situation when we decide to use three temperatures equally spaced across the 2 hour duration of the batch. In this case the objective function becomes a response volume so we must use volume visualisation techniques to see where the optimum lies. Fig. 9.10 compares the optimum trajectories for the case where we select 1,2,3,5 and 7 equally spaced temperatures divisions. Also given is the limiting case where the number of temperature divisions tend to ∞. The analytical computation for this latter case is given in section 9.3.3.

9.3 The general optimal control problem The optimal control problem has the following characteristics: 1. A scalar performance index or cost function, J (u) that is to be minimised (or maximised) by adjusting the manipulated variables u(t).

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

398

0.42 0.4

5

0.38

4

0.36

3

0.34

2

0.32

T

3

6

1 8

0.3 10 6 T

2

5 4

0

0.28 0.26

T1

(a) The response volume when using 3 temperatures

(b) Isosurfaces of the response volume better showing where the optimum point in 3D space is.

Figure 9.9: Temperature profile optimisation using 3 temperatures. Compare with Fig. 9.8.

Figure 9.10: The optimum temperature profiles for cases where we have different numbers of temperature divisions. Note how as the number of allowable temperature divisions increase, the discretised trajectory converges to the smooth analytical optimum profile.

9.3. THE GENERAL OPTIMAL CONTROL PROBLEM

399

2. Constraints that must be either: (a) continuously satisfied, that is the constraint must be satisfied for all time, or (b) satisfied only at the end of the optimisation problem, a terminal constraint. These constraints can either be hard (they must never be violated under any conditions, or soft (they can be violated under special conditions). 3. The optimisation horizon is the length of time over which the optimisation is allowed to take place. Sometimes the horizon is infinite, but in practical cases the horizon has some upper limit over which an optimal solution is sought to minimise the objective function. The optimal control problems can be written as a standard mathematical optimisation problem, thus many algorithms and therefore computer programmes exist to give a solution. Two common solution procedures are Pontryagin’s maximum principle and dynamic programming. [63, pp16–20] or [51] covers these aspects in more detail and a simple introduction to Pontryagin’s maximum principle is given in [172, Chpt 13] and [168, pp 84–105]. The optimal control problem as described above is quite general, and the solution will be different for each case. Section 9.3.1 develops the equations to solve the general optimal control problem using variational calculus and Section 9.2.4 demonstrates this general approach for a simple nonlinear batch reactor application. The accompanying M ATLAB simulation clearly shows that the computation required is involved, and motivates the development of less general linear optimal control designs. This results in the Linear Quadratic Regulator (LQR) described in subsequently Section 9.4. There are many other texts that describe the development of optimal controllers. Ogata has already been mentioned, and you should also consult [100, p226] for general linear optimal control, [163, 167, 168] for chemical engineering applications and [38] is considered a classic text in the optimisation field. A short summary available on the web is [45]. A survey really highlighting the paucity of applications of linear quadratic control, (which is a simplified optimal controller for linear systems), in the process industries is [97].

9.3.1 The optimal control formulation To develop our optimal controller, we need to define, as listed in §9.3, an objective function, a feasible search space, and list our constraints. The Optimal Control Problem, or OCP, is when given a general nonlinear dynamic model, x˙ = f (x, u, t),

x(t = 0) = x0

(9.7)

we wish to select u(t) to minimise the scalar performance criteria J = φ (x(tf )) + | {z } Mayer problem

|

Z

tf

|0

L(x, u, t) dt {z }

(9.8)

Lagrange problem

{z

Bolza problem

}

This performance criteria J (u) to be minimised is quite general and is usually related to process economic considerations and is often called a cost function. Technically Eqn. 9.8 is termed a functional since it maps the function u(t) to the scalar J . The first term of Eqn. 9.8 is called the termination criteria, and is only concerned about the penalty of the final state. The second

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

400

integral term is concerned with the cost incurred getting to the final state. This final term is typically some sort of ISE or IAE type term. For example if L(x, u, t) = x⊤ Qx where the matrix Q is a positive definite matrix, then this term computes the squared deviations in state variables and is used when we are concerned with the cost of deviations in state variables. Alternatively if L(x, u, t) = 1 then we are concerned sorely with the total time for the optimisation (which we want to minimise). If only the terminal criterion, φ, is present, we have a Mayer problem, if we are only concerned with the integral term, we have a Lagrange problem, and if we have both terms, then we have what is known as a Bolza problem. We can convert between all three types of problems by introducing extra state variables, see [51, p71] for more hints how to do this. We solve this constrained optimisation problem by converting it to an unconstrained optimisation problem using generalised Lagrange multipliers. These are a vector of introduced variables λ, that are pre-multiplied to each of the constraint equations and then added to the original objective function. Now converting Eqns 9.8 and 9.7 to an unconstrained optimisation problem gives Z tf   ˙ dt L(x, u, t) + λ⊤ (f − x) (9.9) J =φ+ 0 Z tf   H − λ⊤ x˙ dt (9.10) =φ+ 0

where the scalar H is termed the Hamiltonian and is defined def

H = L + λ⊤ f We can eliminate x˙ in Eqn 9.10 by integrating by parts giving Z tf  0  ⊤ ⊤ H + λ˙ x dt J = φ + λ x + tf

(9.11)

(9.12)

0

Using variational calculus, we get the Euler-Lagrange equations which define the dynamics of the co-state variables ˙λ = − ∂H with final condition λ(tf ) = ∂φ (9.13) ∂x ∂x tf

where we emphasise that the co-state dynamics are specified by terminal boundary conditions as opposed to the initial conditions given for the state dynamics in Eqn. 9.7.

Finally, the optimum control input profile is given by extremitising the Hamiltonian, or equivalently solving for u such that ∂H =0 (9.14) ∂u Solving these two equations, and applying the manipulated variable to our dynamic system (Eqn. 9.7) will result in optimal operation. In many practical cases, the manipulated variable may be constrained between an upper and lower limit. In this case, we would not blindly use the stationary point of the Hamiltonian (Eqn. 9.14) to extract the manipulated variable, but we would simply minimise H, now conscious of the constrained manipulated variable. In summary, the Optimal Control Problem, or OCP, is given in Algorithm 9.1.

9.3. THE GENERAL OPTIMAL CONTROL PROBLEM

401

Algorithm 9.1 The Optimal Control Problem The solution procedure of the optimum control problem (OCP) is as follows: 1. Given a dynamic model with initial conditions x˙ = f (x, u, t),

x(t = 0) = x0

(9.15)

and a scalar performance index which we wish to extremetise over a finite time from t = 0 to t = tf , Z tf L(x, u, t) dt (9.16) J (u) = φ (x(tf )) + 0

2. then we can form the Hamiltonian def

H = L + λT f

(9.17)

where the n introduced co-state dynamics are given by ˙λ = − ∂H with final condition λ(tf ) = ∂φ ∂x ∂x tf

(9.18)

3. and the optimum input is given by extremetising H, or by solving ∂H =0 ∂u

(9.19)

for u(t). Section 9.3.3 solves the optimal control problem for some simple examples. including the optimal temperature profile of a batch reactor from section 9.2.4. For the batch reactor we have only a termination criteria in our objective function, and no state or manipulated variable energy cost. This makes the calculation somewhat easier.

9.3.2 The two-point boundary problem Equations 9.7, 9.13–9.14 need to be solved in order to find the desired u(t), the optimal control policy at every sampling instance. This, however, is not a trivial task. Normally we would expect to know the initial conditions for the states so in principle we could integrate Eqn. 9.7 from the known x(0) for one sample interval, excepting that we do not know the correct control variable (u) to use. However, we can solve for the instantaneous optimum u by solving Eqn. 9.14. The only problem now is that we do not know the correct co-state (λ) variables to use in Eqn. 9.14. So far the only things we know about the co-state variables are the dynamics (Eqn 9.13), and the final conditions, but unfortunately not the initial conditions. These types of ODE problems are known as Two Point Boundary Value problems. If we have n state dynamic equations, then the number of state and co-state dynamic equations is 2n. We know n initial state conditions, but that still leaves us n initial conditions short for the costates. (To solve the system of ODEs, we must know as many initial conditions as DEs). However we do know the final values of the costates, and this information supplies the missing n conditions. Methods to solve two point boundary value problems are described in [161, Chp16] and [196, p176] and are in general much harder to solve than initial value ODE problems, and often require

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

402

an iterative approach. The most intuitive way to solve two point boundary value ODEs is by the shooting method or as it is sometimes termed, the boundary condition iteration, or BCI [167, p237]. This technique is analogous to the artillery gunner who knows both his own and the enemy’s position, but does not know the correct angle to point the gun so that the shell lands on the enemy. Typically an iterative approach is used where the gun is pointed at different angles with an observer who watches where the shells land, and then communicates with the gunner what corrections to make. However, the iteration loop outside the integration is not the only complication. In many physical cases, numerically integrating the state equations backwards or the co-state equations forwards is unstable, where integrating in the opposite direction causes no problems. An alternative method known as Control Vector Iteration (CVI) avoids some of the failings of the BCI method. A comparison of these two techniques is given in [95]. Perhaps the most robust scheme is to use collocation which is the strategy used by the M ATLAB routine bvp4c designed for boundary value problems.

9.3.3 Optimal control examples The following examples illustrate two optimal control problems. In both cases we follow Algorithm 9.1 and use the S YMBOLIC toolbox to assist in developing the necessary equations.

Rayleigh’s optimal control problem We wish to minimise J (u) =

Z

2.5

0

 x21 + u2 dt

(9.20)

subject to the state dynamics and state initial conditions

x1 (t = 0) = −5

x˙ 1 = x2 , x˙ 2 = −x1 + 2 −

0.1x22



x2 (t = 0) = −5

x2 + 4u,

For this problem it is convenient to use the Symbolic toolbox to develop the necessary equations. First we define the state dynamics, the objective function, and form the Hamiltonian. % define symbolic variables

1

>> syms u lam1 lam2 x1 x2 real

6

>> x = [x1 x2]'; lambda = [lam1 lam2]'; % x = [x1 , x2 ]T , λ = [λ1 , λ2 ]T >> f = [x(2); ... -x(1)+(2-0.1*x(2)ˆ2)*x(2) + 4*u];% State dynamics x˙ = f (x, u) R >> phi = 0; L = x(1)ˆ2 + uˆ2; % Terms in the objective function, φ + L dt

def

def

>> H = L + lambda'*f % Hamiltonian, H = L + λT f H = lam1*x2 + uˆ2 + x1ˆ2 - lam2*(x1 - 4*u + x2*(x2ˆ2/10 - 2))

Given the Hamiltonian, we can construct the co-state dynamics, and the terminal conditions from Eqn. 9.18. 1

>> lam_dot = -jacobian(H,x)' lam_dot =

% Eqn. 9.18. Note: Jacobian is a row vector

9.3. THE GENERAL OPTIMAL CONTROL PROBLEM

6

403

lam2 - 2*x1 lam2*((3*x2ˆ2)/10 - 2) - lam1 >> lam_final = jacobian(phi*x(1),x)' lam_final = 0 0

The optimal control input is given by solving Eqn. 9.19 for u(t), or

2

>> uopt = solve(diff(H,u),u) % Eqn. 9.19 uopt = (-2)*lam2

Now all that is left to do is to form and solve our two-point boundary value problem. We can substitute the expression for the optimum u(t) in the state dynamics, and append the co-state dynamics

2

7

>> x_dot = subs(f,u,uopt); >> [x_dot; lam_dot] % State & co-state dynamics ans = x2 - 8*lam2 - x1 - x2*(x2ˆ2/10 - 2) lam2 - 2*x1 lam2*((3*x2ˆ2)/10 - 2) - lam1

To solve the boundary value ODE problem, we take the state and co-state dynamic equations developed above and insert into the two-point boundary value ODE routine bvp4c where we need to specify the dynamics, the boundary conditions, and additionally estimate a suitable grid for the collocation points. We also need to given an initial estimate trajectory for the state and co-state profiles over the integration interval, but in this case I will simply supply constant trajectories.

3

8

13

zdot = @(t,z) ... [z(2); ... -8*z(4) - z(1) - z(2)*(z(2)ˆ2/10 - 2); ... z(4) - 2*z(1) ;... z(4)*(3/10*z(2)ˆ2-2) - z(3)]; % State & co-state dynamics % Set up boundary conditions x0 = [-5;-5]; lam_final = [0;0]; % Initial state conditions & terminal co-state conditions BCres = @(a,b) [a(1:2)- x0; ... b(3:4)- double(lam_final)]; % Boundary residuals solinit = bvpinit(linspace(0,2.5,10),[-1 -1 -0.2 -0.5]) sol = bvp4c(zdot,BCres,solinit); % Now solve TPBVP

The optimum profile is given in Fig. 9.11 where we can quickly check that the boundary conditions are satisfied. We can also visually check that the optimum input u⋆ (t) = −2λ2 (t) as required. The circles plotted show the position of the collocation points and we should check that they capture the general trend of the profile.

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

404

6 x1 x2

4

x(t)

2 0 −2 −4 −6 10

u(t)

5

0

−5 5 0 λ(t)

Figure 9.11: The optimum control policy for the Rayleigh problem. The upper two trends are the states, the middle is the optimal control policy u⋆ (t), and the lower two trends are the corresponding co-states.

λ1

−5

λ2 −10

0

0.5

1

1.5

2

2.5

time

An optimal batch reactor policy revisited In the optimum profile determination for the batch reactor example in section 9.2.4, we approximated the continuous profile with a finite series of constant zeroth-order holds. In this example, we will compute the true continuous curve. Recall that the plant dynamics are given by the reaction kinetics and initial conditions are dx1 = −2e−6/u x1 , starting from x1 (t = 0) = 0.9 dt dx2 = 2e−6/u x1 − 5e−11/u x2 , starting from x2 (t = 0) = 0.1 dt

(9.21)

and the objective function to be maximised is J = x2 (t = 2) +

Z

t=2

0 dt

0

which indicates that L(x, u, t) = 0. The Hamiltonian function, H = L + λT f , in this instance is     −2e−6/u x1 H = 0 + λ1 λ2 2e−6/u x1 − 5e−11/u x2   = −2λ1 e−6/u x1 + λ2 2e−6/u x1 − 5e−11/u x2 The costates vary with time following λ˙ = −∂H/∂x and finish with

dλ1 = 2e−6/u (λ1 − λ2 ), ending at λ1 (t = 2) = 0 dt dλ2 = 5e−11/u λ2 , ending at λ2 (t = 2) = 1 dt

(9.22)

9.3. THE GENERAL OPTIMAL CONTROL PROBLEM

405

since φ = x2 . Now the optimum temperature trajectory is the one that maximises H or the solution to dH/du = 0, which in this case can solved analytically to give 5

u= ln



55λ2 x2 12x1 (λ2 −λ1 )

(9.23)



Once again constructing the costate dynamics and optimal input is easier with the help of a symbolic manipulator as shown in Listing 9.4 below. Listing 9.4: Analytically computing the co-state dynamics and optimum input trajectory as a function of states and co-states >> syms u lam1 lam2 x1 x2 real

% define symbolic variables def

2

7

12

17

def

>> x = [x1 x2]'; lambda = [lam1 lam2]'; % x = [x1 , x2 ]T , λ = [λ1 , λ2 ]T >> f = [-2*exp(-6/u)*x(1); ... 2*exp(-6/u)*x(1) - 5*exp(-11/u)*x(2)]; >> phi = x(2); L = 0; >> H = L + lambda'*f; % H = L + λT f >> lam_dot = -jacobian(H,x)'; % −∂H/∂x lam_dot = (2*lam1)/exp(6/u) - (2*lam2)/exp(6/u) (5*lam2)/exp(11/u) >> lam_final = jacobian(phi,x)'% λtfinal = ∂φ/∂x lam_final = 0 1 >> uopt = solve(diff(H,u),u) uopt = 5/log(-(55*lam2*x2)/(12*lam1*x1 - 12*lam2*x1))

Once again we can solve the two-point boundary value problem succinctly using bvp4c as demonstrated in Listing 9.5. We need to supply the state and co-state dynamic equations, Eqn. 9.21 and Eqn. 9.22, the four required boundary conditions, the initial x1 (0), x2 (0) and the final λ1 (2), λ2 (2), and the optimum input trajectory as a function of states and co-states. Listing 9.5: Solving the reaction profile boundary value problem using the boundary value problem solver, bvp4c.m. u = @(x) 5/log(55*x(4)*x(2)/12/x(1)/(x(4)-x(3))) % Optimum input trajectory, Eqn. 9.23 2

7

12

% State and co-state dynamics, Eqn. 9.21 & Eqn. 9.22. zdot = @(t,x) ... [-2*exp(-6/u(x))*x(1); 2*exp(-6/u(x))*x(1) - 5*exp(-11/u(x))*x(2); 2*exp(-6/u(x))*(x(3)-x(4)); 5*exp(-11/u(x))*x(4) ]; % Boundary residuals x1 (0) = 0.9, x2 (0) = 0.1 and λ1 (2) = 0, λ2 (2) = 1 BCres = @(a,b) [a(1:2)-[0.9; 0.1]; ... b(3:4)-[0;1]]; tf = 2; % Final time tfinal = 2 solinit = bvpinit(linspace(0,tf,10),[0.6,0.2,0.4 0.6]) sol = bvp4c(zdot,BCres,solinit); % Now solve TPBVP

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

406 17

xint = linspace(0,tf,1e3)'; Sxint = deval(sol,xint); % interpolate solution plot(sol.x, sol.y,'ro',xint,[Sxint(1,:)',Sxint(2,:)'],'-') % See Fig. 9.12

The optimum input temperature policy is shown in Fig. 9.12 with the resultant state and costate trajectories. The amount of desired product B that is formed using this policy is 0.438 and we can be confident that no other temperature policy will improve on that result. 1 Ca Concentration

0.8

Cb

0.6 Cb(final) = 0.438 0.4 0.2

Temperature

0 8 6 4 2

Figure 9.12: The concentrations, the optimum temperature trajectory, and co-states for the batch reactor as evaluated using an optimum control policy.

Co−states, λ

0 1.5 λ1

1

λ2

0.5 0 −0.5

0

0.5

1 time [hours]

1.5

2

In both the Rayleigh and the batch reactor optimal control examples given above we could extract analytical expressions for the optimal control policy as an explicit function of states and co-states, u⋆ (t) = g(x, λ, t) which made the subsequent boundary-value problem easier to solve. However in many practical cases, the solution of Eqn. 9.19 to give u⋆ (t) may not be possible to find in closed form. In these cases, we may need to embed an algebraic equation solver such as fsolve, or an optimiser such as fminunc.m inside the BVP solution routine. However the problem to be solved now is a differential algebraic equation or DAE which introduces considerable computational problems.

9.3.4 Problems with a specified target set In some optimal control problems we wish not only to establish the optimum profile for u(t) starting from a given initial condition, x(0), but we might also require some (or all) of our states to satisfy some arbitrary condition at the final time, ψ (xf , tf ) = 0

(9.24)

9.3. THE GENERAL OPTIMAL CONTROL PROBLEM

407

These problems are known as OCP problems with a target or manifold set. Further details and solution strategies for these sorts of problems are given in [45, 163]. The main difference here is that we need to introduce a new vector of Lagrange multipliers, ν, the same dimension as the number of target state constraints in Eqn. 9.24, and these get added to the modified objective functional. A simplified, but very common situation is where we wish some of our states to hit a specified target, and perhaps leave the remainder of our states free. In this case the boundary conditions simplify to: 1. if xi (tf ) is fixed, then we use that as a boundary constraint, i.e. xi (tf ) = xif , 2. if xi (tf ) is free, then we use λi (tf ) = ∂φ/∂xi (tf ) as usual for the boundary constraint. Note that together, these two conditions supply the additional n boundary conditions we need to solve the two-point boundary value problem of dimension 2n. Suppose we wish to find the optimum profile u(t) over the interval t ∈ [0, 1] to minimise Z 1 J = u2 dt 0

subject to the dynamics

x˙ = x2 sin(x) + u,

x(0) = 0

but where we also require the state x to hit a ‘target’ at the final time x(1) = 0.5 In this case we have one state variable and one associated co-state variable, so we need two boundary conditions. One is the initial state condition, and the other is the specified state target. This means that for this simple problem we do not need to specify any boundary conditions for the costate. The rest of the OCP problem is much the same as that given in Algorithm 9.1. 1

6

11

syms x u lam

real

% define symbolic variables, u(t), x(t), λ(t)

tf = 1; xtarget = 0.5;

% final time % target constraint

f = [xˆ2.*sin(x) + u]; phi = 0; L = uˆ2;

% State dynamics x˙ = f (x, u) % Terms in the objective function, φ, L

H = L + lam'*f

% Hamiltonian, H = L + λf

lam_dot = -jacobian(H,x)'; % ensure column vector uopt = solve(diff(H,u),u)

Running the above code gives the optimum input as u⋆ = −λ/2 and the the two-point boundary problem to solve as     x˙ x2 sin(x) − λ2  = (9.25) −λ x2 cos(x) + 2x sin(x) λ˙ in two variables. The two boundary conditions are x(0) = 0,

and

x(1) = 0.5

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

408

3

8

% Define state & co-state dynamics, Eqn. 9.25. ztmp = @(t,z1,z2) ... [z1ˆ2*sin(z1) - z2/2; -z2*(z1ˆ2*cos(z1) + 2*z1*sin(z1))]; zdot = @(t,z) ztmp(t,z(1),z(2)); x0 = [0]; BCres = @(a,b) [a(1)- x0; ... b(1)- xtarget]; % Boundary residuals: Initial & terminal state conditions xlam_init = @(t) [0.5*t; -1];

13

18

solinit = bvpinit(linspace(0,tf,10),xlam_init) sol = bvp4c(zdot,BCres,solinit); % Now solve TPBVP % t x u

Extract solution = sol.x; z = sol.y'; % could also check derivatives = z(:,1); lam = z(:,2); = -lam(:,1)/2;

Fig. 9.13 shows the result of this optimal control problem. We should note that the state, x, did indeed manage to hit the specified target at t = 1. Finally we can establish the optimum profile for u(t).

x

States

0.6 0.4 0.2 0

0.5

u

0.45 0.4 0.35

co−states

−0.6

Figure 9.13: Optimal control with a target where x(1) must equal 0.5.

λ −0.8

−1

0

0.2

0.4

0.6 time

0.8

1

Problem 9.1 (These problems were taken in part from [51, p76].) 1. Show that to determine the optimal input trajectory u(t) given the one dimensional system, x˙ = x + u,

x(0) = 1

9.4. LINEAR QUADRATIC CONTROL

409

such that J (u) =

1 2

Z

0

1

 x2 + u2 dt

is minimised reduces to solving the two point boundary value problem,       x˙ 1 −1 x x(0) = 1 = , −1 −1 λ λ(1) = 0 λ˙ Can you find an analytical solution for this problem? 2. Construct the two point boundary problem as above, (but do not solve it) for the two state, one input system       0 1 0 1 x˙ = x+ u, x(0) = 0 0 1 0 R  1 with the cost functional J (u) = 21 0 x⊤ x + u2 dt

9.4 Linear quadratic control The general optimal controller from section 9.3 has some nice properties, not the least that the trajectory is optimal. However there are some obvious disadvantages, some of which are substantial. Quite apart from the sheer complexity of the problem formulation and the subsequent numerical solution of the two-point boundary value problem, there is the fact that the final result is a manipulated variable trajectory which is essentially an open loop controller. This is fine provided we always start from the same conditions, and follow down the prescribed path, but what happens if due to some unexpected disturbance we fall off this prescribed path? Do we still follow the pre-computed trajectory for u(t), or must we re-compute a new optimal profile for u(t)? Ideally we would like our optimal controller to have some element of feedback, which after all is a characteristic of all our other practical controllers. Furthermore if we restrict our attention to just linear plant models, and use just a quadratic performance objective, then the subsequent problem setup, and implementation, is made considerably easier. These types of optimal controllers designed to control linear plants with quadratic performance are known as Linear Quadratic Regulators, or LQR.

9.4.1 Continuous linear quadratic regulators The linear quadratic control problem is to choose a manipulated variable trajectory u(t), that minimises a combination of termination error and the integral of the squared state and manipulated variable error over a time horizon from t = 0 to some specified (although possibly infinite) final time t = T , Z  1 1 T T J = x(T )Sx(T ) + x Qx + uT Ru dt (9.26) 2 2 0 given the constraint of linear plant dynamics

x˙ = Ax + Bu,

x(t = 0) = x0

(9.27)

As we assume linear plant dynamics, and the performance objective, Eqn. 9.26, is of a quadratic form, this type of controller is known as a continuous Linear Quadratic Regulator or LQR.

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

410

The weighting matrices Q and S are positive semi-definite (and typically diagonal) matrices, while R must be a strictly positive definite matrix. Note that any real positive diagonal matrix is also positive definite. The expressions xT Qx and uT Ru are called quadratic forms and are 2 2 sometimes compactly written as ||x||Q or ||u||R . Following the terminology introduced in the general optimisation criteria in Eqn. 9.8 we have x˙ = Ax + Bu, x(t = 0) = x0 1 ⊤ 1 ⊤ L(x, u, t) = x Q x + u R u 2 2 1 ⊤ φ = x (T ) S x(T ) 2

(9.28) (9.29) (9.30)

for the state dynamics constraint, the ‘getting there’ cost or energy term, and the final cost term. For many applications, there is no explicit termination cost, since all the cost of state deviations is accounted for in the energy term, thus often simply the matrix S = 0. In addition, the upper limit of the time horizon is often set to T = ∞, in which case we are obviously now no longer concerned with the termination cost term. Now applying the Euler-Lagrange equations (Eqns 9.13 and 9.14) gives1   ⊤ 1 ⊤ x Qx + λ Ax ∂ 2 ∂H dλ =− = dt ∂x ∂x ⊤ = −Qx − A λ

(9.33) (9.34)

Similarly using Eqn. 9.14 gives ∂H = 0 = Ru + B⊤ λ ∂u which implies that the optimal control law is

(9.35)

u = −R−1 B⊤ λ

(9.36)

Eqn. 9.36 defines the optimal u as a function of the co-states, λ. Note that now our problem has 2n unknown “states”, the original n x states and the n introduced co-states, λ. We can write this in a compact form using Eqns 9.36, 9.28 and 9.34 

x˙ λ˙



=

"

A −Q

−BR−1 B⊤ −A⊤

#

x λ



(9.37)

with mixed boundary conditions x(0) = x0 ,

and λ(T ) = Sx

From Lyapunov’s theorem, we know that the costates are related to the states via λ(t) = P(t)x(t)

(9.38)

1 Note that Ogata, [148, Appendix A] has a very good summary of matrix operations including differentiation. Especially note the following:

∂Ax = A⊤ ∂x ∂x⊤ Ax = 2Ax ∂x

(9.31) if A is symmetrical

(9.32)

9.4. LINEAR QUADRATIC CONTROL

411

where P(t) is a time varying matrix. Differentiating Eqn. 9.38 using the product rule gives ˙ + Px˙ λ˙ = Px

(9.39)

Now we can substitute the control law based on the costates (Eqn 9.36) into the original linear dynamic model (Eqn 9.28) and further substitute the relation for the states from the costates (Eqn. 9.38) giving x˙ = Ax + Bu   = Ax + B −R−1 B⊤ λ = Ax − BR

−1



B Px

(9.40) (9.41) (9.42)

Now substituting Eqn. 9.42 into Eqn. 9.39 and equating with the Euler-Lagrange equation Eqn. 9.34 gives   ˙ + P Ax − BR−1 B⊤ Px λ˙ = −Qx − A⊤ λ = Px (9.43) Rearranging, and cancelling x gives

˙ = −PA − A⊤ P + PBR−1 B⊤ P − Q P

(9.44)

which is called the differential matrix Riccati equation. It is a matrix differential equation where the boundary requirement or termination value, from Eqn. 9.13 is P(t = T ) = S

(9.45)

and which can be solved backwards in time using the original dynamic model matrices A, B, and the controller design matrices Q, R. While we need to know the model and design matrices for this solution, we need not know the initial condition for the states. This is fortunate, since it means that we can solve the matrix Riccati equation offline once, store the series of P(t), and apply this solution to our problem irrespective of initial condition. We only need to repeat this computation if the plant model or design criteria change. In summary, we now have developed an optimal state feedback controller of the proportional form u = −K(t)x (9.46) where the time varying matrix feedback gain is (from Eqn 9.36) defined as K(t) = R−1 B⊤ P(t)

(9.47)

where the time-varying P matrix is given by Eqn. 9.44 ending with Eqn. 9.45. Since we have assumed that the setpoint is at the origin in Eqn. 9.46, we have a regulatory problem, rather than a servo or tracking problem. Servo controllers are discussed in §9.4.6.

9.4.2 Analytical solution to the LQR problem The problem with implementing the full time-varying optimal controller is that we must solve the nonlinear differential matrix Riccati equation, Eqn. 9.44. This is a complicated computational task and furthermore we must store offline the resultant gain matrices at various times throughout the interval of interest. However there is an analytical solution to this problem which is described in [61, §2.4] and [163, §5.2]. The downside is that it requires us to compute matrix exponentials, and if we want to know P(t) as opposed to just the costates, we must do this computation every sample time.

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

412

We start by solving for both states and costates in Eqn. 9.37, repeated here      x˙ A −BR−1 B⊤ x(0) = known x = , λ(T ) = known λ λ˙ −Q −A⊤ | {z } H

(9.48)

where the matrix H is known as the Hamiltonian matrix. This approach has the attraction that it is a linear, homogeneous differential equation with an analytical solution. Starting from any known point at t = 0, the states and co-states at any future time are given by     x(0) x(t) (9.49) = eHt λ(0) λ(t) However the outstanding problem is that we do not know λ(0) so we cannot get started! def

If we define eHt = Φ(t), then we can re-write Eqn. 9.49 as     x(t) x(0) = Φ(t) λ(t) λ(0)

(9.50)

and remember that with M ATLAB it is straight forward to compute Φ using matrix exponentials since it is a function of known, constant matrices. We then partition the matrix Φ into four equal sized n × n blocks as   Φ11 (t) Φ12 (t) Φ(t) = Φ21 (t) Φ22 (t)

which means we can express Eqn. 9.50 as

x(t) = Φ11 (t)x(0) + Φ12 (t)λ(0)

(9.51)

λ(t) = Φ21 (t)x(0) + Φ22 (t)λ(0)

(9.52)

Employing the Riccati transformation, λ(t) = P(t)x(t), changes Eqn. 9.52 to P(t)x(t) = Φ21 (t)x(0) + Φ22 (t)λ(0) and multiplying Eqn. 9.51 by P(t) and equating to the above gives P(t)Φ11 (t)x(0) + P(t)Φ12 (t)λ(0) = Φ21 (t)x(0) + Φ22 (t)λ(0) Solving for the mystery λ(0) gives λ(0) = [Φ22 (t) − P(t)Φ12 (t)]

−1

[P(t)Φ11 (t) − Φ21 (t)] x(0)

Now at the final point, t = T , we know that P(T ) = S from the transversality conditions, so λ(0) is given by λ(0) = [Φ22 (T ) − SΦ12 (T )]−1 [SΦ11 (T ) − Φ21 (T )] x(0) (9.53)

which is something that we can compute since all the terms are known.

Now having established λ(0), we can use Eqn. 9.49 to compute analytically both states, x(t), and costates, λ(t), at any time t. Consequently, we can compute P(t) at any intermediate time between 0 and T using P(t) = [Φ22 (T − t) − SΦ12 (T − t)]−1 [SΦ11 (T − t) − Φ21 (T − t)]

(9.54)

In many applications, it suffices to ignore the costates and just consider P(0) which is given directly by −1 P(0) = [Φ22 (T ) − SΦ12 (T )] [SΦ11 (T ) − Φ21 (T )] (9.55)

We will investigate further this important simplification in section 9.4.3.

9.4. LINEAR QUADRATIC CONTROL

413

An LQR time-varying example Suppose we wish to control the continuous plant     −2 −4 4 x˙ = x+ u, 3 −1 6

x(0) =



−2 1



using an optimal controller of the form u = −K(t)x to drive the process from some specified initial condition to zero. For this application, we decide that the manipulated variable deviations are more costly than the state deviations,     1 0 0 0 Q= , R = 2, S= 0 1 0 0 Listing 9.6 first defines the plant, then solves for the initial costates, λ(0), using Eqn. 9.53, and then finally simulates the augmented state and costate system given by Eqn. 9.48. Listing 9.6: Computes the full time-evolving LQR solution 1

6

A = [-2 -4; 3 -1]; B=[4,6]'; x0 = [-2,1]'; % Plant: x˙ = Ax+Bu & initial state, x(t = 0) n=length(A); % Problem dimension Q = eye(2); R=2; S=zeros(size(A)); % Design criteria: Q, R and S T = 0.5; % final time, T H = [A, -B/R*B'; -Q, -A']; Phi = expm(H*T);

11

% Create Hamiltonian using Eqn. 9.48 def % Φ(t) = eHt

Phi11 = Phi(1:n,1:n); Phi12 = Phi(1:n,n+1:end); % Construct Φ11 (t), Φ12 (t), . . . Phi21 = Phi(n+1:end,1:n); Phi22 = Phi(n+1:end,n+1:end); Lam_0 = (Phi22 - S*Phi12)\(S*Phi11 - Phi21)*x0; % costate initial condition, Eqn. 9.53 z0 = [x0;Lam_0]; % augment states & costates G = ss(H,zeros(2*n,1),eye(2*n),0); initial(G,z0,T) % simulate it

The results of this simulation are given in Fig. 9.14 which also compares the near identical results from a slightly sub-optimal controller which uses simply the steady state solution to the Riccati equation discussed next in section 9.4.3. Note that the performance drop when using the considerably simpler steady-state controller is small, and is only noticeable when the total time horizon is relatively short. An alternative solution procedure to the analytical solution given in Listing 9.6 is to numerically integrate the continuous time Riccati equation, Eqn. 9.44, backwards using say the workhorse ode45 with ‘initial’ condition Eqn. 9.45. The trick that the function in Listing 9.7 does is to collapse the matrix Eqn. 9.44 to a vector form that the ODE function can then integrate. The negative sign on the penultimate line is because we are in fact integrating backwards. Listing 9.7: The continuous time differential Riccati equation. This routine is called from Listing 9.8. function dPdt = mRiccati(t, P, A, B, Q) % Solve the continuous matrix differential Riccati equation % Solves dP/dt = −AT P − PA + PBBT P − Q 5

P = reshape(P, size(A)); % Convert from (n2 × 1) vector to n × n matrix

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

414 Time−evolving & steady−state: T

=2

Time−evolving & steady−state: T

0

0

−2

−4

0.5

0.5 0

u

u

0 u(t) u∞

1

0.5

0.5

K

1

0

0

0.5

0.5

0

0 −0.5

0.5

0.5

0

0

λ

−0.5

−0.5

0

0.5

1 time [s]

1.5

(a) A long time horizon, T = 2.

2

u(t) u∞

−0.5

P

K P λ

−2

−4

−0.5

=0.5

final

2 states

states

final

2

−0.5

0

0.1

0.2 0.3 time [s]

0.4

0.5

(b) A shorter time horizon, T = 0.5.

Figure 9.14: Comparing the full time-varying LQR control with a steady-state sub-optimal controller. The upper two plots trend the two states and one input for the steady-state case and for the time varying case. The lower three plots trend the time-varying elements of the matrices K(t), P(t), and the co-state vector λ(t) for the full time-varying optimal case. dPdt = -A.'*P - P*A + P*B*B.'*P - Q; % Eqn. 9.44 dPdt = -dPdt(:); % Convert back from n × n to (n2 × 1) return

We call the function containing the matrix differential equation in Listing 9.7 via the ode45 integrator as shown in Listing 9.8. Note that we can express BR−1 B efficiently as ZZT where Z = B(chol(R)−1 ). Listing 9.8: Solves the continuous time differential Riccati equation using a numerical ODE integrator. 2

A = [-2 -4; 3 -1]; B=[4,6]'; % Plant dynamics of interest Q = eye(2); R=2; S=zeros(size(A)); % Weighting matrices, Q, R T = 1; % Final time for the finite time horizon P0 = S; % “Initial” condition for P

9.4. LINEAR QUADRATIC CONTROL

7

415

[t,P] = ode45(@(t,P) mRiccati(t,P,A,B/(chol(R)),Q),[0 T],P0(:)); % Call listing 9.7 P = flipud(P); % reverse time order of P(t)

Now we have generated a trajectory for the four elements of the P(t) matrix as a function of time. We could then pre-compute the time varying gains, K(t), and then store them ready to be used in our closed loop simulation. Compared to the analytical solution, this numerical integration scheme requires that we integrate n2 equations as opposed to 2n when we combine the co-states. Furthermore we must store the trajectory of pre-computed time-varying gains. In practice of course, this is storage requirement rapidly becomes unwieldy and, as we shall see in the next section, rarely worth the effort.

9.4.3 The steady-state solution to the matrix Riccati equation In the optimal controller scheme presented above, the gain K(t), is a continuously time varying matrix, as opposed to a more convenient constant matrix. A time varying controller gain requires excessive computer resources even if we did discretise, since we need to store an (m × n) gain matrix at every sample time in the control computer over the horizon of interest. We can make an approximation to our already approximate optimal controller by using only the steady-state gain derived from the steady-state solution of the matrix differential Riccati equation ˙ = 0. With this approximation, the differential Eqn. 9.44 is simplified to the algebraic when P equation, 0 = A⊤ P∞ + P∞ A − P∞ BR−1 B⊤ P∞ + Q (9.56) where the steady-state solution, P∞ , is now a constant gain matrix which is considerably more convenient to implement. The steady-state controller gain is still obtained from Eqn. 9.47, K∞ = R−1 B⊤ P∞

(9.57)

and is also a constant gain matrix. Whether the performance deterioration due to this approximation is significant depends on the plant, and on the time horizon of interest. However as evident in Fig. 9.14, the differences in performance are negligible for all but the shortest time horizons. Fig. 9.14(a) shows that even for this relatively brief optimisation horizon, the gains are essentially constant for more than two thirds of the horizon, and this feature is generally true for all plants, and optimisation scenarios provided the horizon is reasonably long. We can solve for the elements of the matrix P∞ in Eqn. 9.56 using one of several strategies. One direct way is to by equating the individual elements in each of the matrices and thus reducing the single matrix equation to a set of algebraic equations. However unlike the Lyapunov equation, Eqn. 2.96, which we could collapse to a system of linear equations using vectorisation and Kronecker products as described in section 2.9.5, this time the steady-state Riccati equation includes a quadratic term of the form P∞ BP∞ which means our resultant system of equations will not be linear. However an iterative scheme based on this idea is given on page 417. Another strategy is to compute the analytical expression for P(T ), Eqn. 9.55, with a large time horizon T . Unfortunately Eqn. 9.55 is numerically very ill-conditioned when T is large, let alone ∞, and it is difficult to know a priori exactly what time horizon is sufficiently ‘large’. A final strategy given later in Listing 9.12 is only applicable for the discrete version of the optimal controller. The control toolbox in M ATLAB provides a reliable algebraic Riccati equation routine, care, that

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

416

solves Eqn. 9.56 for P∞ in a numerically reliable manner2 , and the ric routine verifies the computed P from care (or equivalent) by calculating the residual of Eqn. 9.56. The linear quadratic regulator lqr routine finds the controller gain directly which is slightly more convenient than the two-step procedure solving the algebraic Riccati equation explicitly. All three routines are demonstrated in Listing 9.9.

A steady-state continuous LQR example Simulating a steady-state optimal state-feedback controller is trivial in M ATLAB. We can try a steady-state version of the optimal controller for the example given previously on page 413. A script to solve the controller design problem using the toolbox functions are, care or lqr, and to simulate the results in M ATLAB is given in Listings 9.9 and 9.10. Listing 9.9: Calculate the continuous optimal steady-state controller gain. >>A = [-2, -4; 3 -1]; B = [4; 6]; % Plant under consideration >>Q = eye(2); R = 2; % Controller weighting matrices, Q, R. 3

8

13

18

>>P = are(A, B/R*B', Q) % Solve for X such that AT X + XA − XBX + Q = 0 P = 0.1627 -0.0469 -0.0469 0.2514 >>K = R\B'*P % Now compute gain from Eqn. 9.57, K∞ = R−1 B⊤ P∞ . K = 0.1847 0.6603 >>[Kerr,Perr] = ric(A,B,Q,R,K,P) Kerr = 0 0 Perr = 1.0e-014 * 0.0999 0.2720 0.1471 0.1887

% Check results

% Residuals should ≈ 0 which they do

>> [P2,L,G]=care(A,B/chol(R),Q);% Solve for X such that AT X + XA − XBBT X + Q = 0 >> K2 = chol(R)\G;

% Compute controller gain given that G = BT X

23

>>[K2,P2,E] = lqr(A,B,Q,R) >> K2 K2 = 0.1847 0.6603

% Gain from lqr should ≈ gain from care.

This completes the controller design problem, the rest is just a simple closed-loop simulation as shown in Listing 9.10. Listing 9.10: Closed loop simulation using an optimal steady-state controller gain. C = eye(size(A)); D = zeros(2,1); Gcl = ss(A-B*K,zeros(size(B)),C,D); % Hopefully stable optimal closed loop 3

T = 1; x0 = [-2,1]'; [Y,t,X]=initial(Gcl,x0,T); 2 An

% final time & initial state, x0

older toolbox routine, are.m, essentially also does this calculation.

9.4. LINEAR QUADRATIC CONTROL

417 % back-calculate input, u(t), for plotting

U = -X*K'; 8

subplot(2,1,1);plot(t,X); ylabel('states'); % Refer Fig. 9.15. subplot(2,1,2);plot(t,U); ylabel('input'); xlabel('time (s)')

The state and input trajectories of this optimal controller given a non-zero initial condition are given in the Fig. 9.15. Continuous steady−state LQR 1

states

0 −1 −2 −3

0

0.2

0.4

0.6

0.8

1

0

0.2

0.4

0.6

0.8

1

0.4

input

0.2 0 −0.2 −0.4

time (s)

Figure 9.15: A steady-state continuous LQR controller.

The difference between the fully optimal time varying case and the simplification when using the steady-state solution to the Riccati equation is given in Fig. 9.14 which uses the same example from page 416. For short optimisation intervals there is a small difference between the steadystate solution and the full evolving optimal solution as shown in Fig. 9.14(b). However as the final time increases, there is no discernible difference in the trajectories of the states nor in the input in Fig. 9.14(a). This goes along way to explain why control engineers hardly ever bother with the full optimal solution. The lower two plots in Fig. 9.14 trend the time varying P(t) and K(t) matrices.

Solving the algebraic Riccati equation using Kronecker products Notwithstanding that the algebraic Riccati equation of Eqn. 9.56 is nonlinear, we can devise an iterative scheme to solve for P∞ in a manner similar to that for the Lyapunov equation using vectorisation and Kronecker products described in section 2.9.5. Collapsing Eqn. 9.56 to vectorised form gives   − I ⊗ AT + AT ⊗ I − I ⊗ P∞ BR−1 BT vec(P∞ ) = vec(Q)

(9.58)

which we now must solve iteratively due to the unknown P∞ in the coefficient matrix in Eqn. 9.58. Listing 9.11 uses this solution strategy which works (most of the time) for modest sized problems, but is not numerically competitive with, nor as reliable as, the ARE scheme in M ATLAB. Listing 9.11: Solving the algebraic Riccati equation for P∞ using Kronecker products and vectorisation given matrices A, B, Q and R. 1

n = size(A,1); I = eye(size(A)); % Identity, I BRB = B/R*B'; % Constant matrix, BR−1 BT D = kron(I,A') + kron(A',I); % vec(AT P + PA) = (I ⊗ AT + AT ⊗ I)vec(P)

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

418

6

11

P = I; % Start with P∞ = I tol = 1e-8; dP = tol*1e2; % Suggested tolerance, ≈ 10−5 while norm(dP) > tol Pnew = reshape(-(D-kron(I,P*BRB))\Q(:),n,n); % Solve Eqn. 9.58 iteratively for P∞ dP = Pnew - P; P = Pnew; end

In a similar manner to solving the Lyapunov equation using fsolve on page 81, we could also construct the algebraic Riccati matrix equation to be solved and submit that to the general nonlinear algebraic equation solver fsolve. This works in so far as it delivers a solution, but the solution may not be a stabilising solution, or in other words while the matrix P∞ does satisfy the original matrix equation, Eqn. 9.56, it may not be symmetric, or lead to a stable closed loop system. This is due to the fact that the matrix Riccati equation has multiple solutions and general purpose numerical schemes such as fsolve will return the first solution it comes across as oppose to the stabilising one that we are interested in. For this reason it is better to use the dedicated Riccati solving routines than the general purpose fsolve.

9.4.4 The discrete LQR In the discrete domain, the optimisation problem analogous to Eqn. 9.26 is to search for the N future optimal control moves, u0 , u1 , · · · , uN −1 to minimise J =

N −1  1 X T 1 xN SxN + xk Qxk + uTk Ruk 2 2

(9.59)

k=0

where the continuous plant dynamics, Eqn 2.37, are now replaced by the discrete equivalent xk+1 = Φxk + ∆uk

(9.60)

and the state feedback control law, Eqn. 9.46, is as before. Now the discrete matrix difference Riccati equation analogous to Eqn. 9.44 is  −1 Pk = Q + Φ⊤ Pk+1 Φ − Φ⊤ Pk+1 ∆ R + ∆⊤ Pk+1 ∆ ∆⊤ Pk+1 Φ (9.61) with final boundary condition

PN = S and the feedback gain K at time t = kT is  −1 Kk = R + ∆⊤ Pk+1 ∆ ∆⊤ Pk+1 Φ

(9.62)

(9.63)

An alternative form to Eqn. 9.63 is

Kk = R−1 ∆T Φ−T (Pk − Q)

(9.64)

which uses the current Pk rather than the future version, but has the disadvantage that Φ must be invertible. Note that the optimal feedback gain K, is now an (m × n) matrix rather than a row vector as in the SIMO pole placement case described in chapter 8. It is possible to compute the value of the performance index J , of Eqn. 9.59 in terms of the initial states and the initial P0 matrix, 1 J = xT0 P0 x0 (9.65) 2 although this precise value of J has probably little practical worth in most industrial control applications.

9.4. LINEAR QUADRATIC CONTROL

419

Using the slightly sub-optimal discrete steady-state gain Clearly the discrete optimal gain given by Eqn. 9.63 is again time varying as it was in Eqn. 9.47 for the continuous case, but this can be computed offline since it is only dependent on the constant plant matrices Φ and ∆, the weighting matrices Q and R, and the time varying Pk . However, once again as in the continuous case given in §9.4.3, we can use the considerably simpler steady-state approximation to Eqn. 9.61 with little reduction in optimality. We solve for the steady state covariance,  −1 P∞ = Q + Φ⊤ P∞ Φ − Φ⊤ P∞ ∆ R + ∆⊤ P∞ ∆ ∆⊤ P∞ Φ

(9.66)

by starting with P∞ = 0 and stepping, (rather than integrating), backwards in time until Pk approximately equals Pk+1 . It follows that the resultant K given by Eqn. 9.63 will now also be constant. This strategy is implemented in the listing 9.12 which is functionally equivalent, but not as reliable to the lqr routine in the control toolbox. Listing 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.

4

9

function [K,P] = dlqr_ss(Phi,Delta,Q,R) % Steady-state discrete LQR by unwinding the Riccati difference eqn, Eqn. 9.61. % Routine not as reliable as dlqr.m P = zeros(size(Phi)); % Start with P = 0 at t = ∞ tol = 1e-5; % default tolerance P0 = P+tol*1e3; while norm(P0-P,'fro') > tol P0=P; P = Q + Phi'*P*Phi - Phi'*P*Delta*((Delta'*P*Delta+R)\Delta')*P*Phi; end % while −1 T K = (Delta'*P*Delta + R)\Delta'*P*Phi; % K∞ = R + ∆T P∞ ∆ ∆ P∞ Φ end % end function dlqr_ss

However, the backward iteration calculation technique given in dlqr_ss in listing 9.12 is both crude and computationally dangerous. For this reason it is advisable to use the functionally equivalent, but more robust dlqr (or lqr) provided in the C ONTROL T OOLBOX. Listing 9.13 compares a continuous LQR regulator for the system given on page 413 with a discrete LQR sampled at a relatively coarse rate of Ts = 0.1s. Note that in both the discrete and continuous cases we design the optimal gain using the same lqr function. M ATLAB can tell which algorithm to use from the model characteristics. Listing 9.13: Comparing the continuous and discrete LQR controllers. 2

A = [-2, -4; 3 -1]; B = [4; 6]; % Continuous plant, x˙ = Ax + Bu C = eye(size(A)); D = zeros(2,1); G = ss(A,B,C,D) Q = eye(2); R = 2; % Controller weighting matrices Q = I2 , R = 2 K = lqr(G,Q,R); % Optimal gain, K = [k1 , k2 ] Gcl = ss(A-B*K,zeros(size(B)),C,D); % Continuous closed loop

7

T = 1; x0 = [-2,1]'; % final time & initial condition [Y,t,X]=initial(Gcl,x0,T); U = -X*K'; % Simulate & back-calculate input

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

420

12

% Discrete version of the LQR controller Ts = 0.1; % Rather coarse sampling time, Ts Gd = c2d(ss(A,B,C,D),Ts); % Discrete plant, xk+1 = Φxk + Buk , Ts = 0.1 Kd = lqr(Gd,Q,R); % Design discrete LQR gain Gcl_d = ss(Gd.A-Gd.b*Kd,zeros(size(B)),C,D,Ts);

17

[Yd,td,Xd]=initial(Gcl_d,x0,T); Ud = -Xd*Kd'; % Simulate & back-calculate input subplot(2,1,1); plot(t,X,td,Xd,'o'); % Refer Fig. 9.16 subplot(2,1,2); plot(t,U,td,Ud);

1

states

0 −1 −2 −3

0

0.2

0.4

0.6

0.8

1

0.8

1

0.4

Figure 9.16: Comparing discrete and continuous LQR controllers. Note that even with a relatively coarse sample time, the controlled response in both cases is practically identical.

input

0.2 continuous input

0 −0.2

discrete input, T =0.1 s

−0.4

0

0.2

0.4

0.6 time (s)

Problem 9.2 1. Load in the Newell & Lee evaporator matrices (refer Appendix E.1) and design an LQR with equal weighting on the Q and R matrices by typing Q = eye(A); R = eye(B); and using the dlmr function with a sample time of 1.0. This feedback matrix should be the same as the gain matrix given in [145, p55]3 . Comment on any differences in solution you obtain.

2. Repeat the LQR design using the supplied dlqr function rather than the dlqr_ss function. Using dlqr however, the gain elements are now slightly different. Is this difference important and how would you justify your answer?

3. Use either dlqr_ss or dlqr to generate feedback gains for the limiting cases when either (or both) Q or R are zero. What difficulties do you encounter, and how do you solve them?

3 Newell & Lee define the control law in a slightly different way; u = Kx omitting the negative sign. This means that the K on p55 should be the negative of that evaluated by M ATLAB.

9.4. LINEAR QUADRATIC CONTROL

421

Computing the performance of a steady-state discrete LQR controller in M ATLAB In the steady-state case, we are uninterested in the termination part of the performance index of Eqn. 9.59 leaving just J = =



 1X T xk Qxk + uTk Ruk 2

(9.67)

k=0

1 T x P∞ x0 2 0

(9.68)

reinforcing the fact that while the controller gain is not dependent on the initial condition, the value of the performance index is. Suppose we had a plant xk+1 =



0 0 −0.5 1



xk +



1 0



uk , starting from x0 =



2 2



with controller design matrices Q = diag[1, 0.5], and R = 1, and we wanted to compute the performance index J comparing the numerical summation given by Eqn. 9.67, and the analytical strategy in Eqn. 9.68.

4

>> Phi = [0 0; -0.5, 1]; Del = [1 0]'; % Plant matrices Φ, ∆ and controller design Q, R >> Q = diag([1 0.5]); r = 1; >> [K,P,E] = dlqr(Phi,Del,Q,r) % Solve the Riccati equation for K∞ & P∞ . K = 0.2207 -0.4414 P = 1.5664 -1.1328 -1.1328 2.7656

Now that we have the steady-state Riccati equation solution we can compute the performance directly , J .

2

>> x0 = [2,2]'; % Initial condition x0 >> J = 0.5*x0'*P*x0 % Performance J = 12 xT0 P∞ x0 J = 4.1328

To obtain an independent assessment of this, we could ‘simulate until exhaustion’ and numerically compute Eqn. 9.67. Since we have simulated the closed loop, we need to ‘back-extract’ the input by using the control law and the states. 1

Gcl = ss(Phi-Del*K,0*Del,eye(2),0, 1); % Form closed loop (Φ − ∆K) [y,t,x] = initial(Gcl,x0); % Let M ATLAB establish a suitable on final time, k∞ u = -x*K'; % Back extract control input from closed loop simulation, u = −Kx

Now M ATLAB has returned a vector of input and states, and we need to compute P T the summation given in Eqn. 9.67. One elegant way to calculate expressions such as x Qx given the states stacked in rows is to use the M ATLAB construction sum(sum(x.*x*Q’)). This has the advantage that it can be expressed succinctly in one line of code and it avoids an explicit loop.

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

422

2

 P T >> uRu = u'*u*r; % k uk Ruk , but only works for scalar r >> J_numerical = 0.5*(sum(sum(x.*x*Q'))+uRu) % Performance J_numerical = 4.1328

1 2

P

k

xTk Qxk + uTk Ruk



In this case the numerical value of J is very close to the analytical value.

Varying the Q and R weighting matrices The Q and R weighting matrices in the objective function Eqn. 9.26 reflect the relative importance of the cost of state deviations with respect to manipulated variable deviations and are essentially the tuning parameters for this control algorithm. If we increase the Q matrix, then the optimum controller tries hard to minimise state deviations and is prepared to demand very energetic control moves to do it. Likewise, if we increase R, the weighting on the deviations from u, then excessive manipulated variables moves are discouraged, so consequently the quality of the state control deteriorates. If we are only really interested in output deviations, yT y, as opposed to state deviations, then Q is often set equal to CT C. This follows simply from the output relation y = Cx. Fig. 9.17 and the listing below demonstrate the design and implementation of a discrete LQR for a stable, interacting arbitrary plant. We will start from a non-zero initial condition and we subject the system to a small external disturbance at sample time k = 20. In this listing, the state deviations are considered more important than manipulated deviations. 1

6

11

16

% Create an simple, stable, interacting, 3*2 plant Phi = [0.8 0.1 0.1; -0.1 0.7 0.2; 0 0.6 0.1]; Del = [1,2; -2,1; 0,-3]; C = [1,0,0]; D=[0,0]; t=[0:40]'; dist = 20; % sample vector & disturbance point Q = eye(size(Phi)); [n,nb] = size(Del); R=eye(nb,nb);

% tuning constants

K = dlqr(Phi,Del,100*Q,R); % Design LQR controller with Q = 100I, R = I Gd = ss(Phi-Del*K,Del,C,D,1); % closed loop system U = zeros(size([t,t]));U(dist,:) = [1,0.2]; % not much + disturbance x0 = [-1,2,0]'; % given initial condition [Y,T,X3] = lsim(Gd,U,t,x0); % do closed loop simulation U3 = X3*K'; % extract control vector from x stairs(t,[X3,U3]); P T P T % Compute performance indices: x Qx, & u Ru perfx3 = sum(sum(X3.*(Q*X3')')), perfu3 = sum(sum(U3.*(R*U3')'))

Fig. 9.17 compares two responses. The left controlled response is when we consider state deviations more important than manipulated variations, i.e. the weighting factor for the states is 100 times that for the manipulated variables. In the right plot, the opposite scenario is simulated. the left controlled response returns a relatively low ISE (integral squared Clearly in Fig. 9.17 P error) on the states, xT Qx = 12.3, but at the cost of a high ISE on the manipulated variables, P T u Ru = 1.57. Conversely the right controlled response shows the situation, where perhaps owing to manipulated variable constraints, we achieve a much lower ISE on the manipulated variables, but at a cost of doubling the state deviation penalty.

423

2

2

1

1 State Q=1

State Q=100

9.4. LINEAR QUADRATIC CONTROL

0 Σx’Qx=12.3

−1

0

−2

−2

1 input R=100

1 input R=1

Σx’Qx=27.4

−1

0.5 0 Σu’Ru=1.571

−0.5

0.5 0 Σu’Ru=0.059

−0.5 −1

−1

0

10

20 Sample number

30

0

40

(a) A discrete LQR where state deviations are considered costly; q = 100, r = 1.

10

20 Sample number

30

40

(b) A discrete LQR where manipulated variable deviations are considered costly; q = 1, r = 100.

Figure 9.17: Varying the state and manipulated weights of a discrete linear quadratic regulator where there is a disturbance introduced at sample time k = 20. When state deviations are costly (q is large compared to r), the states rapidly return to setpoint at the expense of a large manipulated movement. As Fig. 9.17 shows, the design of an optimal LQR requires the control designer to weigh the relative costs of state and manipulated deviations. By changing the ratio of these weights, different controlled responses can be achieved. As we did in §8.2, we can modify the simulation given above to account for non-zero setpoints, x⋆ , by using the control law, u = K(x⋆ − x) rather than Eqn 9.46, so simulating the closed loop xk+1 = (Φ − ∆K)xk + ∆Kx⋆k thus enabling response to setpoint changes.

9.4.5 A numerical validation of the optimality of LQR If the LQR is indeed an optimal controller, its performance must be superior than any arbitrarily designed pole-placement controller such as those tested in section 8.2.1. Listing 9.14 designs an optimal controller for the blackbox plant with equal state and input weights. Listing 9.14: An LQR controller for the blackbox >> G = ss(tf(0.98,conv([2 1],[1,1])),0.1) % Blackbox plant with sample time Ts = 0.1 3

8

>> [n,m] = size(G.b); % system dimensions  1 0 >> Q = eye(n); % state weight, Q = 0 1 >> R = eye(m); % Input weight, R = r = 1 >> K = dlqr(G.a,G.b,Q,R) % Compute optimal controller gain K. K = 4.7373 -3.5942

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

424

Now it would be interesting to compare this supposedly optimal controller with a pole-placement controller with poles arbitrarily placed at say µT = [0.5 ± 0.5i]. Listing 9.15: Comparing an LQR controller from Listing 9.14 with a pole-placement controller 1

6

11

>> pc = [0.5-0.5i; 0.5+0.5i]; % Desired closed loop poles, µ = [0.5 ± 0.5i] >> Kp = acker(G.a,G.b,pc); % Pole-placement controller gain Kp = 13.6971 -5.7713 >> Gcl = G; Gcl.b = 0*G.b; Gcl.c = eye(n); >> Gcl.a = G.a-G.b*K; % Closed loop system with LQR, (Φ − ∆K) >> Gclpp = Gcl; Gclpp.a = G.a-G.b*Kp; % Closed loop system with pole-placement >> x0 = [-1,2]'; % Simulate disturbance rejection >> initial(Gcl,Gclpp,x0) % Refer Fig. 9.18.

The trajectory of the states for the two schemes are given in Fig. 9.18. However what is surprising is that the pole-placement response looks superficially considerably better than the somewhat sluggish, though supposedly optimal, LQR response. How could this be? Surely the optimally designed controller should be better than any ad-hoc designed controller? Comparing LQR & Pole−placement 2 pole−placement

x

1

0 −2 −4

LQR

−6 2

2

0 x

Figure 9.18: Comparing the state trajectories for both pole-placement and LQR. Note that the optimal LQR is considerably more sluggish to return to the setpoint than the poleplacement controller.

−2 dlqr Pole−placement λ =0.5±0.5i

−4 −6

0

0.5

1

1.5

2

2.5

3

What Fig. 9.18 has not shown us is the input trajectory. This is also important when comparing controlled responses, although typically perhaps not quite as important as the state variable trajectories. We need to consider the input trajectory for at least two reasons. Excessive deviations in input will almost certainly reach the input saturation constraints that are present in any real control system. Secondly, excessive movement in the input can cause unreasonable wear in the actuators. Finally in the case where the input magnitude is related to cost, say fuel cost in an engine, then the larger the magnitude, the more expensive the operating cost of the corrective action will be. Fig. 9.19 reproduces the same problem, but this time includes the input trajectory. In this instance, the cost of the pole-placement controller is J = 1288, while for the LQR it is under half at 553. Obviously different pole locations will give different performances, and it is up to us as control designers to choose the most appropriate pole location for the particular control application at hand. Using M ATLAB, it is easy to do an ‘exhaustive search’ over a reasonable domain to find the best pole location.

9.4. LINEAR QUADRATIC CONTROL

425

Performance: LQR = 553, Pole−place = 1288 2 pole−placement

states

0 −2 LQR

−4 −6 10

input

0 −10 dlqr Pole−placement λ =0.5±0.5i

−20 −30

0

0.5

1

1.5

2

2.5

3

Figure 9.19: Comparing poleplacement and LQR, but this time including the input trajectories. Compared to Fig. 9.18, the input trajectory for the optimal LQR controller is considerably less active.

For real systems (that is systems with real coefficients), the desired poles must appear in conjugate pairs. That means that we only need to consider one half of the unit circle. Furthermore, we should only consider the 1st quadrant, because in the 2nd quadrant, the response will be overly oscillatory. Naturally it goes without saying that in the discrete domain we must be inside the unit circle. I have chosen a set of trial poles lying on a polar grid from 0 degrees round to a little past 90◦ , and from a magnitude of about 0.1 to 0.9. These locations are shown in Fig. 9.20. 1

0.5π/T 0.6π/T 0.4π/T

0.8

0.7π/T

0.6

0.8π/T

0.4



0.2 0 −0.2

0.9π/T

0.1 0.3π/T 0.2 0.3 0.4 0.2π/T 0.5 0.6 0.7 0.8 0.1π/T 0.9

π/T π/T 0.9π/T

0.1π/T

−0.4 −0.6 −0.8 −1 −1

0.8π/T

0.2π/T

0.7π/T

−0.5

0.3π/T 0.6π/T 0.4π/T 0.5π/T 0 ℜ

0.5

1

Figure 9.20: We will test a pole-placement controller at each of the pole locations specified by a +. (See also Fig. 9.21 following.)

For each of these pole locations specified in Fig. 9.20, I will: 1. Design a pole placement controller, then 2. simulate the response for a reasonably long time which I assume will approximate infinity, and then P∞ 3. compute the performance criteria, J = i=0 xT Qx + uT Ru.

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

426

As you can see from the resultant contour plot in Fig. 9.21, the performance of our previously arbitrarily chosen pole location of µT = [0.5 ± 0.5i] is reasonable, but not great, and clearly not optimal. From the plot, the best performance is located at a pole location of approximately µ⋆ ≈ [0.75 ± 0.15i]T marked as a × in Fig. 9.21. The question is: can we find this location without doing an exhaustive search, or indeed any type of numerical optimisation search strategy? 11000 0.9 8000 0.8

4100

0.7

10000 9000

3000

81201 100 0

2100

0.4

7000

800

1100 0.1 0.2π/T 0.2 80.3 0.400 0.5 0.6 0.7 0.1π/T 0.8 0.9

6000 5000 4000 3000 2000

0

80

0

3000

0.1

021118000000

0.2

0.3π/T

2100

0.3

0.6π/T 0.5π/T 0.4π/T 603010500

Figure 9.21: Trial pole-placement performance. The performance when µT = [0.5 ± 0.5i] is approximately 1288, while the optimum performance is considerably lower at around 550 at pole location µ⋆ ≈ [0.75 ± 0.15i]T .

00

15

0.5

8000

0

ℑ (λ)

0.6

0 006 15

021118000000 000150 36

43108102001010 10500 5800 000 600 4100 3000

1000 −0.1

0

0.2

0.4 ℜ (λ)

0.6

0.8

When we look at the closed loop poles of the LQR controller, Listing 9.16: Computing the closed loop poles from the optimal LQR controller from Listing 9.14.

4

9

>> [K,S,E] = dlqr(G.a,G.b,Q,R) K = 4.7373 -3.5942 % Controller gain (as before). S = 90.4087 -65.2391 -65.2391 50.4963 E = 0.7800 + 0.1664i % Optimum closed loop poles, µ⋆ . 0.7800 - 0.1664i

then we see that in fact the computed closed loop poles are intriguingly close to the optimum found numerically in Fig. 9.21. It turns out that the LQR routine did indeed find the optimum controller without going to the computational trouble of an exhaustive search. Just remember of course, that this is not a proof of the optimality of the LQR, it is just a numerical validation. Nonetheless, you should find it a convincing argument. Note of course, if we change the dynamic system, or the controller design weights, the of course the shape of the performance surface in Fig. 9.21, and the corresponding optimum will also change. Problem 9.3 1. Simulate the controlled response of the evaporator for about 500 time steps (T = 0.5 time units) with the initial conditions  ⊤ x0 = 1 −4.3 2.2

9.4. LINEAR QUADRATIC CONTROL

427

for the 4 cases: (a) (b) (c) (d)

Q=R=I Q = 103 R = I 103 Q = R = I any other combination of your choice.

In each case, sketch the results of the input u, and the states x with time and calculate the ISE for the states, manipulated variables and the weighted sum. What conclusions can you deduce from the relative importance of Q and R? 2. Compare the performance of the full multivariable LQR controller with that of a controller comprised of just the diagonal elements of the controller gain. What does this say about the process interactions?

9.4.6 An LQR with integral states The LQR developed in §9.4 is only a proportional controller so will suffer from the problem of offset given setpoint changes as graphically demonstrated in the upper plot in Fig. 9.23. To compensate however, the gains in the true multivariable LQR controller can be higher than in multiple SISO controllers without causing instability, reducing, but not eliminating, the offset problem. If the offset problem is still significant, one can introduce extra integral states, z defined as the integral of the normal states Z def

z=

x dt

(9.69)

and can be augmented to the original system as        x˙ A 0 x B = + u z˙ I 0 z 0

(9.70)

and the feedback control law is now u=

Kp

Ki





x z



(9.71)

where Kp are the gains for the proportional controller, and Ki are the gains for the integral controller. Now the LQR is designed for the new system with n additional integral states in the same manner as for the proportional state only case. In M ATLAB we can formulate the new augmented system as Ai = [A zeros(size(A)); eye(size(A)) zeros(size(A))] Bi = [B; zeros(size(B))]

This modification improves the system type, (i.e. the number of poles at the origin), enabling our controller to track inputs. [111, §10–14,p802] gives further details.

SISO servo integral output control If we want to track setpoint changes (servo-control) for a SISO system, we need only to add one extra integral state. The augmented system is x˙ = Ax + Bu z˙ = r − y y = Cx

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

428

where x is the vector of original states, u, y and r are the scalar input, output and setpoint respectively. We simply concatenate the new state to the old, def

¯= x

h

x1

· · · xn

x2

i⊤

.. . z

¯ x is and the feedback gain row-vector in u = −K¯ ¯ = K

h

k1

.. .

· · · kn

k2

So the closed-loop system is  d¯ x ¯ −B ¯K ¯ x ¯+ = A dt



kn+1 

0 1

i

r

where the augmented matrices are:

¯ = A



 A 0 , −C 0 {z } |

¯ = B

(n+1)×(n+1)



 B 0 | {z }

(n+1)×1

To implement, the augmented system must be controllable, which is a tougher requirement than just ctrb(A, B). A block diagram of a pole-placement controller with a single integral state is given in Fig. 9.22, after [111, p802]. The wide lines are vector paths.

r

integral state R xn+1 - + x˙ n+1-−kn+1 − 6

x˙ R -+ -

- + u- B − 6

x

- C

- y

6

A  K  full state feedback

Figure 9.22: State feedback control system with an integral output state We can compare the effect of adding an integral state to remove the offset given x˙ =



4 3 −1 6



x+



2 1



u

where we want to control x1 to follow reference r(t) using pole-placement. In other words, y = [1, 0]x. I will place the closed-loop eigenvalues for the original system at λ=



−6 + 2i −6 − 2i



and with the extra integral state, I will add another pole at λ3 = −10. Fig. 9.23 compares the response of both cases. Clearly the version with the integral state that tracks the setpoint with no steady-state error is preferable.

9.4. LINEAR QUADRATIC CONTROL

429

Proportional control: λ = (−6 ± 2i) 2

0

−2 Integral states: λ = (−6 ± 2i, −10) 2

0

−2

0

5

10 time [s]

15

Figure 9.23: State feedback with an integral state. Upper: response of original system showing offset. Lower: improved response of the augmented system with no offset.

Servo LQR control of the black-box A good example where poor trajectory-following control is advisable.

In experimental, rather than simulated, applications, since we do not measure the states directly, we must use a plant model to produce state estimates based on the measured outputs. In the experimental optimal regulator example shown in Fig. 9.24, we estimated online a simple 3 state model using recursive least-squares after which we recomputed each sample time the optimal steady-state gains. In this application the sample time was relatively long, T = 1.5 seconds, and the RLS forgetting factor was λ = 0.995. No feedback control was used for the first 20 sample times. Problem 9.4 1. Design an integral state LQR for the Newell & Lee evaporator. Newell and Lee suggest that the weightings on the integral states should be an order of magnitude less than the weightings on the states themselves, hence the augmented Qi matrix is   Qi = diag 1 1 1 0.1 0.1 0.1 and the manipulated weighting matrix R, is as before.

2. Compare the feedback matrix from part 1 with that given in [145, p57]. Why are they different? What are the eigenvalues of the closed loop response?

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

430

LQR of the blackbox ∆ t=1.50

output & setpoint

0.6 0.4 0.2 0 −0.2

0

50

100

150

200

250

150

200

250

150

200

250

150

200

250

dlqr servo: σ2= 1, σ2= 10 q r

Input

0.5

0

−0.5

0

50

100 RLS: λ=0.995

5

θ

0

−5

0

50

100

0

50

100

3

K1 and K2

2 1 0 −1

time (s)

Figure 9.24: An experimental application of LQR servo control of the black box with 10q = r. Plots: (a) output and setpoint; (b) input; (c) model parameters θ; (d) controller gains.

9.5. ESTIMATION OF STATE VARIABLES

431

Disturbances & noise

-

? Plant

actual noisy outputs

- Meas

? + − 6

inputs - Model

- g(x)

-

Estimator

corrected states -

predicted outputs predicted states



inputs

state control



state feedback

Software

Figure 9.25: A state-based estimation and control scheme

9.5 Estimation of state variables Chapter 6 looked at various alternatives to identify the parameters of dynamic systems, given possibly noisy input/output measured data. This section looks at ways to estimate not the parameters, (they are assumed known by now), but the states themselves, x, by only measuring the inputs u, and the outputs y. This is a very powerful technique since if this estimation works, we can use state feedback control schemes without actually going to the trouble of measuring the states, but instead using only their estimates. ˆ , which can be compared to the These estimators work by using a model to predict the output, y measured output, y. Based on this difference we can adjust, if necessary, the predicted states. The estimation of states in this way is known, for historical reasons, as a Kalman filter. A block scheme of how the estimator works is given in Fig. 9.25. Here we have a control scheme that while demanding state-feedback, actually uses only state estimates rather than the actual hardto-obtain states. There are many texts describing the development (eg: [50, 96]) and applications (eg: [37, 189]) of the Kalman filter.

9.5.1 Random processes The only reason that our estimation scheme will not work perfectly, at least in theory, is due to the corrupting noise, and to a lesser degree, incorrect initial conditions. Now in practice, noise

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

432

is the garbage we get superimposed when we sample a real process, but when we run pure simulations, we can approximate the noise using some sort of random number generator such as described previously in §6.2. These are correctly termed pseudo random number generators, and most of them are of the very simple linear congruent type, and are therefore deterministic and not strictly random. Whole books have been written on this subject and many of them quote John von Neumann saying in 1951 “Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin.” M ATLAB can generate two types of random numbers; namely uniform or rectangular, and normal or Gaussian. Using the uniform scheme, we can generate any other arbitrary distribution we may desire including Gaussian. However in most practical cases, it is the Gaussian distributed random number we are more interested in. To visualise the difference, try: 1

x = rand(1000,1); hist(x) % [default] uniformly y = randn(1000,1); hist(y) % normally distributed

Sometimes it is interesting to compare the actual probability density function or PDF obtained using the hist command with the theoretical PDF. To directly compare these, we need to scale the output of the histogram such that the integral of the PDF is 1. Fig. 9.26 compares the actual (scaled) histogram from 104 samples of a random variable, N (µ = 12, σ = 2) with the theoretical probability density function. The PDF of a normal variate is, [190, p60],  2 ! 1 x−µ 1 exp − f (x) = √ (9.72) 2 σ 2πσ 2 0.25

0.2

frequency

mean = 12.0116 0.15 σ2 = 4.03369 0.1

0.05

0

2

4

6

8

10

12

14

16

18

20

x

Figure 9.26: The probability density function of a normally distributed random variable x ∈ N (µ = 12, σ = 2); theoretical (solid) and experimental (histogram).

Listing 9.17: Comparing the actual normally distributed random numbers with the theoretical probability density function.

3

xsig = 2; xmean = 12; % Variance, σ, & mean, x ¯ x = xsig*randn(10000,1)+xmean; % sample (realisation) of r.v. x. xv = linspace(min(x),max(x),100)'; % approx range of x pdf= @(xv) 1/sqrt(2*pi)/xsig*exp(-0.5*(((xv-xmean)/xsig).ˆ2));% expected PDF, Eqn. 9.72. area = trapz(xv,pdf(xv)); % Note integral of PDF should=1.0 [numx,xn] = hist(x,30); % Generate histogram [incidence #, x-value]

9.5. ESTIMATION OF STATE VARIABLES 8

433

dx = mean(diff(xn)); % assume evenly spaced scale = 1/dx/sum(numx); % scale factor so total area = 1 freq = numx*scale; % normalise so total area =1 bar(xn,freq); hold on; plot(xv,pdf(xv));hold off % See Fig. 9.26

Multivariable random numbers For a single time series xk of n elements, the variance is calculated from the familiar formula n

Var(x) = σx2 =

1X 2 (xi − x) n i=1

(9.73)

where x is the mean of the vector of data. In the case of two time series of data (xk , yk ) the variances of x and y are calculated in the normal fashion using Eqn. 9.73, but the cross-variance or co-variance between x and y is calculated by n

Cov(x, y) =

1X (xi − x) (yi − y) n i=1

(9.74)

Note that while the variance must be positive or zero, the co-variance can be both positive and negative and that Cov(x, y) = Cov(y, x). For this two vector system, we could assemble all the variances and cross-variances in a matrix P known as the variance-covariance matrix   σx2 Cov(x, y) P= Cov(y, x) σy2 which is of course symmetric with positive diagonals for time series of real numbers. In normal usage, this name of this matrix is shortened to just the ‘covariance’ matrix. For an n variable system, the co-variance matrix P will be a positive definite symmetric n × n matrix. M ATLAB can calculate the standard deviation (σ) of a vector with the std command and it can calculate the co-variance matrix of a multiple series using the cov command. One characteristic about two independent random time series of data is that they should have no cross-correlation, or in other words, the co-variance between x and y, should be approximately zero. For this reason, most people assume that the co-variance matrices are simply positive diagonal matrices, and that the off-diagonal or cross-covariance terms are all zero. Suppose we create three random time series vectors in M ATLAB (x, y, z).

4

x=randn(1000,1) +3; y=randn(1000,1)*6+1; z=randn(1000,1)*2-2; a=[x y z]; cov(a)

% generate 3 independent vectors % standard deviation, σ = 6 % variance σ 2 = 22 = 4 % find co-variance

The co-variance matrix of the three time series is in my case, (yours will be slightly different),     1 0 0 1.02 −0.11 0.10 Cov(x, y, z) =  −0.11 37.74 0.30  ≈  0 36 0  0.10 0.30 4.22 0 0 4

which shows the dominant diagonal terms which are approximately the true variances (1, 36, 4) and the small, almost zero, off-diagonal terms.

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

434

Covariance matrices and ellipses In many cases, the random data does exhibit cross-correlation and we will see this clearly if the x, y data pairs fall in a patten described by a rotated ellipse. We can compute the 95% percent confidence limits of this ellipse using T

(x − µ) P−1 (x − µ) ≤

p(n − 1) Fα,p,(n−p) n−p

where p is the number of parameters (usually 2), and n is the number of data points (usually > 100). Fα,p,(n−p) is the F -distribution at a confidence of α, in this case 95%. To compute values from the F -distribution we could either use the functions given in Listing 9.18, Listing 9.18: Probability and inverse probability distributions for the F -distribution. pf = @(x,v1,v2) betainc(v1*x/(v1*x+v2),v1/2,v2/2); qF = @(P,v1,v2) fsolve(@(x) pf(x,v1,v2)-P,max(v1-1,1))

or use equivalent routines from S TIX B OX toolbox from Holtsberg mentioned on page 3. The easiest way to construct this ellipse is to first plot a circle parametrically, scale the x and y axes, rotate these axes, then finally translate the ellipse so that the center is at the mean of the data. The axes of the ellipse are given by the eigenvectors of P, and the lengths are given by the square root of the eigenvalues of P. Example of confidence limit plotting Here we will generate 1000 random (x, y) samples with deliberate correlation and we will compute the ellipse at a 95% confidence limit. Furthermore we can check this limit by using the inpolygon routine to calculate the actual proportion of data points that lie inside the ellipse. We expect around 95%. 1. First we generate some correlated random data, x ∈ N (−0.3, 1) and y ∈ N (2, 1.1) + x These data pairs are correlated because y is explicitly related to x. Listing 9.19: Generate some correlated random data.

3

N = 1e3; % # of samples in Monte-Carlo x = randn(N,1)-0.3;% N (−0.3, 1) y = 1.1*randn(N,1)+x + 2; % Deliberately introduce some cross-covariance plot(x,y,'.') % See Fig. 9.27(a).

9.5. ESTIMATION OF STATE VARIABLES

435

We can plot the (x, y) points and we can see a that the ‘buckshot’ pattern falls in a rotated ellipse indicating correlation as expected as shown in Fig. 9.27(a). 2. The distribution of the data in Fig. 9.27(a) is more clearly shown in a density plot or a 3D histogram. Unfortunately M ATLAB does not have a 3D histogram routine, but we can use the normal 2D histogram in slices along the y-axis as demonstrated in the following code snippet. Listing 9.20: Plot a 3D histogram of the random data from Listing 9.19. 1

6

Nb = 30; % # of bins in a quick & dirty 3D histogram xmin = min(x); ymin = min(y); xmax = max(x); ymax = max(y); xv = linspace(xmin,xmax,Nb); yv = linspace(ymin,ymax,Nb); [X,Y] = meshgrid(xv,yv); Z= 0*X; for i=1:length(xv)-1 idx = find(x>xv(i)&x 0 (positive semi-definite) and R > 0. The optimum gain Kis given by the simultaneous solution to the following design equations: 0 = ATc P + PAc + CT KT RKC + Q 0 = Ac S + SATc + X −1  K = R−1 BT PSCT CSCT

(9.130) (9.131) (9.132)

where the closed loop Ac and the covariance of the initial state are defined as  def Ac = A − BKC, X = E x(0)xT (0) and the performance index is given by

J = trace (PX)

(9.133)

The coupled nature of the multiple Lyapunov equations mean that we will need to use a numerical technique to solve for the K that satisfies all three design equations. Our alternatives are:

9.6. SUMMARY

459

1. To use a general-purpose unconstrained optimiser to search for the values of K that minimise Eqn. 9.133 directly where P is given by the solution to Eqn. 9.130. 2. To use an unconstrained optimiser and exploit the gradient information since the gradient of J with respect to K is   ∂J = 2 RKCSCT − BT PSCT ∂K

where we have computed the auxiliary matrices P, S by solving the two Lyapunov equations Eqns 9.130–9.131 perhaps using the M ATLAB function lyap. 3. To follow a simple fixed-position algorithm where we guess a value for K and then iterate around Eqns 9.130 to 9.132. Numerical experiments show that the direct optimisation is prone to infinite looping, and the fixed-point algorithm can converge to local optima.

9.6 Summary This chapter dealt with optimal control using classical methods. Optimal control is where we try to control a process in some “best” manner. The term best in the engineering field usually means most economic (either most profit, or least cost). While it is naive to expect our controller to perform optimally in the field, in practice they have been found to out-perform more conventional controllers designed via methods such as loop shaping or frequency response for example. I think of optimal controllers as simply another set of design rules to construct a workable, satisfactory controller, but would not expect them to be the “best” in any strict and absolute sense. A convenient objective function is the quadratic objective function that tries to minimise the weighted sum of state and manipulated deviations squared over time. The optimal controller design problem given nonlinear process dynamics and constraints is, in general, too hard to solve online, although offline open-loop optimal profiles are possible using numerical techniques. The optimisation problem given linear dynamics is tractable and the solution is termed the linear multivariable regulator (LMR or LQG). The LMR in its simple guise is a multivariable proportional controller. The fact that estimation is closely related to regulation was shown in chapter 8 and the optimal estimator is the Kalman filter.

460

CHAPTER 9. CLASSICAL OPTIMAL CONTROL

Chapter 10

Predictive control To be computationally practical, the optimal controllers of chapter 9 required that the system satisfy certain mathematical restrictions. To use variational calculus, the dynamic models must be differentiable; to use LQG, we require linear models with no saturation constraints. In contrast the controllers described in this chapter take into account constraints in the manipulated and control variables, something which is crucial for practical control applications.

10.1 Model predictive control Model predictive control, or MPC, first started appearing in a variety of flavours in the late 1970s and has since then emerged as one of the most popular and potentially valuable control methodologies, particularly popular in the chemical processing industries. A good comprehensive survey of theoretical and practical applications is given in [52, 72, 162, 166]. The central theme of all these variants of predictive control is a controller that uses a process model to predict responses in a moving or receding horizon. Unlike the optimal control of section 9.3.1 or the linear cases following, this control strategy uses a finite optimisation horizon, (refer Fig. 10.1). At every sample time, the optimiser built into the controller selects the best finite number of future control moves over a horizon of 10 or so samples, of which the controller will subsequently implement just the first. At the next sample time, the whole optimisation procedure would be repeated over the new horizon, which has now been pushed back one step. This is also known as receding horizon control. Since an optimisation problem is to be solved each sampling time step, one hopes that the calculations are not too involved! This long-term predictive strategy coupled with the seeking of multiple optimal future control moves turns out to be rather a flexible control scheme where constraints in manipulated and state variables can be easily incorporated, and some degree of tuning achieved by lengthening or shortening the horizon. By predicting over the dead time and two or three time constants into the future, and by allowing the controller to approach the setpoint in a relaxed manner, this scheme avoids some of the pitfalls associated with the traditionally troublesome processes such as those with inverse response or with excessive dead-time. However relying predictions from models are not without their problems. I pity the Reserve Bank of New Zealand which has the unenviable task of predicting the future time-varying interest rates at quarterly intervals as shown in Fig. 10.2. The dark solid line shows the actual 90-day interest rates from March 1999 until March 2003 compared to the predictions made at the originating 461

CHAPTER 10. PREDICTIVE CONTROL

462

Past 

6

- Future Known future setpoint

Predicted (sampled) outputs

Past values

∆t  -

- time

Prediction horizon 6

Current manipulated input . .. Planned future manipulated inputs .. ............... ............... .. . ........................................ .. . ............ .............. Control horizon

- time

Current time

Figure 10.1: Horizons used in model predictive control point. This data was obtained from [192, p18] where is it cautioned: “While we consider our approach generally useful, there are risks. For example, if the interest rate projections are taken as a resolute commitment to a particular course of policy action, then those that interpret it as such will be misled.”

Figure 10.2: Successive future 90-day interest predictions by the Reserve Bank at quarterly intervals. The idea behind MPC is that we have a dynamic, possibly nonlinear, plant described as yˆi+1 = f (yi , ui )

(10.1)

where we wish the plant output y(t) to follow as closely as practical a possibly varying setpoint or reference r(t).

10.1. MODEL PREDICTIVE CONTROL

463

To establish the control move, we find a suitable u(t) solve that minimises the quantity Jt =

subject to some input constraints

Np X i=1

|

2

(rt+i − yˆt+i ) + {z

prediction horizon

}

Nc X

w∆u2t+i−1

(10.2)

i=1

|

{z

control horizon

ui ∈ U

} (10.3)

The set U in the constraint equation, Eqn. 10.3 is the set of allowable values for the input and typically takes into account upper and lower saturation limits in the actuator. For example in the case of a control valve, the allowable set would be from 0 (shut) to 100% (fully open). The optimisation of Eqn. 10.2 involves finding not just the one next control move, but a series of Nc future moves, one for each sample time over the future control horizon. In practice the control horizon is often about 5–15 samples long. The quantity optimised in Eqn. 10.2 is comprised of two parts. The first expression quantifies the expected error between the future model predictions yˆ and the future setpoints, r. Typically the future setpoint is a constant, but if changes in reference are known in advanced, they can be incorporated. The comparison between error and expected output is considered over the prediction horizon, Hp , which must be longer than the control horizon. The second term in Eqn. 10.2 quantifies the change in control moves. By making the weighting factor, w, large, one can discourage the optimal controller from making overly excited manipulated variable demands. At each sample time, a new constrained optimisation problem is solved producing an updated vector of future control. At the next sample instance, the horizons are shifted forward one sample time T , and the optimisation repeated. Since the horizons are continually moving, they are often termed receding horizons. The chief drawback with this scheme is the computational load of the optimisation every sample time. If the model, Eqn. 10.1, is linear, and we have no constraints, then we are able to analytically extract the optimum of Eqn. 10.2 without resorting to a time consuming numerical search. Conversely if we meet active constraints or have a nonlinear plant, then the computation of the optimum solution becomes a crucial step. Further details for nonlinear predictive control are given in the survey of [84]. Algorithm 10.1 Model Predictive Control (MPC) algorithm The basic general predictive control algorithm consists of a design phase and a implementation phase. The design phase is: 1. Identify a (discrete-time) model of the plant to be controlled. 2. Select a suitable sampling time and choose the lengths of the control and prediction horizons, Hc , Hp , where Hc ≤ Hp and the control move weightings, w. Typically Hp is chosen sufficiently long in order to capture the dominant dynamics of the plant step response. 3. For further flexibility, one can exponentially weight future control or output errors, or not include the output errors in the performance index for the first few samples. Making the prediction horizon longer than the control horizon effectively adds robustness to the algorithm, without excessively increasing the optimisation search space.

CHAPTER 10. PREDICTIVE CONTROL

464

4. Incorporate constraints in the manipulated variable if appropriate. In the absence of constraints, and as the prediction horizons tend to ∞, the MPC will lead to the standard linear quadratic regulator as described in §9.4. The implementation phase is carried out each sampling time. 1. Use an optimiser to search for the next future Nc optimum control moves ut starting from the current position. 2. Implement only the first optimum control move found from step 1. 3. Wait one sample period, then go back to step 1. Use the previous optimum ut vector, (shifted forward one place) for the initial estimate in the optimiser. The following sections demonstrate various predictive controllers. Section 10.1.1 applies a predictive controller to a linear plant, but with input constraints. Because this is a nonlinear optimisation problem, a generic nonlinear optimiser is used to solve for the control moves. As you will see if you run the example in Listing 10.1, this incurs a significant computational burden. If we ignore the constraints, then we can use a fast analytical solution as shown in section 10.1.2, but this loses one of the big advantages of MPC in the first place, namely the ability to handle constraints. The M ODEL P REDICTIVE C ONTROL T OOLBOX for M ATLAB described in [26] is another alternative to use for experimenting with MPC.

10.1.1 Constrained predictive control This section demonstrates a constrained predictive control example using the following linear non-minimum phase plant, 1.5(1 − 2.5s) (10.4) Gp = 2 4s + 1.8s + 1 but where the manipulated variable is constrained to lie between the values −3.5 < u < 3. Sampling Eqn. 10.4 at T = 0.75 with a zeroth-order hold gives the discrete system Gp (z) =

−0.005z −1 − 0.4419z −2 1 − 1.596z −1 + 0.7136z −2

whose open loop response to a step change is illustrated in Fig. 10.3. To make the control problem more interesting, we will assume that Since we have a constraint in the manipulated variable, I will use the general nonlinear constrained optimiser fmincon from the O PTIMISATION T OOLBOX. The function to be minimised is fmodstpc in Listing 10.2 which returns the performance index. We can see from the discrete step response that a sample time of T = 0.75 is a reasonable choice. However the response drops before it climbs to the final steady-state, exhibiting an inverse response or non-minimum phase behaviour owing to the right hand plane zero at s = +2.5. With this sort of inverse behaviour, we must take care that the prediction horizon is sufficiently long to span the initial inverse response which again we can estimate approximately from the discrete step response. In this case I will set Hp = 20 and optimise for 10 inputs, Hc = 10. The control weightings are set to w = 1. The script file to run the simulation and to obtain results similar to Fig. 10.4 is given in Listing 10.1.

10.1. MODEL PREDICTIVE CONTROL

465

Step Response 2

Amplitude

1.5

1

0.5

0

Gp =

−0.5

−1

0

5

1.5(1−2.5s) 4s2 +1.8s+1 ,

10 15 Time (sec)

Ts = 0.75

20

25

Figure 10.3: An inverse plant model sampled at Ts = 0.75s.

Listing 10.1: Predictive control with input saturation constraints using a generic nonlinear optimiser ntot=150; dt=0.75; t=dt*[0:ntot-1]';

% time vector

2

r = [2,3,-2,-7,2]; % Interesting setpoint Yspt = ones(size(t(1:fix(length(t)/length(r))+1)))*r(:)'; Yspt = Yspt(1:length(t))'; % Cut off excess data points 7

12

tau = 2.0; zeta = 0.45; Kp=1.5;taup=2.5; % Create non-minimum phase plant Gss = ss(c2d(tf(Kp*[-taup 1],[tauˆ2 2*tau*zeta 1]),dt)); % discrete plant Hc = 10; % control horizon, Hc Hp = Hc+10; % prediction horizon, Hp > Hc Umin = randn(Hc+1,1); % start guess Ulb = -3.5*ones(size(Umin)); Uub = 3*ones(size(Ulb)); % bounds Uopt=zeros(size(t)); Y=zeros(size(t)); % initialise u(t) x = [0,0]'; % initialise starting point optns = optimset('Display','off','TolFun',1e-3,'TolX',1e-3); % optimiser options

17

for i=1:ntot-Hp-1; % for each sample time ... Umin = [Umin(2:end);Umin(end)]; % roll & repeat Umin = fmincon(@(u)fmodstpc(u,Gss,x,Yspt(i:i+Hp-1),Hp),Umin, ... [],[],[],[],Ulb,Uub,[],optns); 22

x = Gss.a*x + Gss.b*Umin(1,:)'; % do 1-step prediction Y(i,:) = Gss.c*x; Uopt(i,:) = Umin(1)'; % collect end % for i Yspt(1) = []; Yspt=[Yspt;1]; % shift due to fence-post error 27

32

subplot(2,1,1); % Now plot results plot(t,Y,t,Yspt,'r--') % plot results ylabel('output & setpoint') subplot(2,1,2); [ts,Us] = stairs(t,Uopt); plot(ts,Us,t,[ones(size(t))*mean([Ulb,Uub])],'k--') xlabel('time [s]'); ylabel('Input')

CHAPTER 10. PREDICTIVE CONTROL

466

The objective function to be minimised called by the optimiser is given in Listing 10.2. Note that auxiliary variables, such as the model, and horizon lengths are passed as anonymous variables through to the function to be optimised. Listing 10.2: Objective function to be minimised for the predictive control algorithm with input saturation constraints 1

6

11

function Perf = fmodstpc(U,G,x0,Yspt,Hp) % Short-term-prediction error called via fmincon via TGPC.M if Hp > length(U), % normally the case U = [U;U(end)*ones(Hp-length(U),1)]; % pad extra end % if P c 2 ssdu = sum(diff(U).ˆ2); % Control weightings N i=1 ∆ut+i−1 [Y,t,X] = lsim(G,U,[],x0); % do linear model prediction Perf = sum((Y-Yspt).ˆ2) + ssdu; return %

% Performance index J

The controlled performance as shown in Fig. 10.4 is very good, as indeed it should be. MPC: T =0.75, H =20, H =10 s

p

c

output & setpoint

5 0 −5 −10 4

umax Input

2 0 −2 −4

umin 0

20

40

60 time [s]

80

100

120

Figure 10.4: Predictive control of a non-minimum phase system with constraints on u with a control horizon of Hc = 10 and a prediction horizon of Hp = 20. Refer also to Fig. 10.5 for a zoomed portion of this plot. Especially note that since we are making use of a vector of future setpoints, the control algorithm starts preparing for the setpoint change before the actual setpoint changes. This acausal behaviour, illustrated more clearly in Fig. 10.5, is allowed because we assume we know future setpoints, improves the response compared with a traditional feedback only PID controller. Naturally the control becomes looser as the manipulated variable hits the upper and lower bounds. You will soon realise, if you run this example, that the computational load for the optimal input trajectory is considerable. With such a performance load, one needs to investigate ways to increase the speed of the simulation. Reasonable starting estimates for the new set of future control moves are simply obtained from the previous optimisation problem. Good starting guesses for the nonlinear optimiser are essential to ensure that the controller manages to find a reasonable output in the time available. Even though our model, ignoring the manipulated variable

10.1. MODEL PREDICTIVE CONTROL

467

MPC: Ts=0.75, Hp=20, Hc=10

output & setpoint

5

0

−5 H

H

p

H

c

p

−10 4

Input

2 0 −2 −4

30

35

40 time [s]

45

50

Figure 10.5: A zoomed portion of Fig. 10.4 centered about the setpoint change around t = 46 showing clearly the acausal response possible if we take advantage of the vector of future setpoints.

constraints, is linear, we have used a general nonlinear optimiser to solve the control problem. This means that the same algorithm will work in principle for any plant model, whether linear or nonlinear, and any constraint formulation. Naturally there are many extensions to the basic algorithm that address this issue such as only optimising every n-th sample time, or lowering Nc . However substantial simplifications can be made if we restrict our attention to just linear plants and bounded output, input and input rate constraints. Under these restrictions, the optimal MPC formulation can be re-written as a standard quadratic program, or QP for which there are efficient solution algorithms. Further details of this are given in [24, 164], and a commercial M ATLAB implementation is described in [27].

Varying the control and prediction horizons Investigating different controller design decisions is computationally expensive for this application, but we can relax the termination requirements for the optimiser with little noticeable change in results. From a computational complexity viewpoint, we want to reduce the search space, and hence reduce the horizons. However, reducing the horizons excessively, will result in a poor controlled response. Fig. 10.6 demonstrates what is likely to happen as the control and prediction horizons grow shorter. For a short control horizon, Nc = 2, and a reasonably short prediction horizon, Np = 8, but one that still covers inverse response, the controlled response is still quite reasonable as shown in Fig. 10.6(a). However decreasing the prediction horizon any further, even just slightly such as to Np = 7, gives problems as exhibited in Fig. 10.6(b). The inverse response horizon is ≈ 5. MPC on the laboratory blackbox Fig. 10.7 shows the result of using the constrained MPC on the black box assuming a constant model of the blackbox as 0.98 M: G(s) = (3s + 1)(5s + 1)

CHAPTER 10. PREDICTIVE CONTROL

468 GPC: T =0.75, H = 8, H = 2 s

p

GPC: T =0.75, H = 7, H = 2

c

s

0

−5

−5

2

2 Input

−10 4

Input

c

0

−10 4

0 −2 −4

p

5 output & setpoint

output & setpoint

5

0 −2

0

20

40

60 time [s]

80

100

120

−4

0

20

40

60 time [s]

80

100

120

(b) Short control & prediction horizons,Hc = 2, Hp = 7.

(a) Short control & reasonable prediction horizons, Hc = 2, Hp = 8.

Figure 10.6: Varying the horizons of predictive control of a non-minimum phase system with constraints on u. sampling at T = 0.75 seconds with a prediction horizon of Hp = 20, and control horizon of Hc = 10 samples. Clearly we should also estimate the controller model online perhaps using a recursive least-squares type algorithm. Black−Box: MPC ∆t=0.75, H =20, H =10 p

c

output & setpoint

0.5

0

−0.5

−1 1

input

0.5 0 −0.5 −1

0

20

40

60

80

100 time (s)

120

140

160

180

200

Figure 10.7: Constrained MPC applied to the laboratory blackbox with sampling at T = 0.75 sec and prediction & control horizons Hp = 20, Hc = 10.

10.1.2 Dynamic matrix control If you actually ran the simulation of the general optimal predictive controller from §10.1.1, and waited for it to finish, you would have stumbled across the one big drawback — computational load. As previously anticipated, one way to quicken the search is to assume a linear system, ignore any constraints, and make use of the analytical optimisation solution. To do this, we must

10.1. MODEL PREDICTIVE CONTROL

469

express our model as functions of input only, that is, a finite impulse response model, rather than the more parsimonious recursive infinite impulse response model. There are again many different flavours of this scheme, but the version here is based on the step response model,

y(t) =

∞ X i=1

gi ∆u(t − i)

(10.5)

where the gi s are the step response coefficients, and ∆u(t) is the change in input, or ut − ut−1 , refer Fig. 10.8. Suppose we start from rest, and make a unit step change in ∆u at time t = 0. Using Eqn. 10.5, the first few output predictions are

y1 = g1 ∆u0 + g2 ∆u−1 + · · · |{z} | {z } =1

(10.6)

=0

y2 = g1 ∆u1 + g2 ∆u0 + g3 ∆u−1 + · · · |{z} |{z} | {z } =0

=1

(10.7)

=0

y3 = g1 ∆u2 + g2 ∆u1 + g3 ∆u0 + · · ·

(10.8)

Since all the control moves are zero, except ∆u0 = 1, then it follows that y1 = g1 , y2 = g2 , y3 = g3 and so on. So the values of the output at each sample time yk in response to a unit step at k = 0 are the step response coefficients, gk . These coefficients form an infinite series in general, but for stable systems, converge to a limit as shown in Fig. 10.8.

output 6 ... ... .. .. ... ..

... .. .. .. .. .. .. .. ..

impulse coeff, h5 6 ?.. .. g3 ... .. .. .. .. . .. .. .. .. .. . . g2 Step response coefficients g1

0

6

.. ... .. .. ... ... .. .. ..

gNp .. .. ... ... .. .. .. .. ... ... ... ... .. .. .. .. .. ..  -

steady-state

- time

∆t Manipulated input

1 unit step - time Past 

0

- Future

Figure 10.8: Step response coefficients, gi , for a stable system.

CHAPTER 10. PREDICTIVE CONTROL

470

We can write the response of the model in a compact matrix form as     

y1 y2 .. . yN p





     =    |

g1 g2 g3 .. .

0 g1 g2 .. .

0 0 g1 .. .

gNp

gNp −1

gNp −2 {z

··· ··· ··· .. .

· · · gNp −Nc +1

dynamic matrix

yforced = G ∆u

0 0 0 .. .



       }

∆u0 ∆u1 .. . ∆uNc −1

     (10.9)

The Np × Nc matrix G in Eqn. 10.9 is referred to as the dynamic matrix, hence the term dynamic matrix control or DMC. It is also closely related to a Hankel matrix which provides us with a convenient, but not particularly efficient, way to generate this matrix in M ATLAB. Eqn. 10.9 tells us how our system will respond to changes in future moves in the manipulated variable. Specifically Eqn. 10.9 will predict over the prediction horizon, Np , the effect of Nc control moves. As in the general optimisation case, the input is assumed constant, ∆u = 0, past the end of the control horizon. All we need to do for our optimal controller, is to find out what to set these future control moves to, in order that the future outputs are close to the desired setpoints. Actually Eqn. 10.9 only predicts how our system will behave given future control changes, (termed the forced response), but it ignores the ongoing effect of any previous moves, (termed the free response). We must add the effect of the free response, if any, to Eqn. 10.9 to obtain a valid model prediction. This simple addition of two separate responses is a consequence of the linear superposition principle applicable for linear systems. We can calculate the free response over the prediction horizon, yfree simply by integrating the model from the current state with the current constant input for Np steps. Therefore to ensure our future response is equal to the setpoint, r, at all sample times over the prediction horizon, we require r = yfree + yforced

(10.10)

Again, since we will make the requirement that the control horizon is shorter than the prediction horizon, our dynamic matrix, G, is non-square, so the solution of Eqn. 10.9 for the unknown control moves involves a pseudo inverse. Typically we further weight the control moves to prevent an over-excited input demands by a positive weight λ, so the optimal solution to the predictive control problem is  −1 G⊤ (r − yfree ) (10.11) ∆u = G⊤ G + λI This analytical solution to the optimal control problem is far preferred above the numerical search procedure required for the general nonlinear case. Note that the matrix inversion in Eqn. 10.11 is only done once, offline and thus does not constitute a severe online numerical problem. The effect of the control move weighting improves the numerical conditioning of the matrix inversion. Fig. 10.9 shows in detail how this control philosophy works. If we are controlling a process with a controller that uses a prediction horizon of 12 samples and a controller horizon of 5, and we take a snap-shot at t = 135. The thick solid line (upper plot of Fig. 10.9) shows how the controller predicts the process will respond given the optimally calculated dashed input (lower plot) at time t = 135. Since the model inside the controller is slightly wrong owing to model/plant mismatch, the process would, in fact, follow the thin solid line if given the dashed pre-supposed optimal input profile. In actual fact, since only the first input is implemented, and the whole optimisation repeated at the next time step, the process follows the · · · ◦ · · · line given the solid input trajectory. A dynamic matrix control (DMC) example

10.1. MODEL PREDICTIVE CONTROL

471

DMC dt= 1.0 Hp= 12 Hc= 5 6

Output

4 2 0 -2 -4

134

136

138

134

136

138

140

142

144

146

148

150

140 142 144 time w= 1 noise var=0.04

146

148

150

3

Input

2 1 0 -1 -2

Figure 10.9: DMC predictive control showing at t = 135 how the controller predicts the process will respond (heavy-solid line) given the current calculated optimal (dashed) input trajectory, how the process would really respond (light-solid line), and how in fact eventually the process was controlled (· · · ◦ · · · ) given the solid input trajectory. Fig. 10.10 shows the performance of a DMC controller for the non-minimum phase plant of Eqn. 10.4 from §10.1.1. I generated the step response coefficients elegantly from the transfer function model simply using the dstep command. For illustration purposes in this simulation I have varied the control move weighting, λ in Eqn. 10.11 as λ = 100 for t < 50, then λ = 1 for the interval 50 < t < 100, and then finally λ = 0. The controller uses a prediction horizon of Hp = 25, a control horizon of Hc = 8 at a sample time of T = 0.5. The manipulated variable constraints present in §10.1.1 are relaxed for this example. As the control move weighting is decreased, the output performance improves at the expense of vigorous manipulated variable movements. Note that a weighting λ = 0 is allowable, but will result in an over-excited controller. The m-file for this DMC example, but using a constant weight of λ = 1 is given in Listing 10.3. Listing 10.3: Dynamic Matric Control (DMC) control

4

ntot=250; dt=0.5; t=dt*[0:ntot-1]';% time vector r = [1,3,-1,-2.5,3.5,5.4,-4,-6,5,2.2]; % random square wave setpoint Yspt = ones(size(t(1:fix(length(t)/length(r))+1)))*r(:)'; Yspt = Yspt(1:length(t))'; % Cut off excess data points Kp=1.5;taup=2.5; tau = 2.0; zeta = 0.45; % process model Gpc = tf(Kp*[-taup 1],[tauˆ2 2*tau*zeta 1]); % Kp (−τp s + 1)/(τ 2 s2 + 2ζτ s + 1) Gp = c2d(Gpc,dt); % discrete plant

CHAPTER 10. PREDICTIVE CONTROL

472

T =0.5, H =25, H = 8 s

p

c

1

Y & spt

0.5

0

−0.5

−1 1

U

0.5 0 −0.5 −1

λ = 100 0

λ = 20

λ = 0.1

50

100 sample time

Figure 10.10: DMC predictive control of a non-minimum phase system with Hc = 8, Hp = 25 showing the effect of varying the control move weighting λ.

9

[Phi,Del,C,D] = ssdata(Gp);

% state space for x0

Hc = 8; % Control horizon, Hc Hp = 25; % Prediction horizon, Hp > Hc 14

19

24

[g,ts] = step(Gp,dt*Hp); % step response coefficients g(1) = []; % only consider Hp points (ignore first zero) % Formulate DMC G matrix & inverse once; (offline) Hankel version G = flipud(hankel(flipud(g))); G(:,Hc+1:end) = []; weight=1; % control move weighting w ≥ 0 GG = G'*G; % G⊤ G −1 ⊤ invG = (GG + weight*eye(size(GG)))\G'; % G⊤ G + λI G x = [0,0]'; y=C*x; u=0; p=0; % cheat here but Ok Uopt=zeros(size(t)); Y=zeros(size(t)); % initialise u(t) for i=1:ntot-Hp-1; du = invG*(Yspt(i:i+Hp-1)-p); % analytical optimisation u = du(1)+u ; % only take first change x = Phi*x + Del*u; y = C*x; % apply 1 control move

29

% Calculate future free response (assume all future du=0) [p,px] = dlsim(Phi,Del,C,D,u*ones(Hp+1,1),x); p(1)=[]; % kill repeat of x0 34

39

Y(i,:) = y; Uopt(i,:) = u; end % for i Yspt(1) = []; Yspt=[Yspt;1]; subplot(2,1,1); plot(t,Y,t,Yspt,':') subplot(2,1,2); stairs(t,Uopt);

% plot results

The high fidelity of the controlled response of both predictive control algorithms, (Figures 10.4 and 10.10) is helped by the lack of model/plant mismatch in the previous simulations. In practice, faced with the inevitable mismatch, one can extend the basic DMC algorithm such as varying the

150

10.1. MODEL PREDICTIVE CONTROL

473

weights and/or horizon lengths or by including an adaptive model and therefore performing the matrix inversion online. In some cases, particularly for unstable processes, or for cases where the sampling rate is either very fast or very slow compare with the step response of the system, the DMC algorithm will fail primarily owing to the poor conditioning of G. In these cases singular value decomposition may help.

DMC of the blackbox A DMC controller is tried on the laboratory blackbox in Fig. 10.11. Unlike the GPC example on 468 however, here we will identify the model online using a recursive least-squares estimation algorithm. The model-based controller assumes the structure M:

G(q −1 ) =

b0 + b1 q −1 + b2 q −2 1 + a1 q −1 + a2 q −2 + a3 q −3

for the blackbox with a sample time of T = 1.5 seconds and a forgetting factor of λ = 0.995. The controller horizon is set to 8 samples, and the prediction horizon is set to 20 samples. The control move weighting is set to 0.2. DMC of the blackbox ∆ t=1.50, H =25, H = 8 p

c

output & setpoint

1

0.5

0

−0.5

−1

0

50

100

150

200

250

300

350

400

300

350

400

RLS Model ID λ=0.20, n = 3, n = 2 a

b

1

Input

0.5

0

−0.5

−1

0

50

100

150

200 time (s)

250

Figure 10.11: Adaptive dynamic matrix control (DMC) of the blackbox with control horizon Hc = 8 and prediction horizon Hp = 20.

CHAPTER 10. PREDICTIVE CONTROL

474

10.2 A Model Predictive Control Toolbox A Model Predictive Control toolbox developed by Currie, [55, 56] allows one to rapidly build and test various MPC configurations for a wide variety of linear, or linearisable nonlinear plants with both soft and hard constraints on the output, the input and input rate of change. The following sections describe this toolbox in more detail.

10.2.1 A model predictive control GUI The easiest way to get started is to use the Model Predictive Control toolbox GUI as shown in Fig. 10.12. In this M ATLAB GUI, one can load and experiment with different plants (and models of those plants), adjust prediction horizons, operating constraints, and setpoints. What is interesting to observe in the GUI application are animations of the future output and input predictions given to the right of the solid line in the scrolling plot.

Figure 10.12: An MPC graphical user interface

10.2.2 MPC toolbox in M ATLAB The MPC toolbox is easy to use in script mode. This section shows how to build a multivariable MPC controller using the Wood-Berry column plant in Eqn. 3.24 from section 3.3.3. This plant has 2 inputs (reflux and steam) and two outputs (distillate and bottoms concentration) and we will use a sampling time of Ts = 2 seconds. For this application we will assume no model/plant mismatch.

10.2. A MODEL PREDICTIVE CONTROL TOOLBOX

475

Listing 10.4: Setting up an MPC controller 1

6

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]) % The Wood-Berry column plant from Eqn. 3.24 Plant = jSS(G); % Convert the LTI model to a special form required for the MPC controller Ts = 2; Plant = c2d(Plant,Ts); % Discretise the plant at Ts = 2 seconds Model = Plant; % Assume (for the moment) no model-plant mismatch

Now we are ready to specify the controller tuning parameters which include the length of the control and prediction horizons, the values of the input and output saturation constraints, and the relative input and output weights in the objective function.

2

Np = 10; % Prediction Horizon Nc = 5; % Control Horizon

7

con.u = [-1 -1 con.y = [-2 -2

1 0.1; ... % Input weights: umin , umax , ∆umax 1 0.1]; % One row for each input 2; % Output weights: ymin , ymax 2] ;

uwt = [1 1]'; % Individual weighting on the inputs ywt = [1 0.1]'; % We are less interested in controlling bottoms, y2 12

Kest = dlqe(Model); %Estimator Gain

Now we are ready to initialise the model (and plant). To that, we need to know how many internals states we have in our discrete model. That number depends on the discretisation method, and the sampling rate, so the easiest way is to inspect the properties of the plant and model.

3

>> Plant Plant = -- jMPC State Space Object -States: 10 Inputs: 2 Outputs: 2 Sampling Time: 2 sec

8

>> Plant.x0 = zeros(10,1); % Initial condition of the 10 states >> Model.x0 = zeros(10,1);

Finally we are ready to design a setpoint trajectory, assemble the MPC controller, and simulate the results. In this case we are using the high-speed MEX version of the optimisation routines. T = 200; % Desired simulation length setp = 0.5*square(0.05*Ts*[0:T]',50)+0.7; % Design interesting setpoint setp(:,2) = 0.5*square(0.1*Ts*[0:T]',50)-0.7; setp(1:10,:) = 0; 5

MPC1 = jMPC(Model,Np,Nc,uwt,ywt,con,Kest); % Construct an MPC controller simopts = jSIM(MPC1,Plant,T,setp); % Set some simulation options

CHAPTER 10. PREDICTIVE CONTROL

476

10

simresult = sim(MPC1,simopts,'Mex'); % Simulate & plot results plot(MPC1,simresult,'summary'); suptitle(sprintf('Horizons: N_p=%2i, N_c=%2i',Np,Nc))

The results for this multivariable MPC example are shown in Fig. 10.13. Note how the control of y2 is considerably looser than that for y1 . This is a consequence of the output weights which are ten times higher for y1 . Also note that the change in input ∆u never exceeds the required ±0.1. Horizons: N =10, N = 5 p

c

Outputs: y (k)

States: x (k)

p

p

6 4 Amplitude

Amplitude

1

0

2 0

−1 0

50

100

150

−2

200

0

50

0.1

0.4

0.05 Amplitude

Amplitude

150

200

150

200

Change in Input: ∆ u(k)

Input: u(k) 0.6

0.2 0 −0.2

100

0 −0.05

0

50

100 Sample

150

−0.1

200

0

50

100 Sample

Figure 10.13: Multivariable MPC of the Wood-Berry column.

10.2.3 Using the MPC toolbox in S IMULINK It is also easy to implement MPC controllers in S IMULINK. Fig. 10.14 shows an MPC controller from the jMPC toolbox connected to an unstable, non-minimum phase plant G(s) =

s−1 (s − 2)(s + 1)

(10.12)

which is difficult to control and has been used in various benchmark control studies, [103].

u

mdist double

Signal Generator

double

(s−1)

double

(s−2)(s+1) delu

Plant

setp ym yp

xm Discrete MPC Controller

Figure 10.14: The MPC block in the S IMULINK environment.

Scope

10.2. A MODEL PREDICTIVE CONTROL TOOLBOX

477

To use the MPC controller block in S IMULINK, we first must design an MPC controller in the same way as we did in section 10.2.2. Once we have designed the controller, we can simply insert it into the discrete MPC controller block and connect it to our plant. However in this case instead of using the true plant inside the model-based MPC controller, we will inadvertently use the slightly different model ˆ = 0.95(s − 1) (10.13) G (s − 2.1)(s + 1) thereby introducing some model/plant mismatch. Model = jSS(zpk([1],[2.1 -1],0.95));% Mismatch: Compare Eqn. 10.12 with Eqn. 10.13. Ts = 0.1; Model = c2d(Model,Ts); % Discretize Model Np = 40; Nc = 5; con.u = [-5 5 0.3]; con.y = [-2 2]; uwt = 1; ywt = 0.5; Kest = dlqe(Model);

4

% Prediction & control Horizons % Input & output constraints % input & output weightings

9

14

T = 800; setp = square(0.2*Ts*[0:T]',50); setp(1:10,:) = 0; Model.x0 = zeros(2,1); % Initial values

% Setpoint

MPC1 = jMPC(Model,Np,Nc,uwt,ywt,con,Kest);

% Build the MPC controller

The last line created an MPC controller object called MPC1 which we can place in the MPC controller block in the S IMULINK diagram in Fig. 10.14. Note that the true plant, Eqn. 10.12 is never actually used in the MPC controller. The results of the subsequent S IMULINK simulation in Fig. 10.15 show that we hit, but do not exceed, the input rate constraint during the transients. 2

y

1 0 −1 −2 4

u

2 0 −2

∆u

−4 0.5

0

−0.5

0

10

20

30

40

50

time

60

70

Figure 10.15: MPC of a SISO non-minimum phase unstable plant with model/plant mismatch from Fig. 10.14.

10.2.4 Further readings on MPC Model predictive control is now sufficiently mature that it has appeared in numerous texts, [132, 173, 197], all of which give an overview of the underlying theory, and insight into the industrial practice. Industrial applications using commercial implementations such as Pavilion

CHAPTER 10. PREDICTIVE CONTROL

478

Technologies’ Pavilion8, Honeywell’s RMPCT or Perceptive Engineering have been surveyed in [162]. A commercial MPC toolbox for M ATLAB is available in [27] while freeware versions also exist from [55] and [4]. Problem 10.1 1. Repeat the DMC simulation of §10.1.2 but add an integrator to the plant. Adjust the constraints 2. Repeat the DMC simulation of §10.1.2 but add some model/plant mismatch by both varying one of the model parameters, and adding noise to the true system. Investigate the performance of DMC control by varying the length of the prediction and control horizons. Construct a contour plot of ISE as a function of Nc and Np over a sensible range of values. 3. Modify the basic DMC simulation given in §10.1.2 to investigate the robustness of the technique to structural model/plant mismatch. You should start by separating the model used by the DMC and the true process, and introduce some minor structural mismatch (gains and time constants changed by 10% for example). How does the controlled performance deteriorate as the model gain changes? 4. Design an adaptive DMC regulator by introducing an online model parameter estimator as discussed in chapter 6, section §6.7.2 to the simulation completed in question 3. Investigate ways to improve the robustness, and to reduce the computational requirements.

10.3 Optimal control using linear programming Optimal control problems quickly demand excessive computation, which all but eliminates them from practical real-time applications. If however our model is a linear discrete-time state-space model, our performance objective is to minimise the sum of the absolute value, rather than the more normal least-squares, and we have linear constraints on the manipulated variables, then the general constrained optimisation problem becomes a linear program. Linear programs or LPs are much more attractive to solve than a general constrained nonlinear optimisation problem of comparable complexity because, in theory, they can be solved in a finite number of operations, and in practice they are far more successful at solving problems with more than 50 variables and 100 constraints on modest hardware. The theory of linear programming is well known, and if the problem is poorly conditioned, or not ‘well-posed’, then the software will quickly recognise this, ensuring that we do not waste time on impossible, or poorly thought out problems. There are many computer codes available to solve linear programs, including linprog from the O PTIMIZATION T OOLBOX. An introduction to linear programming with emphasis on the numerical issues with M ATLAB is given in [201], and an experimental application is given in [146] from which this section was adapted. As in the predictive control development, we want a controlled response that minimises the error between setpoint, r, and the actual state, say something like Eqn. 9.8 J =

Z



f (x, r)

0

In this application we will take the absolute value of the error, partly because this is a more robust measure than the classical least-squares, but mainly because a squared error will introduce a nonlinearity into the performance objective, which will render the linear programming inapplicable. We will also consider only a finite time horizon, and since the model is discrete, we will use a simple sum in place of the integral. The optimisation problem is then to choose the set of future

10.3. OPTIMAL CONTROL USING LINEAR PROGRAMMING

479

manipulated variables uk over the time horizon such that the performance index J =

N X n X k=0 i=1

|ri − xi |

(10.14)

is minimised subject to the process model. In Eqn. 10.14, n is the number of states, and N is the number of samples in the time horizon, (typically around 10–20). If desired, Eqn. 10.14 could be further modified by adding state weighting if some states are more important than others.

10.3.1 Development of the LP problem The hardest part of this optimal controller is formulating the LP problem. Once that is done, it can be exported to any number of standard numerical LP software packages to be solved. We will use a discrete state model for the predictive part of the controller. xk+1 = Φxk + ∆uk

(10.15)

Unwinding the recursion in Eqn. 10.15, we can calculate any subsequent state, xk given the manipulated variable history, and the stating condition, x0 , (refer Eqn. 2.81, xk = Φk x0 + Φk−1 ∆u0 + Φk−2 ∆2 u1 + · · · + ∆uk−1

(10.16)

If rk is the setpoint at sample time k, then the error is rk − xk = rk − Φk x0 − Φk−1 ∆u0 − · · · − ∆uk−1

(10.17)

We desire to minimise the sum of the absolute values of these errors, as given in Eqn. 10.14, but the absolute value sign is difficult to incorporate in a linear programming format. We can instead introduce two new non-negative variables,  ǫ1i := ri − xi if ri ≥ xi (10.18) ǫ2i := 0 otherwise

ǫ1i := 0 ǫ2i := xi − ri



if

xi ≥ ri

(10.19)

Note that we could write the above four relations without the IF statement as something like: e1 = abs(r-x)*round(sign(r-x)/2 + 0.5) e2 = abs(x-r)*round(sign(x-r)/2 + 0.5)

for scalar x and r. Using definitions Eqns 10.18–10.19, the absolute value is |ri − xi | = ǫ1i + ǫ2i

(10.20)

ri − xi = ǫ1i − ǫ2i

(10.21)

and the error Both relations are valid at all times because only one of either ǫ1 or ǫ2 is non-zero for any particular state at any particular time.

CHAPTER 10. PREDICTIVE CONTROL

480

Re-writing the objective function, Eqn. 10.14 in terms of the new variables using Eqn. 10.20 gives the linear relation without the troublesome absolute values. J =

N X n X

(ǫ1i + ǫ2i )k

(10.22)

k=0 i=1

The penalty paid is that we have doubled the number of decision variables, thereby doubling the optimisation space. Eqn. 10.22 is a linear objective function suitable for a linear program. The constraints arise from the model dynamics which must be obeyed. Substituting Eqn. 10.21 into Eqn. 10.17 gives N blocks of equality constraints, each with n equations. To make things clearer, the first few blocks are written explicitly out below. ǫ11 − ǫ21 +∆u0 = r1 − Φx0 | {z } r1 −x1 ǫ12 − ǫ22 +Φ2 ∆u0 + ∆u1 = r2 − Φ2 x0 | {z } r2 −x2 .. . ǫ − ǫ +Φk−1 ∆u0 + Φk−2 ∆u1 + · · · + ∆uk−1 = rk − Φk x0 | 1k {z 2k} rk −xk

Naturally this is best written in a matrix form.



u0



   u  1      .   .   .     u    N −1     ∆ 0 · · · 0 I −I r1 − Φx0 ǫ11         r2 − Φ2 x0 ∆ ··· 0 I −I   Φ∆    ǫ21  = ..      .. .. .. .. .     . . . 0 .   ǫ12   r − ΦN x 0 N   N −1 N −2  Φ ∆ Φ ∆ ··· ∆ I −I   ǫ22       ..   .      ǫ  1N    ǫ2N

    

(10.23)

The dimensions of the partitions in this large constraint matrix are given in Fig. 10.16 where N is the number of future sample horizons, n is the number of states, and m is the number of manipulated variables. The constraint matrix in Fig. 10.16 is a N n × (N m + 2N n) matrix, the decision variable vector has N m manipulated variables and 2N n auxiliary variables comprising of (N m + 2N n) × 1 vector, and the right-hand side is a N n × 1 vector. In general applications it is necessary for the control variable, u, to be unrestricted in sign, which is counter to the formulation required in most linear programming packages. To achieve this we,

10.3. OPTIMAL CONTROL USING LINEAR PROGRAMMING

     Nn   

m z }| {

n

Φ

∆ Φ∆ .. .

0 ∆ .. .

··· ··· .. .

0 0 .. .

N −1

N −2

···



∆ Φ

|

∆ {z

n z }| { I

−I

−I

I

}|

Nm

481

..

.



n

−I

I

{z

}

2N n

Figure 10.16: LP constraint matrix dimensions must introduce two further new variables, both non-negative, for each manipulated variable. u := s − t,

s, t ≥ 0

(10.24)

If the unrestricted u > 0, then t = 0, otherwise u is negative and s = 0. This substitution modifies the A matrix in the constraint equation, Eqn. 10.23, to        

Φ



0

··· 0

−∆

0

···

0

Φ∆

∆ .. .

−Φ∆

−∆

···

0

.. .

··· 0

.

0

N −1

N −2

∆Φ

..

.. .

. 0

N −1

∆ · · · ∆ −Φ

.. .

N −2

∆ −Φ

..



I −I I −I

..

∆ · · · −∆

. I −I

      

and the decision variables are now h

s0

s1

· · · sN −1

.. . t0

t1

· · · tN −1

.. .

ǫ11

· · · ǫ2N

i⊤

Using this ordering of decision variables, the objective function, Eqn. 10.22, is the sum of the ǫs. In linear programming, the objective function is written as J = c⊤ x, where c is termed the cost vector, and x is the decision variable vector to be optimised. In our case the cost vector is given as #⊤ " 1 1 1 1 ··· 1 0 0 ··· 0 (10.25) c= | {z } | {z } 2N m

2N n

Note that the manipulated variables do not explicitly enter the objective function. Naturally the ones in Eqn. 10.25 could be replaced by different positive individual time and state weightings, if so desired.

This completes the formal development of the LP as far as the unconstrained optimum controller is concerned. However since we are already solving a constrained optimisation problem, there is little overhead in adding extra constraints such as controller upper and lower bounds to the problem. In practice the manipulated space is limited, (a control valve can only open so far, an electric drive is limited in top speed), so we are interested in constraints of the form ulower ≤ u ≤ uupper These constraints can be appended to the other constraint equations.

(10.26)

CHAPTER 10. PREDICTIVE CONTROL

482 Simplifications when using the optimisation toolbox

When using linprog.m from the O PTIMIZATION T OOLBOX, certain simplifications are possible to the standard LP problem form. These simplifications reduce the problem size, and therefore also reduce the solution time. Since the algorithm does not make the non-negative constraint assumption, we do not need to introduce the variable transformation given by Eqn. 10.24, and suffer the associated growth of the constraint matrix. This is not the case in general, if we were to use other LP routines such as described in [201] or [78], then we would need to use non-negative variables. Most LP programs assume the constraints are given as Ax ≤ b, i.e. less-than inequalities rather than equalities as in Eqn. 10.23. While the conversion is trivial, it again increases the number of constraint equations. However the routine linprog conveniently allows the user to specify both equality and inequality constraints. The third simplification is to exploit how linprog handles constant upper and lower bounds such as needed in Eqn. 10.26. These are not added to the general constraint matrix, Ax ≤ b, but are supplied separately to the routine. All these modifications reduce the computation required to solve the problem.

Optimal control using linear programming Listing 10.5 demonstrates a finite time-horizon optimal controller with a randomly generated stable multiple-input/multiple output (MIMO) model. The optimisation problem is solved using the linear program linprog from the O PTIMISATION T OOLBOX. Listing 10.5: Optimal control using linear programming 1

n = 2;% # of states m = 2;% # of manipulated variables [Ac,Bc,C,D]=rmodel(n,1,m); % Some arbitrary random model for testing

11

Gc = ss(Ac,Bc,C,D); dt = min(1. ./abs(eig(Ac)))/0.5; % sparse sample time reasonable guess G = c2d(Gc,dt,'zoh'); G.d = zeros(size(G.d)); % clear this if rank(ctrb(G)) 6= n error('System not controllable') end % if

16

N = 20; % future optimisation horizon x0 = randn(n,1); % random start point r = [ones(floor(N/2),1)*randn(1,n); ... ones(ceil(N/2),1)*randn(1,n)]; % setpoint change

6

21

26

%% start construction of the LP matrix Phin = G.b; Aeq = G.b; % better for when m>1 for i=2:N Phin = G.a*Phin; Aeq = [Aeq; Phin]; % rough method end Z = zeros(size(G.b)); % padding for i=2:N Aeq = [Aeq, [Z;Aeq(1:(N-1)*n,(i-2)*m+1:(i-1)*m) ]];

10.3. OPTIMAL CONTROL USING LINEAR PROGRAMMING

483

end % for i

31

36

41

46

51

56

% weighting Could use blkdiag here (but messy) W = eye(n); % change if want different state weighting A2 = zeros(N*n,2*N*n); % initialise for i=1:N A2((i-1)*n+1:i*n,2*(i-1)*n+1:2*i*n) = [W, -W]; end % for Aeq = [A2,Aeq]; % put +ve variables before general +/- variables % Now right-hand side ..... U = zeros(N+1,m); % unforced, therefore zero input (drop start term) [yuf,t,xuf]=lsim(G,U,[],x0); % simulate unforced response xuf(1,:) = []; % drop start term since dlsim repeats it. b = r - xuf; % error b = b'; beq = b(:); % columnerise % Now objective function [nr,nc] = size(Aeq); % current size c = zeros(1,nc); % row vector for the moment c(1:2*N*n) = 1; % unity weights for the moment ! % Set up A*x < b (or -Ax > 0) b = zeros(2*N*n,1); % All #s are positive A = zeros(2*N*n,nc) A(:,1:2*N*n) = -eye(2*N*n); tic; % now ready to solve LP .................. ulow = -13; uhigh = 14; % upper/lower constraints xlower = [zeros(2*N*n,1); ulow*ones(N*m,1)]; xupper = [1e6*ones(2*N*n,1); uhigh*ones(N*m,1)]; xsol=linprog(c',A,b,Aeq,beq,xlower,xupper); % first 2Nn are +ve toc

61

% extract solution, if found U = xsol(2*N*n+1:end); % must reshape if m6=1 U = reshape(U,m,length(U)/m)'; % MI system 66

71

76

[y,t,xopt] = lsim(G,U,[],x0); % Now test system response %k = [0:length(xopt)-1]'; [ts,rs] = stairs(t,r); [ts,Us] = stairs(t,U); subplot(2,1,2); plot(ts,Us,t,ones(size(t))*[ulow, uhigh],'--'); h = line(ts,Us); set(h,'LineWidth',2); %set(gca,'YLim',[-4,4.5]) xlabel('sample #'); ylabel('Manipulated') % Sub-sample output response nsub = 500; % # of sub-samples total (approx 500) ts2 = ts(:,1) + [1:length(ts)]'/1e10; ts2(1) = 0; % destroy monotonicity t2 = linspace(0,t(end),nsub)'; U2 = interp1(ts2,Us,t2);

81

[y,t2,xoptsc] = lsim(Gc,U2,t2,x0); subplot(2,1,1); plot(ts(:,1),rs,':',t2,xoptsc); h = line(t,xopt); set(h,'Marker','.','MarkerSize',24,'LineStyle','none');

CHAPTER 10. PREDICTIVE CONTROL

484 86

ylabel('state'); title('LP optimal control')

You should run the simulation a number of times with different models to see the behaviour of the optimal controller. One ideal 2-input/2 state case is given in Fig. 10.17. Here the states reach the setpoint in two sample times, and remain there. The manipulated variables remain inside the allowable upper (4) and lower (−3) bounds. It is clear that the trajectory is optimal, since the sum of the absolute error at the sample points is zero. One cannot do better than that. LP optimal control

state 1

0

−0.5

−1

−1.5 2

state 2

1 0 −1

Manipulated

−2 20 0 −20

0

5

10 sample #

15

20

Figure 10.17: LP optimal control with no active manipulated variable bounds. Note the “perfect” controlled performance. We hit the setpoint in one sample time, and stay there. One cannot do much better than that within the limitations of discrete control. The plot was generated by Listing 10.5. In another case, the manipulated bounds may be active and consequently the setpoint may not be reached in the minimum time, and our objective function will not reach zero. In Fig. 10.18, both steady-states are reachable, but owing to the upper and lower bounds on u, they cannot be met in just two sample times. In other words we have hit the manipulated variable constraints during the transients. Our system does not need to be square, Fig. 10.19 shows the results for a 3-state, 2 input problem. In this case, one state is left ‘floating’. Some small inter-sample ripple is also evident in this case. Note that since this is a predictive controller, and it knows about future setpoint changes, it anticipates the changes and starts moving the states before the setpoint change. Fig. 10.20 shows

10.3. OPTIMAL CONTROL USING LINEAR PROGRAMMING

485

LP optimal control 2

state

1 0 −1 −2 0

1

2

3

4

5

6

7

8

9

Manipulated

4 2 0 −2 −4 0

1

2

3

4 5 sample time

6

7

8

9

6

7

8

9

Figure 10.18: LP optimal control with active manipulated variable constraints. During transients, the manipulated variables hit the upper constraints, so compromising the controlled performance for a short period.

LP optimal control 2

state

1 0 −1 −2 −3 0

1

2

3

4

5

Manipulated

4 2 0 −2 −4 0

1

2

3

4 5 sample time

6

7

8

9

Figure 10.19: Non-square LP optimal control with 3 states and 2 inputs. Note the small inter-sample ripple.

the case for a 2 × 3 system where owing to the active upper and lower bounds on u, the controller knows that it cannot reach the setpoint in one sample time, hence it chooses a trajectory that will minimise the absolute error and in doing so, starts the states moving before the setpoint.

CHAPTER 10. PREDICTIVE CONTROL

486

LP optimal control 1 0.5 state

0 −0.5 −1 −1.5 −2 0

1

2

3

1

2

3

4

5

6

7

8

9

6

7

8

9

Manipulated

4

Figure 10.20: LP control showing behaviour

optimal acausal

2 0 −2 −4 0

4 5 sample time

Chapter 11

Expert systems and neural networks

Doctor Whirtzle’s controversial “talking brain in a jar” is revealed for the shameless fraud that it was. ©1995 David Farley

11.1 Expert systems An expert system is a computer programme that uses knowledge and techniques in much the same way as a human expert would to solve a wide variety of problems. Typically expert systems are used for types of problems that cannot be successfully solved using traditional procedural type programmes. Expert systems do not use numeric data like conventional programmes, but they manipulate symbolic data instead. Expert systems differ from human experts in that:

Human experts have the following characteristics that expert systems try to duplicate:

• They do not die, retire or go to sleep, and will diligently work 24 hours a day.

• A narrow field of expertise (domain) • Usually are formal about decision making and can justify their reasoning.

• They are easily duplicated – One just copies the programme and supplies additional hardware if required.

◦ Use all possible senses (touch, hearing, sight, smell etc.)

◦ Generally cheap to maintain once the original development is done.

• They do not do large quantitative number crunching in their head,– at least initially.

• Expert systems find it difficult to use “common sense” or to realise if a situation is sufficiently novel that it should fail gracefully.

• Can deal with vague and uncertain or even irrelevant input data. • Learn from past experience.

487

488

CHAPTER 11. EXPERT SYSTEMS AND NEURAL NETWORKS

The concept of Expert systems, or machines that can reason in a manner similar to humans, seems to worry some people. One strong argument against the algorithmic view of the human brain was put forward by Roger Penrose in the popular, but detailed work The Emperor’s New Mind.

11.1.1 Where are they used? Expert systems originally grew out of the field of artificial intelligence (AI) and is now used in game playing, theorem proving, pattern recognition and diagnosis, [81]. Languages used in AI are typically different from conventional languages such as FORTRAN, Cobol, Pascal etc. AI languages deal with symbolic notation rather than numeric data and include LISP, Prolog, POP and OOPs. However, some applications in AI use conventional languages with extensions (Object Oriented Pascal, C++).

Artificial intelligence is sometimes difficult to distinguish from monkey business.

Conventional programmes (rather than expert systems) are used for applications such as payroll calculations, finite element analysis, 3D flight simulators etc. Here the problem can be rigorously defined and an accurate numerical answer is required. Some well known expert systems are: M YCIN Medical diagnosis for bacterial infections. This has been shown, in its admittedly limited domain, to be better than expert human doctors . E MYCIN : (Empty M YCIN) Similar programme as the above M YCIN, but without the data for bacterial infections. This allows other applications to use the same programme shell but in different domains. P ROSPECTOR : Gives advice about mining and drilling operations. This programme pointed to a $2 billion molybdenum deposit that human experts had previously overlooked. All the above expert systems have enjoyed good success, but then they also have had hundreds of human years effort. However in the case of P ROSPECTOR, which is invariably cited by AI enthusiasts as a particularly good example, [102] notes that it is credited for finding only one mineral deposit around 1982, and this was achieved using a never-released experimental version rather than the publicly available version. Since that time, there have been no other reported mineral deposit finds.

11.1.2 Features of an expert system Most expert systems have in addition to a knowledge base, a facility to explain how it arrived at a decision, some sort of question and answer format, and an accompanying probability analysis to address the degree of uncertainty.

11.1. EXPERT SYSTEMS

489

In structure they have an inference engine, a knowledge base, and after time, some case specific data.

An inference engine This is the part of the programme that decides what knowledge is relevant and what further questions need to be asked to arrive at a conclusion. It is the central core or kernel. There are two different styles of inference engine: 1. Goal driven or top down 2. Data driven or bottom up The style which is used depends on the application. A goal driven system asks questions that work backwards from a possible goal to find pre-requisites (sub goals) until the initial conditions required by the proposed goal are the same as the actual initial conditions. A data driven method looks at the data and examines which rules are satisfied. The rules that are satisfied are said to “fire” which in turn may satisfy conditions for other rules to fire. This continues until a goal is satisfied. An example of the two types of inference engine methods are from HAZOP (hazard and operability) studies. • Consider causes: top down • Consider consequences: bottom up

Goal driven Suppose you are an expert consultant employed by a multinational oil company which is wondering why their plant has just exploded. You propose (guess) that a pipe carrying octane corroded at an elbow spraying flammable material around. A dialogue between an expert (you) and an eye witness might go something like Was there a large plume after the explosion? ... Yes Was the centre of the explosion 50m down wind of the suspected leak? ... Well it was about 100m I suppose.

You are trying to establish sufficient evidence to support your initial hypothesis.

Data driven You are designing a new plant and carry out a consequence analysis as part of a preliminary H AZOP (Hazard and operability study). You might ask: What would happen if pump #23 failed? Would the pressure be high enough to rupture the vessel? Would the contents find a source of ignition within the explosive limit?

490

CHAPTER 11. EXPERT SYSTEMS AND NEURAL NETWORKS

Here you are taking the initial data and evaluating what would happen given that data. You then match that with what really happened.

Knowledge representation in expert systems Information in the knowledge base has two forms; facts and rules. The fact base contains a collection of fact statements. These facts may be stored in the form older(John,Paul) which is read as “John is older than Paul”. This way of expressing facts is derived from the P ROLOG programming language. Rules in a more engineering context could be: saturated(steam,100C, 1 Bar) saturated(freon,-36C,1 Bar) rupture(boiler, 15 Bar)

These facts can be dynamically updated or deleted from the knowledge base as the expert system grows and gains experience. The second type of knowledge representation is as rules. The rules are usually of the simple I F . . . T HEN . . . E LSE type. I F the flame colour is blue AND the flow rate is high THEN a secondary reaction is occurring. Other types of knowledge representations are possible such as semantic nets or neural networks. Neural networks are introduced in §11.2.

11.1.3 The user interface The user interface is the part of the programme that asks the questions and receives the answers. Generally the users of the expert system are not computer experts and would like to communicate in as near to natural language as possible. An example that requires a good user interface is one where a group of doctors installed a common disease diagnosis expert system in the waiting room of their surgery. The waiting patients could ask the Expert system, in the same way they could ask the doctor what was wrong with them, whilst waiting for the doctor. Supposedly the programme was not too successful, or the doctors might soon be out of a job. The user interface can operate on at least 3 levels: 1. Solves problems for the client. (normal mode) 2. The user is an expert who is extending the knowledge base of the system. 3. The user is extracting knowledge from the programme. (Industrial espionage?)

11.1.4 Expert systems used in process control Why is it that an experienced human operator can often satisfactorily control large complex plants when they exhibit nonlinear time varying behaviour and where there is little or no precise knowledge available? Examples are control of processes such as sugar crystallisation, cement kilns, floatation separations etc. All these plants involve imprecise measurements such as sharpness of crystals, colour of the flame, shape and size of bubbles, and stability of boiling. Given that conventional controllers have difficulty and are substandard when compared to the human operators, it seems logical to try and develop non-conventional computer based controllers that duplicate what the human operator is doing. Here the human operator is considered an expert and one tries to capture their way of doing things in a computer programme such as an expert system. Fuzzy control is a further attempt to duplicate how a human makes decisions given

11.1. EXPERT SYSTEMS

491

vague and qualitative information. Fuzzy control is quite closely related to expert systems, and is described formally in [73] and an application to the nonlinear evaporator is given in chapters 13 and 14 of [145]. Outside regulatory control, expert systems have also been used in: ◦ Tuning industrial PID controllers, (pattern recognition) • Monitoring equipment for faults (diagnosis) • Analysing alarms on complex plants ◦ Designing distributed computer control (DCC) configurations ◦ Qualitative simulation • Prediction, planning and design

Auto-tuners PID controllers are very common on chemical processing plants. However they will only work effectively if they are well tuned. Tuning PID controllers is where one selects the optimum Gain (Kc ), integral time τi and derivative time τd . These 3 variables will be dependent on the process being controlled. Traditionally instrument engineers tuned the PID controllers during start-up, but often never re-tuned them afterwards. Auto-tuners such as the EXACT controller manufactured by Foxboro will re-tune the controller if the operator demands [17, pp445-446]. This means that the controller can be frequently retained by inexperienced personnel. The method of tuning is based on analysis of the transient response of the closed loop system to changes in setpoint and load. It uses the methods of Ziegler-Nichols. Heuristic logic is used to detect if a proper disturbance has occurred and when the peaks subsequently occur. Hence the Expert system. This system has been widely accepted in industry.

Fault diagnosis Expert systems are ideal for fault diagnosis. Here one constructs a fault tree which is some type of conditions connected by branches. Given a fault such as a high exit temperature, you can trace back through the tree and find the cause such as a pump failure. Unfortunately these trees can get rather large very quickly, so some heuristic rules must be employed to reduce the scope of the tree. Also most people will ignore events that have a low probability associated with them (asteroids hitting the distillation column for example).

Alarm system analysis Related to fault diagnosis is alarm analysis. In a large chemical plant, there may be thousands of variables and hundreds of controllers. If each controller has two alarms (high & low) associated with it, then there will also be hundreds of possible alarms. Often one alarm will trigger other alarms which in turn also trigger alarms. Consequently a single fault may generate many different alarms making the control room display light up like a “Christmas tree”. Faced with so many alarms, the operator may find it difficult to evaluate exactly what has happened and what should be done to correct the situation. Experience has shown that typically operators, who otherwise

CHAPTER 11. EXPERT SYSTEMS AND NEURAL NETWORKS

492

know the process better than anybody else, make poor decisions when faced with the emergency situation of so many alarms. Expert systems have been developed to analyse these alarms (what order, which type etc) and to try to deduce what was the crucial initial fault that triggered all the subsequent alarms. Once the programme has established a probable cause, it advises the operator the cause and a suitable remedy. Programmes of this type typically have heuristic rules and plant models built into them. To be useful however, they must generate good answers quickly (within say 5 minutes), and reject the inevitable false alarms.

Qualitative simulation (QSIM) This combines the fields of exact mathematical modelling (simulation) and the heuristic approach of expert systems and is described in [58]. In an emergency situation such as a major plant failure, the human operators want to be able to predict quickly what will happen if they take some particular course of action such as open a valve or shut down a reactor for example. They do not have time or even are interested in exact results, just general trends. QSIM is designed to provide reasonably confident results in the face of uncertainty without having to resort to a time consuming major plant simulation. Essentially QSIM is a method that tries to provided knowledge of the approximate dynamics of the system from incomplete knowledge of the process. Normally everything must be exactly known (or estimated exactly) before any traditional equation solver or dynamic simulator such as those discussed in chapter 3 can begin. This condition is not required for the QSIM algorithm. The QSIM algorithm is a little like a programming language that includes operators, constraints, relations and values. Operators include the familiar mathematical operators such as: MULT(mass,temp,enthalpy) DERIV(enthalpy,heat_flow)

where the first entry can be read as mass∗temperature = enthalpy. Other operatives include qualitative relations such as: M+(temp,press) M-(press,vol)

The first qualitative relation says that pressure increases with temperature for a particular process. Nothing is said about how much increase or does it give particular values. The second relation says that volume decreases with pressure in some unspecified manner. These style of relations incorporate uncertainty and cannot be duplicated in normal simulation computer programmes. Values can equal landmark values such as −∞, 0, +∞ or somewhere in between. Values can also be increasing or decreasing. If a temperature (in Kelvin) is decreasing, then the qualitative state will be T = ((0,+∞),dec). Dynamic modelling is possible with QSIM just as with conventional quantitative simulation but for QSIM the output results are now not numerical values, but qualitative states.

Difficulties of QSIM • Most implementations today take more computer time than an equivalent numerical solution.

11.2. NEURAL NETWORKS

493

• Only very simple cases are described. • Problems arise when two numbers close in magnitude are subtracted since now the sign of the result is unknown! This causes big ambiguities in the result. Problem 11.1 Tuning PID controllers in industrial conditions is somewhat of an art. Construct a rule-based expert system to aid a control engineer to tune a PID controller. 1. Write down a list of rules that you would use in your expert system. You should incorporate heuristics and mathematical calculations in this rule base. You may wish to add a classifier to judge what type of response you get, (non-minimum phase, oscillatory, excessive dead time etc). 2. Structure the rules so the most important ones are searched first. Draw a diagram of the logic tree and show an example for a typical case. What happens if you have an open loop unstable process, or a process that is difficult to control? 3. What sort of diagnostics and explanation facilities would you incorporate in your expert system?

11.2 Neural networks “We’ve replaced the bad cybernetic brain that went berserk and tore people limb-from-limb with a good one that does not.” ©1994 David Farley

Accompanying expert systems, the other popular development in the research in artificial intelligence with relevance for process control is Artificial Neural Networks or ANN. Artificial neural networks are computer programs that attempt to duplicate how the brain works, albeit at a very limited level, by simulating the highly interconnected biological neurons. The relation between the biological brain and even the most complex computer programs is really quite weak, and nowadays most people do not expect that current ANNs will ever convincingly duplicate a human’s cognitive ability. However ANNs do represent a novel and refreshing way of solving certain types of problems. Neural networks are also referred to as connectionist models, parallel distributed models, or neuromorphic systems. Of course, any program that claims to duplicate the brain’s working, must do at a very crude level and this is certainly the case for ANN. Both the artificial and biological neural networks are composed of simple elements called neurons that are joined together in a particular topology or

494

CHAPTER 11. EXPERT SYSTEMS AND NEURAL NETWORKS

network. The connections between neurons are referred to as dendrites, and the inputs and outputs are called axons. However in the case of the artificial neural network, the size and topology of the network is much much simpler than those even in an ant’s biological brain. We will not be concerned further with biological neural networks, so henceforth I will simply refer to ANN as neural networks with the artificial term implied. The neural network attempts to model complex behaviour with a dense interconnection of simple computational elements, hence the descriptive term connectionist models referred to above, and the obvious parallelising of the computation. Table 11.1 compares the characteristics between expert systems and neural networks. The M ATLAB neural network toolbox, [59] supplies tools and gives a methodology for elegantly simulating neural networks within the matrix framework. There are many introductory texts explaining neural networks, [154] is just one. Table 11.1: A comparison of characteristics between expert systems and artificial neural networks

Neural Networks example based domain free finds rules easy to program & maintain needs database adaptive time consuming

Expert systems rule based domain specific needs rules supplied hard to program & maintain needs human expert needs re-programming generally quicker

It is clear by now, that successful advanced control for chemical processes hinges on the development of accurate suitable models, and that these models are expensive and time consuming to develop and verify. Neural networks are interesting because they can be made to model complex nonlinear systems with very little attention paid to the underlying structure of the model. In this sense, ‘one size fits all’, which has its obvious advantages when one is trying to model complex behaviour for which no feasible mechanism is known. If ANN are to be useful for control problems we must compared their performance to more classical and traditional techniques such as model based control, adaptive control and so forth. We should carefully look at the quality of the model/plant matching, the efficiency of parameter use, online and offline computer usage and ease of tuning and configuration. [141, p151] cite some additional issues such as the high degree of parallelisation exhibited by neural networks ensures a certain fault tolerancy, and speed of operation if the hardware is optimised for the task. One of the most successful areas of application of ANN is the fusion between symbolic information such as that used by an Expert System and a deterministic model. By combining both sources of information, one would naturally expect an improved result. As a final caution consider carefully the following quote by the computer scientist A. K. Dewdney in his expose of bad science, Yes, We Have No Neurons. “As computer recreations columnist for a number Of years with Scientific American magazine, I had ample opportunity to review the literature on neural nets and may have unwittingly helped to spark the revolution by writing more than one article on the subject. Only now may I say what I never could in the column: The appearance of an idea in Scientific American does not automatically make it the coming thing. The number of people who seemed unable to spot the word “recreations” in my column was truly frightening. Although neural nets do solve a few toy problems, their powers of computation are so limited that I am surprised anyone takes them seriously as a general problem solving tool. Most computer scientists who work in the field known as computational complexity understand this very well.

11.2. NEURAL NETWORKS

(a) Hard limit

495

(b) Linear with possible saturation

output

(c) Nonlinear

output

6

output

6 input

6 input

log-sig

input

tanh(x)

Figure 11.1: Possible neuron activation functions. Neural nets have already entered the long, slow decline predicted by Irving Langmuir (see the end of chapter 1) for all bad science-or for that matter, technology.”

11.2.1 The architecture of the neural network Neural networks have three basic characteristics; their architecture or how the neurons are connected to each other, the type of processing element in the individual neuron and the training rule used to initialise the network.

The neuron model The neuron is a very simple element that takes as input a value p, multiplies this by a weight w, and then passes this weighted input to a transfer or activation function f (). There are a variety of possible transfer functions and some are given in Fig. 11.1. The simplest transfer (or activation) function is a binary switch;- either it fires or it does not (see Fig. 11.1 (a)). This is at the heart of the perceptron, but it is limited as to what behaviour it can model. A more flexible transfer function is a linear transfer function, although in practice the output may be constrained by limits (see Fig. 11.1b) but it is the nonlinear activation functions, (see Fig. 11.1c) that give the neural network the most power to model interesting and nonlinear relations. The two most common nonlinear activation functions are the hyperbolic tangent, y = tanh(x), and the log sigmoidal, y=

1 . 1 + exp(−x)

(11.1)

(11.2)

Both of these are sigmoidal or “S” shaped curves that are bounded both above and below and are continuously differentiable.

Multiple neurons in layers There are two obvious extensions to the single neuron example given above. First we can deal with multiple inputs to the single neuron. In this case, the inputs are individually scaled by a

CHAPTER 11. EXPERT SYSTEMS AND NEURAL NETWORKS

496

weight, w, and then summed to form a single input to the activation function in the same manner as before as shown in Fig. 11.2. Suppose we have N inputs and corresponding weights, then the output of the neuron y is ! N X (11.3) wi pi + w0 y=f i=1

where w0 is a bias weight. Bias weights have an implied input of 1 and are used to enable the neuron model to give a nonzero output for a zero input. This adds flexibility to the neuron model. synaptic connections

inputs

-w1

            

nonlinear function -w2

           

- .. . -wL

1

s P z : 3

si -

- output, yi

activation function f (·) single neuron

-w0

bias weighted summer

Figure 11.2: A single neural processing unit with multiple inputs If we duplicate the single neuron given in Fig. 11.2, we can build up a one layer feed-forward neural network. Fig. 11.3 shows the topology for a single layer neural network with L inputs and N outputs or neurons. The weight wij is the weight from the jth input to the ith neuron. Given this multivariable structure, a convenient computational molecule employed by the Neural Network toolbox is to use a vector/matrix version of Eqn. 11.3, y = f (Wx)

(11.4)

where y is a N × 1 vector of outputs, x is a L vector of inputs, and W is a N × L matrix of weights,   w11 w21 · · · w1L  w21 w22 · · · w2L    W= . .. ..  ..  .. . . .  wN 1 wN 1 · · · wN L The neural network is comprised of two mappings, the Wx linear transformation, and the nonlinear f (·).

The second extension is to feed the output of one neuron into the input of another. This layering of neurons forms network part of the neural network as shown in Fig. 11.4. Organising the

11.2. NEURAL NETWORKS

L inputs

                            

497

w11

x1

w21 w12 x2 .. .

-1 * 7

- y1

j -2 >

- y2

wN 2

.. .

w1L w2L

xL

wN L

~ wN

- yN

              

N outputs

             

Figure 11.3: Single layer feedforward neural network

neurons in layers allows the technique far more flexibility to model things than before. Most neural networks in practice have sigmoidal processing elements, are arranged in layers with at least one center or hidden layer and have at least one bias input.

output

input -

s 3  sU *

*  j 3 U s

-

hidden layer - information flow

-

Figure 11.4: A 3 layer fully interconnected feedforward neural network

Layering the neurons gives a great deal of flexibility in what can be approximated by the network. In fact one can prove using the Stone-Weierstrass theorem that just a two layer network is sufficient to model any continuous function. Unfortunately this theorem does not tell us how many neurons we need, and it should be mentioned that simple polynomials or other orthogonal expansions can also approximate to arbitrary accuracy any continuous function, although again the theorem is silent regarding how many coefficients are required. (See for example [104, p289].) So two main design problems remain; how many layers we should use, and how many nodes in each layer. Naturally we wish to minimise the number of parameters to search for, but still obtain a reasonable result.

CHAPTER 11. EXPERT SYSTEMS AND NEURAL NETWORKS

498 Recurrent networks

In the network structure given in Fig. 11.4, the information travels from left to right, analogous to an open loop process producing an output given an input. These are called statical networks. However for the analysis of dynamic models, it is natural to use a neural network structure with a feedback through a unit time delay duplicating the nonlinear discrete time model, xk+1 = f (xk ). Fig. 11.5 shows a neural network suitable for an autonomous (no input) dynamic system. The outputs are delayed one sample time and then fed back to the inputs.

unit delays z −1  z −1  z −1  *  j * jR -

x1 (0) x2 (0) xN (0) |

{z } initial conditions

|

{z

1 2 N }

-y1 -y2 -yN

feedforward part

Figure 11.5: Single layer network with feedback

Other possibilities include using a two layered network with a delays between the layers, or feeding only some of the states back. Adding provision for a control signal is simply a matter of adding another node in the first layer joined to the input at time k.

Training or regressing the weights Once we have decided on a network structure, (number of hidden layers, number of neurons in each layer etc), and have decided on the type of neuron, (sigmoid, linear etc), then we must calculate appropriate values for the weights between the neurons. In essence this is a nonlinear regression problem, where inputs and known outputs are presented to the network in a supervised learning mode. The weights are adjusted by the optimiser so that the network duplicates the correct answers. Once the network can do this, and the weights have converged, it may be able to extrapolate and produce reasonable answers to inputs that it had not seen previously.

11.2. NEURAL NETWORKS

499

11.2.2 Curve fitting using neural networks Fitting functions to data is a classic engineering pastime. When faced with some data say such as given in Fig. 11.6, our first, and often hardest choice, is to decide what is an appropriate underlying structure for the function that stands some chance of going through the data. This is where strategies that make minimal demands on any a priori information such as neural networks have advantages. 3 2 1 0 −1 −2 data Initial NN fit

−3 −4 −2

−1

0

1

2

Figure 11.6: An input/output data series ◦ and initial trial fit (solid) to be approximated using a neural network. The initial fit was obtained by randomly setting the neuralnetwork weights.

We are going to make use of the neural network characteristic of ‘one size fits all’ mentioned above, in that we will not actually pay much attention to the structure of the model to which we will regress. To speed up the prototyping, I am going to use the Neural Network toolbox for M ATLAB, but constructing this example from scratch is also very simple. I will also closely follow the example for curve fitting from the NN toolbox manual. Traditionally to select a model structure for curve fitting, I by looking at the data, would choose some sort of growing exponential sinusoidal family with say 3–6 parameters and then use a nonlinear regression package. However in this case we avoid the problem specific model selection step and just to be different, will use neural networks. It this advantage, that of eliminating the requirement to select a model structure that is why neural networks are currently so popular. We will search for the values of the weights inside the neural network (also termed parameters) such that our neural network approximates the unknown function. We will use a crude, but effective optimisation technique to search for these weights called back propagation. Searching for the optimal neural network weights is termed training the network, but in reality it is simply a nonlinear regression problem.

How many neurons and in what structure? It turns out that we can, at least in principle, fit any function with a finite neural network with only two layers, the first a nonlinear layer, and the output, a linear layer. Unfortunately, this result does not tell us how many neurons are required for a given accuracy specification, so it is not much use in practice. Hence we will use a three layer network (two hidden which are nonlinear, and one linear output). Current thinking is that if the network is too large, it will not be able to generalise very well, despite the good performance on the training runs. I will use the hyperbolic tangent activation function, (see Fig. 11.1c), for the nonlinear neurons. We are already constrained by the number of input and output neurons, that is given by the

500

CHAPTER 11. EXPERT SYSTEMS AND NEURAL NETWORKS

problem. In our case we have 1 input (the independent variable) and 1 output (the dependent variable). However we do have to choose how many neurons we want in our two hidden layers. Too many neurons take too much memory, and can over-fit the data. Too few may never fit the data to the desired level of accuracy. I will choose 10 neurons for each of the hidden layers. The M ATLAB code in Listing 11.1 first generates some arbitrary data to be fitted and initialises the neural network with random weights. Listing 11.1: Generate some arbitrary data to be used for subsequent fitting x = linspace(-2,2,20); % Note: row vector for input F = @(x) 1./(1+2*x.ˆ2).*cos(3*(x-2)); % create "unknown" Target function to fit! y=F(x); 4

xi = linspace(x(1), x(end),50); % Interpolating input vector validate

9

14

% Now create Network Skeleton [R,Q] = size(x); % dimension of input S1 = 10; S2 = 10;% # of hidden nodes (2 layers) [S3,Q] = size(y);% dim of output % Initialize weights and biases. [W1,B1] = rands(S1,R); % random weights to start [W2,B2] = rands(S2,S1); [W3,B3] = rands(S3,S2); % try out our initial guess plotfa(x,y,xi,purelin(W3*tansig(W2*tansig(W1*xi,B1),B2),B3));

Clearly when using random weights, any fit will be purely fortuitous. More likely as a first estimate, we will see a fit similar to the attempt in Fig. 11.6. However hopefully once we have optimised the network weights the fit will improve. Now we are ready to train the network using the back-propagation algorithm. We specify a maximum of 2000 iterations, and a final error allowance of 10−3 . There is scope for many more tuning parameters just for the optimiser, and these are specified in the following code. The algorithm should work without them, but it will be much less efficient. We will use the supplied trainbpx m-file to perform this optimisation.

3

8

disp_freq = 500; % plotting frequency max_epoch = 20000; % maximum allowable iterations err_goal = 1.0e-3;% termination error lr = 0.01; % learning rate TP = [disp_freq max_epoch err_goal lr]; % adaptive learning rate add-ons lr_incr=1.01; % learn rate increase lr_decr=0.99; % decrease momentum = 0.9;% low pass filter (sort of) err_r = 1.04; TPx = [TP,lr_incr, lr_decr, momentum, err_r];

13

% Now do the training by accelerated back-prop. [W1x,B1x,W2x,B2x,W3x,B3x,epoch,errors] = ... trainbpx(W1,B1,'tansig',W2,B2,'tansig',W3,B3,'purelin',x,y,TPx); 18

% finally when finished plot the best approximated curve

11.2. NEURAL NETWORKS

501

plotfa(x,y,xi,purelin(W3x*tansig(W2x*tansig(W1x*xi,B1x),B2x),B3x));

If you have tried the above, you will have learned the first important feature of neural networks — they are not very computationally efficient! The result of my best fit is given in Fig. 11.7. The fit is good considering we are using 140 parameters! Just for comparison, the dashed line in Fig. 11.7 shows the fit only using 3 neurons in the hidden layers or 9 fitted parameters. 1.2 1 0.8

data NN

10,10

fit

NN

2,1

0.6 0.4 0.2 0 −0.2 −0.4 −2

−1

0

1

2

Figure 11.7: An unknown input/output function approximated using a neural network with two hidden layers of 10 neurons each with 140 fitted parameters, (solid) and (2,1) neurons in the two hidden layers with 9 parameters, (dashed). Both optimisers were constrained to 2000 iterations.

Actually one must be weary of comparisons such as these since in both cases the optimiser “timed out” by exceeding the maximum allowed number of iterations rather than actually finding the appropriate minimum. On the other hand however, I do not have time to waste! For the case with 5 neurons in the hidden layers, a good fit is obtained with 16,000 iterations.

Predicting the tides The high and low tides in Auckland habour (36◦ 50′ 39′′ S, 174◦ 46′ 6′′ E) is shown in Fig. 11.8(a) over 4 months.1 Note that this time series only shows the extreme values of the data, and it is evident from the plot that Auckland experiences what is known as semi-diurnal tides but with a noticeable mixed component. That is, Auckland has two low tides and two high tides each day, but one of the tides is larger than the other. Recreational boaters need to know the tides, and it is interesting to try and fit a function to this data. In fact this is quite a challenge because there are really 4 curves in Fig. 11.8(a). Suppose to make the problem easier, we just take one of the high tides, and use this as a test case for fitting a neural network function. Fig. 11.8(b) shows the result of fitting a large neural-network with 2 layers of 30 neurons in each. Note that the last month of data was withheld from the neural network and gives an indication of the quality if the extrapolation that we can expect. Not too good I’m afraid. Problem 11.2 1. Repeat the curve fitting using a neural network with only one hidden layer. Investigate the effect of varying the number of hidden neurons. 2. Fit the data given in Fig. 11.6 using the conventional nonlinear least squares optimisation. (The optimisation toolbox procedure fminu may be useful.) You will need to select an appropriate model and suitable initial parameters. How does this compare to the neural network approach in terms of computational effort required, user understanding, robustness etc? 1 This

data was obtained from http://www.niwascience.co.nz/services/tides.

CHAPTER 11. EXPERT SYSTEMS AND NEURAL NETWORKS

502 2

Height of High & Low tides

1.5 1 0.5 0

Mean Sea Level

−0.5 −1 −1.5 −2 May

Jun

Jul

Aug

Sep

Oct

Date

(a) The high and low tides in Auckland harbour over 4 months. 2

Height of High tides

1.8

data Final NN fit

1.6 1.4 1.2 1 Validation 0.8 May

Jun

Jul

Aug

Sep

Oct

Date

(b) High tide predictions. Note that the September data was not used for the curve fitting, and is used to validate the fit.

Figure 11.8: Fitting a neural network function to tide data Some preliminary cautions A very short readable criticism of the whole neural network idea is given by Ponton, [160]. Ponton makes the point that there is nothing particularly special about neural networks, and that often fitting a known nonlinear model will probably work just as well, if not better. Ponton also asserts that a neural network function does not generally correspond to physical reality, and in general the network output cannot be extrapolated beyond the domain used to train (or in other words, fit) the network parameters. Ponton advises that one can use a neural network when nothing is known about a particular relationship except that it is nonlinear. In many engineering applications however, something is known (or at least partially known), and that this information is useful in the model. This approach is known as using the a priori knowledge available. Ponton ends his short critique of neural networks with the following two statements found from experience: • A simpler arbitrary function can probably be found to perform just as well as a ANN, and • a model incorporating almost any engineering or scientific knowledge will do much better. In a similar manner, the September 1990 issue of B YTE magazine published a dialogue from a discussion of experts in the field of artificial intelligence. B YTE asked these experts “Why have we failed to come up with real AI?” The replies ranged from It’s an extremely hard problem (Danny Hillis) to AI started to work on robotics and expert systems, which were very easy in comparison to really understanding intelligent behaviour and learning at the early stages (Nicholas Negroponte) to the

11.3. SUMMARY

503

dramatic The computation power required . . . is enormous (Federico Faggin), to At a very fundamental level, we do not know how the brain works (Dick Shaffer). Remember some of these concerns when next investigating the claims of new expert systems and artificial intelligence.

11.3 Summary Expert systems have been around for about 25 years and have been popular for about the last 10 years. They represent a major departure from the traditional way of using computers as that of a precise exact machine solving engineering problems exactly to solving more vague problems that require concepts that humans have traditionally been better then computers at. With this new technology has arrived new programming languages and new computer architectures. Expert systems in the process control field is still in its infancy, and has had mixed success. Expert systems are often applied to control problems that are traditionally control ‘hard’ such as the control of cement kilns and pulp digestors. These applications are characterised by complicated physiochemical phenomena with scarce reliable online measurements. Notwithstanding, human operators do manage to operate these plants, so one predicts there is scope for an expert system. Usually the expert system is configured to operate in an advisory mode which the operator can override. Installation costs are high hence they tend to be used only for projects that show a large potential pay back. Recently there has been some published disillusioned analysis of expert systems, and many researches abandoned the field moving to the now more popular neural network field. Whether this currently popular ship will also capsize in the near future makes interesting speculation. Like expert systems, neural networks have also been around for 25 years or more, and is only now gaining interest in the general engineering community. The neural network is the quintessential black-box model, that hopefully after it has been trained on some data, can make useful predictions with similar, but slightly different data. The training of the network, or alternatively the regression of the network weights is a time consuming, expensive nonlinear optimisation problem, but needs to be done only once offline. The actual operation of the neural network once trained, is trivial.

504

CHAPTER 11. EXPERT SYSTEMS AND NEURAL NETWORKS

Appendix A

List of symbols S YMBOL

D ESCRIPTION

U NITS

t T, ∆t τ K ζ δ(·) f (t) f ∗ (T ) L(·) Z(·) s z q −1 ω f V(x) P, Q J num den

time sample time time constant Gain shape factor Dirac delta function function of time sampled function f (T ) Laplace transform z transform Laplace variable z transform variable backward shift operator radial velocity frequency scalar Lyapunov function positive definite matrices Jacobian matrix numerator denominator

s s s radians/s Hz -

M F ρ h A ∆P T H I cp ∆T Q, q J θ Λ

mass material flow density height cross sectional area pressure differential temperature Enthalpy current heat capacity temperature differential heat loss (gain) moment of inertia angle relative gain matrix

kg kg/s kg/m3 m m2 kPa K,◦ C kJ mA kJ/kg.K K kJ/s radians -

u ǫ τi τd Kc Ku

manipulated variable error integral time derivative time proportional gain ultimate gain

s s -

505

ωu Pu ωm γ, α d, θ P Φ W

ultimate frequency ultimate period phase margin actual PID parameters dead time period signal power weight

rad/s s s samples, s s

M S θ ǫ t1−α/2 cov(·) C K P I λ f E{·}

model system vector of parameters error vector t-statistic co-variance past input/output data gain matrix co-variance matrix identity matrix forgetting factor factor expected value

-

∆t x u y d A B D C Φ ∆ Γ θ β z Co Ob K L

sample time s state vector n×1 input vector m×1 output vector r×1 disturbance vector p×1 system matrix n×n control matrix n×m disturbance matrix n×p measurement matrix r×n transition matrix n×n discrete control matrix n×m discrete disturbance matrix n × p time delay s # whole samples delay augmented state vector controllability matrix observability matrix controller gain observer gain -

J,j Q, R

performance index weighting matrices

kg

≈4

$ -

APPENDIX A. LIST OF SYMBOLS

506 x ¯ σx λ, ϕ H φ

mean of x standard deviation of x Lagrange multipliers Hamiltonian termination criteria

S UBSCRIPTS D ESCRIPTION N u,l ss

Nyquist upper & lower steady-state

S UPERSCRIPTS D ESCRIPTION x ˆ x ¯ x⋆

estimate (of x) mean (of x) desired value (of x)

-

Appendix B

Useful utility functions in Matlab The routine in Listing B.1 adds two or more polynomials of possibly differing lengths. The resultant polynomial order is the same as the maximum order of the input polynomials. Note that this routine pads with zeros to the left so that all the polynomials are of the same size. It assumed (but not checked) that the polynomials are row vectors in descending order. Listing B.1: Polynomial addition. 1

6

11

function R = polyadd(A,varargin) % Adds two or more row vectors of possibly differing lengths. % R(x) = A(x) + B(x) + C(x) + · · · . np = length(varargin); nmax = length(A); for i=1:np % find maximum order in the input argument list nmax = max(nmax,length(varargin{i})); end % if R = [zeros(1,nmax-length(A)),A]; for i=1:np varargin{i} = [zeros(1,nmax - length(varargin{i}),1), varargin{i}]; R = R+varargin{i}; end % if return

This routine is useful for checking the results of a Diophantine solution, A(x)R(x) + B(x)S(x) = T (x). Tc = polyadd(conv(A,R),conv(B,S)) The routine in Listing B.2 convolves or multiplies two or more polynomials. Unlike polynomial addition, we do not need to ensure that all the polynomials are of the same length. Listing B.2: Multiple convolution. 2

7

function y = mconv(a,varargin) % Multiple convolution of polynomial vectors % R(x) = A(x)B(x)C(x) · · · . % Would be faster to do “divide & conquer”, and lots of smaller first. if nargin < 2 error('Need two or more arguments') end % if

507

508

12

APPENDIX B. USEFUL UTILITY FUNCTIONS IN MATLAB

y = conv(a,varargin{1}); % do the first pair for i=2:nargin-1 % now do any remaining y = conv(y,varargin{i}); end return

Listing B.3 strips the leading zeros from a row polynomial, and optionally returns the number of zeros stripped which may, depending on the application, be the deadtime. Listing B.3: Strip leading zeros from a polynomial. 2

7

function [Br,i] = stripleadzeros(B) % Strip the leading zeros from a (vector) polynomial & return deadtime (# of leading zeros) % [Br,i] = stripleadzeros(B) for i=0:length(B)-1 if B(i+1) % if Bi 6= 0 Br = B(i+1:end); return % jump out of routine end end % for return

Appendix C

Transform pairs

time function f (t) unit step

1

impulse

δ(t) t

unit ramp

t2 tn e−at te−at (1 − at)e−at sin(at) cos(at) − e−at a−b e−bt sin(−at) e

−bt

e−bt cos(−at) ae−bt − be−at 1 + ab ab(b − a)

Laplace transform F (s) 1 s 1 1 s2 2 s3 n! sn+1 1 s+a 1 (s + a)2 s (s + a)2 a s2 + a2 s s2 + a2 1 (s + a)(s + b) a (s + b)2 + a2 s+b (s + b)2 + a2 1 s(s + a)(s + b)

509

z-transform Z z z−1 Tz (z − 1)2 T 2 z(z + 1) 2(z − 1)3 z z − eaT T zeaT (z − eaT )2 z sin(aT ) z 2 − 2z cos(aT ) + 1

510

APPENDIX C. TRANSFORM PAIRS

Appendix D

A comparison of Maple and MuPad Much of the functionality of the symbolic manipulator M APLE, www.maplesoft.com is duplicated in the freeware alternative M U PAD, www.sciface.com. Below both packages are demonstrated in parallel.

D.1 Partial fractions Suppose we want to decompose G(s) =

s3 + s2 + 1 s2 (s2 − 1)

into partial fractions. MuPad uses the partfrac command. Maple uses the parfrac option in the convert command. partfrac((sˆ3+sˆ2+1)/(sˆ2*(sˆ2-1))); > G := (sˆ3+sˆ2+1)/(sˆ2*(sˆ2-1)): > convert(G,parfrac,s);



1 3 1 1 1 + − 2 s 2s−1 2s+1

3 1 1 --------- - -- - --------2 (s - 1) 2 2 (s + 1) s Note the different spelling!

D.2 Integral transforms First we must load the relevant package to do integral transforms. Maple In this case for integral transforms. >with(inttrans):

MuPad In this case Laplace, Fourier, z and Mellin transforms. export(transform);

Now we find a Laplace transform of a common function, L{sin(at)} 511

APPENDIX D. A COMPARISON OF MAPLE AND MUPAD

512

laplace(sin(a*t),t,s);

laplace(sin(a*t),t,s);

a ------2 2 a + s

a 2 a + s2 The inverse Laplace transform of L−1 {K/(s2 + s + 1)}

ilaplace(K/(sˆ2+s+1),s,t); invlaplace(K/(sˆ2+s+1),s,t);

/ 1/2 \ / t \ | t 3 | 2 K 3 exp| - - | sin| ------ | \ 2 / \ 2 / --------------------------------3 1/2

 √ 1 1 −1 √  ((− 12 + 21 √−3)t) K −3 e − e((− 2 − 2 −3)t) 3

We can try a Laplace transform the ‘hard way’ following the mathematical definition (without using the integral transform packages), Z ∞

def

L{sin(at)} =

sin(at) e−st dt

0

f := cos(a*t): int(f*exp(-s*t),t=0..infinity); However M APLE returns a solution accompanied with a warning: Definite integration: Can’t determine if the integral is convergent. Need to know the sign of --> x Will now try indefinite integration and then take limits.

−se−st cos(at) + ae−st sin(at) + s t→∞ s2 + a2 lim

MuPad, however, has no resevations. f := cos(a*t): int(f*exp(-s*t),t=0..infinity); s ------2 2 a + s

> assume(s,positive); > simplify(%); s s2 + a2

D.3 Differential equations Find the solution to the linear ordinary differential equation with initial conditions 3

dx dx + + x = 4e−t , dt dt

x(0) = 1,

dx (0) = 2 dt

In M APLE we use the dsolve command to solve differential equations. >ode2 := 3*diff(x(t),t,t) + diff(x(t),t)+x(t)=4*exp(-t);

D.4. VECTORS AND MATRICES

ode2 := 3

513 

   ∂2 ∂ x(t) + x(t) + x(t) = 4e−t ∂t2 ∂t

>dsolve({ode2,x(0)=1,D(x)(0)=2},x(t));

1 1 4 x(t) = e−t − e− 6 t cos 3 3



   √ 59 − 1 t 1√ 1√ 6 sin 11t + e 11t 11 6 33 6

In M U PAD we construct an ‘ode’ object group and use the normal solve command. >eqn := ode({3*x’’(t) + x’(t) + x(t)=4*exp(-t),x(0)=1, D(x)(0)=2},x(t)); ode({D(x)(0) = 2, x(0) = 1, x(t) + diff(x(t), t) + 3 diff(x(t), t, t) = 4 exp(-t)}, x(t)) >solve(eqn); { / 1/2 \ / 1/2 \ { / t \ | t 11 | 1/2 / t \ | t 11 | { exp| - - | cos| ------- | 59 11 exp| - - | sin| ------- | { 4 \ 6 / \ 6 / \ 6 / \ 6 / { -------- - ------------------------- + ---------------------------------{ 3 exp(t) 3 33

D.4 Vectors and matrices To manipulate vectors and matrices in M U PAD, we must load the linear algebra package. info(linalg): which returns a list of functions available in the linear algebra package. We start by defining the domain of the matrices we are dealing with. In our case we will stick with the default and call that domain type M: M := Dom::Matrix(); Dom::Matrix(Dom::ExpressionField(id, iszero)) Now we are ready to input a test matrix, A, and perform some arithmetic operations such as addition, inverse, matrix exponentiation. A:=M([[1,3],[4, 5]]); +-+ | 1, 3 | | | | 4, 5 |

} } } } } }

APPENDIX D. A COMPARISON OF MAPLE AND MUPAD

514

+-

-+

A+A; +-+ | 2, 6 | | | | 8, 10 | +-+ exp(A,T); +| 3 exp(-T) exp(7 T) 3 exp(-T) 3 exp(7 T) | --------- + --------, - --------- + ---------| 4 4 8 8 | | exp(-T) exp(7 T) exp(-T) 3 exp(7 T) | - ------- + -------- , ------- + ---------| 2 2 4 4 +-

-+ | | | | | | | -+

Of course we could involve variables in the matrix, and perform further manipulations A:=M([[1,3],[4, x]]); +-+ | 1, 3 | | | | 4, x | +-+ A+Aˆ(-1); +| 12 3 | ------ + 2, - ------ + 3 | x - 12 x - 12 | | 4 1 | - ------ + 4 , x + -----| x - 12 x - 12 +-

-+ | | | | | | | -+

linalg::eigenValues(A); { 2 1/2 2 1/2 } { x (x - 2 x + 49) x (x - 2 x + 49) } { - + ------------------ + 1/2, - - ------------------ + 1/2 } { 2 2 2 2 }

Appendix E

Useful test models The following are a collection of multivariable models in state-space format which can be used to test control and estimation algorithms.

E.1 A forced circulation evaporator The linearised forced circulation evaporator developed in [145, chapter 2] and mentioned in §3.3.2 in continuous state-space form, x˙ = Ax + Bu, is

 0 0.10455 0.37935  −0.1 0 A= 0 0 −1.034 · 10−2 −5.4738 · 10−2  −0.1 −0.37266 0 0 0 B =  −0.1 0 3.6914 · 10−2 −7.5272 · 10−3 

(E.1) 0.36676 0 3.6302 · 10−2

0.38605 0.1 3.2268 · 10−3

0 0.1 0

−3.636 · 10−2 0 3.5972 · 10−3

T200

iT

 0  0 1.7785 · 10−2 (E.2)

with state and input variables defined as in Table 3.3,

x= u=



h

L2 F2

P2 P100

x2

T

(E.3)

F200

.. .

F3

F1

x1

T1

(E.4)

In this case we assume that the concentration cannot be measured online, so the output equation is

y=



1 0 0 1 515

0 0



x

(E.5)

APPENDIX E. USEFUL TEST MODELS

516

E.2 Aircraft model The following model is of an aircraft reported in [61, p31]. The state model is    0 0 1.132 0 −1 0  0 −0.0538 −0.1712   −0.12 0 0.0705     0 0 1 0  A=  0 , B =  0  0   4.419 0.0485 0 −0.8556 −1.013 0 −0.2909 0 1.0532 −0.6859 1.575   1 0 0 0 0 C= 0 1 0 0 0  0 0 1 0 0

0 1 0 0 0

0 0 0 −1.665 −0.0732

     

where the aircraft states & control inputs are defined as:

state x1 x2 x3 x4 x5 u1 u2 u3

description altitude forward velocity pitch angle pitch rate, x˙3 vertical speed spoiler angle forward acceleration elevator angle

units m m/s degrees deg/s m/s deg/10 m/s2 deg

measured yes yes yes no no

Note that we only measure altitude, velocity and pitch angle, we do not measure the rate states. A reasonable initial condition is x0 =



10 100 −15 1 25

⊤

.

(E.6)

(E.7)

Bibliography [1] J. Abate and P.P. Valko. ´ Multi-precision Laplace transform inversion. International Journal for Numerical Methods in Engineering, 60:979–993, 2004. 32

˚ om [13] Karl J. Astr ¨ and Tore H¨agglund. Advanced PID Control. ISA, Research Triangle Park, NC, USA, 2006. 132

[2] James L. Adams. Flying Buttresses, Entropy, and Orings: The World of an Engineer. Harvard University Press, 1991. 4

˚ om. [14] Karl-Johan Astr ¨ Introduction to stochastic control theory. Academic press, 1970. 322

[3] Advantech Co. Ltd. PC-Multilab Card User’s Manual, 1992. 14 ˚ [4] Johan Akesson. MPCtools: A toolbox for simulation of MPC controllers in Matlab. Technical report, Lund Institute of Technology, Lund, Sweden, January 2006. 478

˚ om [15] Karl-Johan Astr ¨ and Tore H¨agglund. Automatic tuning of PID controllers. Instrument Society of America, Research triangle park, NC, 1988. 132, 141, 155, 166, 167, 321 ˚ om [16] Karl-Johan Astr ¨ and Tore H¨agglund. Revisiting the Ziegler-Nichols step response method for PID control. Journal of Process Control, 14:635–650, 2004. 152

[5] Brian D.O. Anderson and John B. Moore. Optimal Filtering. Information and System Sciences. Prentice-Hall, 1979. 452, 454

˚ om [17] Karl-Johan Astr ¨ and Bjorn ¨ Wittenmark. Adaptive control. Addision–Wesley, 1989. 5, 306, 308, 491

[6] Jim Anderson, Ton Backx, Joost Van Loon, and Myke King. Getting the most from Advanced Process Control. Chemical Engineering, pages 78–89, March 1994. 5

˚ om [18] Karl-Johan Astr ¨ and Bjorn ¨ Wittenmark. Adaptive Control. Addision–Wesley, 2 edition, 1995. 243, 328, 348

[7] Anon. Experience with the X-15 Adaptive Flight Control System. Technical Report NASA TN D6208, NASA Flight Research Centre, Edwards, California, Washington, D.C., March 1971. 317 ˚ en. Realisation of expert system based feed[8] K-E Arz´ back control. PhD thesis, Department of Automatic control, Lund Institute of Technology, Lund, Sweden, 1987. 148 ˚ om. [9] K. J. Astr ¨ Computer Control of a Paper Machine – an Application of Linear Stochastic Control Theory. IBM Journal of Research and Development, 11(4):389–405, 1967. 322 [10] K. J. Astrom. Maximum likelihood and prediction error methods. Automatica, 16:551–574, 1980. 280 ˚ om. [11] K. J. Astr ¨ Ziegler–Nichols Auto-tuners. Technical Report LUTFD2/(TFRT–3167) /01–025/, Lund University, Lund, Sweden, 1982. 169, 173, 456 ˚ om [12] K. J. Astr ¨ and B. Wittenmark. On Self Tuning Regulators. Automatica, 9:185–199, 1973. 322

517

˚ om [19] Karl-Johan Astr ¨ and Bjorn ¨ Wittenmark. Computer-Controlled Systems: Theory and Design. Prentice–Hall, 3 edition, 1997. 61, 141, 357, 367 ˚ om [20] K.J. Astr ¨ and R.D. Bell. Drum-boiler dynamics. Automatica, 36(3):363–378, 2000. 181 [21] K.J. Astrom ¨ and B. Wittenmark. Adaptive Control. Addison–Wesley, 1989. 326 ˚ om [22] K.J. Astr ¨ and B. Wittenmark. Computer Controlled Systems: Theory and Design. Prentice–Hall, 2 edition, 1990. 310, 341, 344, 352 [23] Yonathan Bard. Nonlinear parameter estimation. Academic Press, 1974. 276 [24] R.A. Bartlett, A. W¨achter, and L. T. Biegler. Active set vs. interior point strategies for model predictive control. In Proceedings of the American Control Conference, pages 4229–4233, Chicago, Illinois, USA, 2000. 467 [25] B. Bellingham and F.P. Lees. The detection of malfunction using a process control computer: A Kalman filtering technique for general control loops. Trans. IChemE, 55:253–265, 1977. 451

518 [26] Alberto Bemporad, Manfred Morari, and N. Lawrence Ricker. Model Predictive Control Toolbox. The MathWorks Inc., 2006. 464 [27] Alberto Bemporad, Manfred Morari, and N. Lawrence Ricker. Model predictive control toolbox 3. Technical report, The Mathworks, 2009. 467, 478 [28] B. Wayne Bequette. Nonlinear control of chemical processes: A review. Ind. Eng. Chem. Res., 30:1391– 1413, 1991. 380 [29] A. Besharati Rad, Wai Lun Lo, and K.M. Tsang. Self-tuning pid controller using newton-raphson search method. Industrial Electronics, IEEE Transactions on, 44(5):717–725, Oct 1997. 155, 256 [30] Torsten Bohlin. A grey-box process identification tool: Theory and practice. Technical Report IRS3-REG-0103, Department of Signals Systems & Sensors, Royal Institute of technology, SE-100 44 Stockholm, Sweden, August 2001. 86 [31] C. Bohn and D.P. Atherton. An Analysis Package Comparing PID Anti-Windup Strategies. IEEE Control Systems, 15:34–40, 1995. 141 [32] G.E.P. Box and G.M. Jenkins. Time Series Analysis: Forecasting and Control. Holden–Day, 1970. 236, 243, 307, 308 [33] M. Braun. Differential Equations and their Applications. Springer–Verlag, 1975. 86, 120 [34] John W. Brewer. Kronecker products and matrix calculus in system theory. IEEE Transactions on Circuits and Systems, 25(9):772–781, September 1978. 80, 81 [35] E.H. Bristol. On a new measure of interaction for multivariable process control. IEEE transactions on Automatic Control, AC–11(133), 1966. 103 [36] Jens Trample Broch. Principles of Experimental Frequency Analysis. Elsevier applied science, London & New York, 1990. 220 [37] Robert Grover Brown and Patrick Y.C. Hwang. Introduction to Random Signals and Applied Kalman Filtering. John Wiley & Sons, 2 edition, 1992. 431

APPENDIX E. USEFUL TEST MODELS [41] Richard L. Burden and J. Douglas Faires. Numerical Analysis. PWS Publishing, 5 edition, 1993. 120 [42] C. Sidney Burrus, James H. McClellan, Alan V. Oppenheim, Thomas W. Parks, Ronald W. Schafer, and Hans W. Schuessler. Computer-Based Exercises for Signal Processing using Matlab. Prentice–Hall, 1994. 17, 204 [43] B. Carnahan and J.O. Wilkes. Numerical solution of differential equations - an overview. In R. Mah and W.O. Seider, editors, FOCAPD ’80, Henniker, New Hampshire, 1980. 86 ˚ om [44] C.C. Hang and K. J. Astr ¨ and Q.G. Wang. Relay feedback auto-tuning of process controllers – A tutorial overview. J. Process Control, 12:143–162, 2002. 177 [45] B. Chachuat. Nonlinear and dynamic optimization: From theory to practice. Technical report, Automatic Control Laboratory, EPFL, Switzerland, 2007. Available from infoscience.epfl.ch/record/111939/files/. 399, 407 [46] Edward R. Champion. Numerical Methods for Engineering Applications. Marcel Dekker, Inc., 1993. 120 [47] Cheng-Liang Chen. A simple method of on-line identification and controller tuning. 35(12):2037– 2039, 1989. 159 [48] Cheng-Liang Chen. A closed loop reaction–curve method for controller tuning. Chemical Engineering Communications, 104:87–100, 1991. 159, 166 [49] Robert Chote. Why the Chancellor is always wrong. New Scientist, page 26, 31 October 1992. 91 [50] C.K. Chui and G. Chen. Kalman Filtering with RealTime Applications. Springer–Verlag, 1987. 431, 452, 456 [51] C.K. Chui and G. Chen. Linear Systems and Optimal Control. Springer–Verlag, 1989. 399, 400, 408 [52] David Clarke. Advances in Model-Based Predictive Control. Oxford University Press, 1994. 184, 318, 461

[38] Arthur E. Bryson and Yu-Chi Ho. Applied Optimal Control. Ginn & Co., Waltham, Mass., 1969. 399

[53] David W. Clarke. PID Algorithms and their Computer Implementation. Trans. Inst. Measurement and Control, 6(6):305–316, Oct-Dec 1984. 132

[39] James L. Buchanan and Peter R. Turner. Numerical Methods and Analysis. McGraw–Hill, 1992. 120

[54] J.D. Cryer. Time series analysis. PWS, 1986. 243

[40] F. Buchholt and M. Kummel. ¨ A Multivariable Selftuning Regulator to Control a Double Effect Evaporator. Automatica, 17(5):737–743, 1981. 94

[55] Jonathan Currie and David I. Wilson. A Model Predictive Control toolbox intended for rapid prototyping. In Tim Molteno, editor, 16th Electronics New Zealand Conference (ENZCon 2009), pages

E.2. AIRCRAFT MODEL 7–12, Dunedin, New Zealand, 18–20 November 2009. 474, 478 [56] Jonathan Currie and David I. Wilson. Lightweight Model Predictive Control intended for embedded applications. In 9th International Symposium on Dynamics and Control of Process Systems (DYCOPS), pages 264–269, Leuven, Belgium, 5–7 July 2010. 474 [57] James B. Dabney and Thomas L. Harman. Mastering Simulink 4. Prentice–Hall, 2001. 395 [58] D.T. Dalle-Molle, T. Edgar, and B.J. Kuipers. Qualitative modelling of physical systems. In 3rd Int. Symposium on Process Systems Engineering, pages 169–174, August 1988. 492 [59] Howard Demuth and Mark Beale. Neural Network Toolbox User’s Guide. The MathWorks Inc., June 1992. 494 [60] J.J. DiStefano, A.R. Stubberud, and I.J. Williams. Feedback and Control Systems. Schaum’s Outline Series, McGraw-Hill, 1990. 71 [61] Peter Dorato, Chaouki Abdallah, and Vito Cerone. Linear-quadratic Control: An Introduction. Prentice– Hall, 1995. 411, 457, 516 [62] Richard Dorf. Modern control systems. Addison– Wesley, 5 edition, 1989. 65 [63] M. Drouin, H. Abou-Kandil, and M. Mariton. Control of complex systems. Methods and technology. Plenum Press, 223 Spring St, New York NY 10013, 1 edition, 1991. 5, 399 [64] D.B. Ender. Control analysis and optimisation. Technical report, Instrument Soc. America, Techmation, Tempe, Arizona 85282, 1990. 149 [65] D. Grant Fisher and Dale E. Seborg. Multivariable Computer Control. North-Holland, 1976. 94 [66] Samuel C. Florman. The Existential Pleasures of Engineering. St. Martins Press, New York, 1976. 4 [67] T. R. Fortescue, L. S. Kershenbaum, and B. E. Ydstie. Implementation of self-tuning regulators with variable forgetting factors. Automatica, 17(6):831–835, 1981. 295 [68] Lloyd D. Fosdick, Elizabeth R. Jessup, and Carolyn J.C. Schauble. Elements of Matlab. High Performance Scientific Computing, University of Colorado, January 1995. Available from cs.colorado.edu/pub/HPSC. 3, 4 [69] A. S. Foss. Critique of chemical process control theory. American Inst. Chemical Engineers J, 19(2):209–214, 1973. 45

519 [70] G.F. Franklin and J.D. Powell. Digital control of dynamic systems, pages 131–183. Addison–Wesley, 1980. 42, 68, 367 [71] G.F. Franklin, J.D. Powell, and M.L. Workman. Digital Control of Dynamic Systems. Addison– Wesley, 3 edition, 1998. 276 [72] C.E. Garcia, D.M. Prett, and M. Morari. Model predictive control: Theory and practice — A survey. Automatica, 25(3):335–348, 1989. 461 [73] H.P. Geering. Introduction to Fuzzy Control. Technical Report IMRT-Bericht Nr. 24, Eidgenossische ¨ Technische Hochschule, February 1992. 491 [74] Paul Geladi and Bruce R. Kowalski. Partial LeastSquares Regression: A Tutorial. Analytica Chimica Acta, 185:1–17, 1986. 111 [75] S.F. Goldmann and R.W.H. Sargent. Applications of linear estimation theory to chemical processes: A feasibility study. Chemical Engineering Science, 26:1535–1553, 1971. 441 [76] Graham C. Goodwin, Stefan F. Graebe, and Mario E. Salgado. Control System Design. Prentice– Hall, 2001. 125 [77] Felix Gross, Dag Ravemark, Peter Terwiesch, and David Wilson. The Dynamics of Chocolate in Beer: The Kinetic Behaviour of theobroma cacao Paste in a CH3 CH2 OH–H2 O–CO2 Solution. Journal of Irreproducible Results, 37(4):2–4, 1992. 237 [78] Tore K. Gustafsson and Pertti M. M¨akil¨a. ˚ L1 Identification Toolbox for Matlab. Abo Akademi, Finland, August 1994. From ftp.abo.fi/pub/rt/l1idtools. 482 [79] I. Gustavsson. Survey of Applications of Identification in Chemical and Physical Processes. Automatica, 11:3–24, 1975. 236 [80] Juergen Hahn, Thomas Edison, and Thomas F. Edgar. A note on stability analysis using bode plots. Chemical Engineering Education, 35(3):208– 211, 2001. 72 [81] F. Hayes-Roth. Building Expert Systems. Addison– Wesley, Reading Massachusetts, 1983. 488 [82] A. Helbig, W. Marquardt, and F. Allgower. Nonlinearity measures: definition, computaiton and applications. Journal of Process Control, pages 113– 123, 2000. 129 [83] M.A. Henson and D.E. Seborg. Input-output Linearization of General Nonlinear Processes. American Inst. Chemical Engineers J, 36(11):1753–1757, 1990. 122, 380

520

APPENDIX E. USEFUL TEST MODELS

[84] Michael A. Henson. Nonlinear model predictive control: current status and future directions. Computers in Chemical Engineering, 23(2):187–202, 1998. 463

[99] Arthur Jutan and E. S. Rodriguez II. Extension of a New method for On-Line Controller Tuning. The Canadian Journal of Chemical Engineering, 62:802– 807, December 1984. 159

[85] Michael A. Henson and Dale E. Seborg. Nonlinear Process Control. Prentice Hall, Saddle River, New Jersey, 1997. 92

[100] Thomas Kailath. Linear Systems. Prentice–Hall, 1980. 399

[86] David R. Hill. Experiments in Computational Matrix Algebra. The Random House, 1988. 54 [87] David M. Himmelblau. Process Analysis by Statistical Methods. John Wiley & Sons, 1970. 117, 259 [88] Roger A. Horn and Charles R. Johnson. Topics in Matrix Analysis. Cambridge University Press, 1991. 80 [89] Morten Hovd and Sigurd Skogestad. Pairing Criteria for Unstable Plants. In AIChE Annual Meeting, page Paper 149i, St. Louis, Nov 1993. 351 [90] P. J. Huber. Robust regression: Asymptotics, conjectures, and Monte Carlo. Ann. Math. Statist., 1(5):799–821, 1973. 280 [91] Enso Ikonen and Kaddour Najim. Advanced Process Identification and Control. Marcel Dekker, 2002. 265 [92] Vinay K. Ingle and John G. Proakis. Digital Signal Processing using Matlab V.4. PWS Publishing Company, 1997. 204 [93] Rolf Isermann. Paramater adaptive control algorithms—A tutorial. Automatica, 18(5):513–528, 1982. 308 [94] M.L. James, G. M. Smith, and J. C. Wolford. Applied Numerical Methods for Digital Computation with Fortran and CSMP. Harper & Row, 2 edition, 1977. 120 [95] R.K. Jaspan and J. Coull. Trajectory Optimization Techniques in Chemical Reaction Engineering II: Comparison of Methods. American Inst. Chemical Engineers J, 18(4):867–869, July 1972. 402 [96] Andrew H. Jazwinski. Stochastic Processes and Filtering Theory. Academic Press, 111 Fifth Avenue, New York, 1970. 431, 452 [97] A. Johnson. LQG Applications in the Process Industries. Chemical Engineering Science, 48(16):2829– 2838, 1993. 399 [98] Michael A. Johnson and Mohammad H. Moradi. PID COntrol: New Identification and Design Methods. Springer–Verlag, London, UK, 2005. 132, 134

[101] Paul G. Kaminski, Arthur E. Bryson, and Stanley F. Schmidt. Discrete Square Root Filtering: A survey of current techniques. IEEE Trans. Automatic Control, AC-16:727–735, 1971. 452 [102] Solomon S. Katz. Emulating the PROSPECTOR Expert System with a Raster GIS. Computers & Geosciences, 17(7):1033–1050, 1991. 488 [103] L.H. Keel and S.P. Bhattacharyya. Robust, fragile, or optimal? Automatic Control, IEEE Transactions on, 42(8):1098 –1105, Aug 1997. 476 [104] David Kincaid and Ward Cheney. Numerical Analysis. Mathematics of Scientific Computing. Brooks/Cole, 1991. 120, 497 [105] Costas Kravaris and Jeffery C. Kantor. Geometric Methods for Nonlinear Process Control. 1 Background. Ind. Eng. Chem. Res., 29:2295–2310, 1990. 380 [106] Costas Kravaris and Jeffery C. Kantor. Geometric Methods for Nonlinear Process Control. 2 Controller Synthesis. Ind. Eng. Chem. Res., 29:2310– 2323, 1990. 380 [107] Erwin Kreyszig. Advanced Engineering Mathematics. John Wiley & Sons, 7 edition, 1993. 220 [108] B. Kristiansson and B. Lennartson. Robust and optimal tuning of PI and PID controllers. IEE Proc.Control Theory Applications, 149(1):17–25, January 2002. 190 [109] R. Kulhavy´ and M.B. Zarrop. On a general concept of forgetting. Int. J. Control, 3(58):905–924, 1993. 311 [110] Benjamin C. Kuo. Automatic Control Systems. Prentice–Hall, 6 edition, 1991. 40 [111] Benjamin C. Kuo. Automatic Control Systems. Prentice–Hall, 7 edition, 1995. 427, 428 [112] I. D. Landau. Identification in closed loop: a powerful design tool (better design models, simpler controllers). Control Engineering Practice, 9:51–65, 2001. 308 [113] Yoan D. Landau. Adaptive Control: The model reference approach. Marcel Dekker, 1979. 297 [114] Leon Lapidus and John H. Seinfeld. Numerical Solution of Ordinary Differential Equations. Academic Press, 1971. 86

E.2. AIRCRAFT MODEL

521

[115] Alan J. Laub. Matrix Analysis for Scientists and Engineers. Society for Industrial and Applied Mathematics, 2004. 80

[131] Paul A. Lynn and Wolfgang Fuerst. Introductory Digital Singnal Processing with Computer Applications. John Wiley & Sons, 2 edition, 1994. 208, 220

[116] P.L. Lee and G.R. Sullivan. Generic Model Control (GMC). Computers in Chemical Engineering, 12(6):573–580, 1988. 371

[132] J. M. Maciejowski. Predictive Control with Constraints. Prentice–Hall, 2002. 477

[117] T.H. Lee, Q.G. Wang, and K.K. Tan. Knowledgebased process identification from relay feedback. Journal of Process Control, 5(6):387–397, 1995. 177, 179 [118] S. Lees and J.O. Hougen. Determination of pneumatic controller characteristics by frequency response. Ind. Eng. Chem., 48:1064, 1956. 247 [119] J. R. Leigh. Control Theory: A guided tour. IEE Control Series 45. Peter Peregrinus Ltd., 1992. 73

[133] Sven Erik Mattsson. On Modelling and Differential/Algebraic Systems. Simulation, pages 24–32, January 1989. 129 [134] Cleve Moler and John Little. Matlab User’s Guide. The MathWorks Inc., December 1993. 1 [135] B. De Moor, P. De Gersem, B. De Schutter, and W. Favoreel. DAISY: A database for identification of systems. Journal A, 38(3):4–5, 1997. 312 [136] Manfred Morari. Three critiques of process control revisited a decade later. In D.M. Prett, C.E. Grac´ıa, and B.L. Ramaker, editors, The Shell Process control workshop, pages 309–321. Butterworths, 1987. 45, 360

[120] A. Leva, C. Cox, and A. Ruano. Hands-on pid autotuning: a guide to better utilisation. In Marek Zaremba, editor, IFAC Professional Brief, chapter 3. IFAC, 2002. Available from www.ifac-control.org/publications/pbriefs/PB_Final_LevaCoxRuano.pdf. [137] Manfred Morari. Process control theory: Reflec240 tions on the past and goals for the next decade. In D.M. Prett, C.E. Grac´ıa, and B.L. Ramaker, edi[121] Frank L. Lewis. Optimal Estimation. John Wiley & tors, The second Shell Process control workshop, pages Sons, 1986. 282, 437, 452 469–488. Butterworths, December 1988. 95 [122] Frank L. Lewis and Vassilis L. Syrmos. Optimal Control. John Wiley & Sons, 2 edition, 1995. 457 [123] R.J. Litchfield, K.S. Campbell, and A. Locke. The application of several Kalman filters to the control of a real chemical reactor. Trans. IChemE, 57(2):113–120, April 1979. 375, 376 [124] Lennart Ljung. System Identification: Theory for the User. Prentice–Hall, 1987. 236, 244, 270, 280, 310

[138] Manfred Morari. Some Control Problems in the Process Industries. In H.L. Trentelman and J.C. Willems, editors, Essays on Control: Perspectives in the Theory and its applications. Birkh¨auser, 1993. 141 [139] Manfred Morari. Model Predictive Control: Multivariable Control Technique of Choice in the 1990s. In David Clarke, editor, Advances in Model-Based Predictive Control, pages 22–37. Oxford University Press, 1994. 45, 221

[125] Lennart Ljung. System Identification Toolbox, for use with Matlab. The MathWorks Inc., May 1991. 236, 305, 309

[140] Manfred Morari and Evanghelos Zafiriou. Robust Process Control. Prentice–Hall, 1989. 101, 122

[126] Lennart Ljung. System Identification: Theory for the User. Prentice–Hall, 2 edition, 1999. 277

[141] Jerzy Moscinski and Zbigniew Ogonowski. Advanced Control with Matlab and Simulink. Ellis Horwood, 1995. 247, 494

[127] Lennart Ljung and Torkel Glad. Modeling of Dynamic Systems. Prentice–Hall, 1994. 236 [128] Charles F. Van Loan. The ubiquitous kronecker product. Journal of Computational and Applied Mathematics, 123:85–100, 2000. 80 [129] W. L. Luyben. Process Modeling, Simulation, and Control for Chemical Engineers. McGraw-Hill, 2 edition, 1990. 86 [130] W.L. Luyben. Process modelling simulation and control for chemical engineers. McGraw-Hill, 1973. 98

[142] Frank Moss and Kurt Wiesenfeld. The benefits of Background Noise. Scientific American, pages 50– 53, August 1995. See also Amateur Scientist in the same issue. 195 [143] Ivan Nagy. Introduction to Chemical Process Instrumentation. Elsevier, 1992. 6 [144] Ioan Nascu and Robin De Keyser. A novel application of relay feedback for PID auto-tuning. In IFAC CSD03 Conference on Control systems Design, Bratislava, Slocak Republic, 2003. 177

522

APPENDIX E. USEFUL TEST MODELS

[145] R.B. Newell and P.L. Lee. Applied Process Control – A Case Study. Prentice–Hall, 1989. 94, 95, 420, 429, 446, 491, 515

[160] Jack W. Ponton. Neural Networks: Some Questions and Answers. J. Process Control, 2(3):pp163– 165, 1992. 502

[146] R.E. Nieman and D.G. Fisher. Experimental Evaluation of Optimal Multivariable Servo-control in Conjunction with Conventional Regulatory Control. Chemical Engineering Communications, 1, 1973. 478

[161] W.H. Press, B.P. Flannery, S.A Teukolsky, and W.T. Vetterling. Numerical Recipes: The Art of Scientific Computing. Cambridge University Press, 1986. 110, 220, 221, 229, 401

[147] R.E. Nieman, D.G. Fisher, and D.E. Seborg. A review of process identification and parameter estimation techniques. Int. J of control, 13(2):209–264, 1971. 236 [148] Katsuhiko Ogata. Discrete Time Control Systems. Prentice–Hall, 1987. 15, 24, 26, 28, 31, 36, 38, 49, 54, 55, 62, 74, 75, 78, 83, 108, 231, 310, 338, 339, 352, 353, 355, 365, 367, 368, 410, 443 [149] Katsuhiko Ogata. Discrete-Time Control Systems. Prentice–Hall, 1987. 27 [150] Katsuhiko Ogata. Modern Control Engineering. Prentice–Hall, 2 edition, 1990. 71, 76, 78, 80, 109, 151, 168, 352, 353, 355, 389 [151] B. A. Ogunnaike, J. P. Lemaire, M. Morari, and W. H. Ray. Advanced multivariable control of a pilot-plant distillation column. 29(4):632–640, July 1983. 97 [152] Alan V. Oppenheim and Ronald W. Schafer. Digital Signal Processing. Prentice–Hall, 1975. 207 [153] Overschee and De Moor. Subspace Identification. Kluwer Academic Publshers, 1996. 276 [154] G.F. Page, J.B. Gomm, and D. Williams. Applications of Neural Networks to Modelling and Control. Chapman & Hall, 1993. 494 [155] Chris C. Paige. Properties of Numerical Algorithms Related to Computing Controllability. IEEE transactions on Automatic Control, AC–26(1):130– 138, 1981. 355 [156] Sudharkar Madhavrao Pandit and Shien-Ming Wu. Time Series and System Analysis with Applications. Wiley, 1983. 307 [157] Rajni V. Patel, Alan J. Laub, and Paul M. van Dooren. Numerical Linear Algebra Techniques for Systems and Control. IEEE Press, 1994. A selected reprint volume. 62, 355, 356 [158] Linda Petzold. Differential/Algebraic Equations are not ODE’s. SIAM J. Sci. Stat. Comput., 3(3):367– 384, 1982. 123 [159] C.L. Phillips and H.T. Nagle. Digital Control System Analysis and Design. Prentice–Hall, 2 edition, 1990. 200

[162] S. Joe Qin and Thomas A. Badgwell. A survey of industrial model predictive control technology. Control Engineering Practice, 11(7):733–764, July 2003. 461, 478 [163] W. Fred Ramirez. Process Control and Identification. Academic Press, 1994. 399, 407, 411 [164] C. V. Rao, S. J. Wright, and J. B. Rawlings. Application of interior-point methods to model predictive control. Journal of Optimization Theory and Applications, 99(3):723–757, 1998. 467 [165] T. Rautert and E.W. Sachs. Computational design of optimal output feedback controllers. Technical Report Nr. 95-12, Universit¨at Trier, FB IV, Germany, June 1995. 457 [166] James B. Rawlings. Tutorial overview of Model Predictive Control. IEEE Control Systems Magazine, 20(3):38–52, June 2000. 461 [167] W. Harmon Ray and Julian Szekely. Process Optimization. John Wiley & Sons, 1973. 399, 402 [168] W.H. Ray. Advanced Process Control. McGraw–Hill, NY, 1 edition, 1981. 399 [169] John R. Rice. Numerical Methods, Software, and Analysis. McGraw–Hill, 1983. 120 [170] C. Magnus Rimvall and Christopher P. Jobling. Computer Aided Control System Design. In W.S. Levine, editor, The Control Handbook, chapter 23, pages 429–442. CRC Press, 1995. 2 [171] William H. Roadstrum and Dan H. Wolaver. Electrical Engineering for all Engineers. John Wiley & Sons, 2 edition, 1994. 13 [172] E.R. Robinson. Time Dependent Chemical Processes. Applied Science Publishers, 1975. 399 [173] J. A. Rossiter. Model-Based Predictive Control: A Practical Approach. CRC Press, 2003. 477 [174] Hadi Saadat. Computational Aids in Control Systems using Matlab. McGraw–Hill, 1993. 51 [175] Robert Schoenfeld. The Chemist’s English. VCH Verlagsgesellschaft mbH, D-6940 Weinheim, Germany, 2 edition, 1986. 220 [176] J. Schoukens and R. Pintelon. Identification of Linear Systems. Pergamon, 1991. 110

E.2. AIRCRAFT MODEL

523

[177] Tobias Schweickhardt and F. Allgower. Linear control of nonlinear systems based on nonlinearity measures. Journal of Process Control, 17:273–284, 2007. 129

[192] Dominick Stephens. The Reserve Bank’s Forecasting and Policy System. Technical report, Economics Department, The Reserve Bank of New Zealand, Wellington, NZ, 2004. 462

[178] Dale E. Seborg, Thomas F. Edgar, and Duncan A. Mellichamp. Process Dynamics and Control. Wiley, 2 edition, 2005. 152, 155

[193] O. Taiwo. Comparison of four methods of online identification and controller tuning. IEE Proceedings-D, 140(5):323–327, 1993. 159, 166

[179] D.E. Seborg, T.F. Edgar, and D.A. Mellichamp. Process Dynamics and Control. Wiley, 1989. 15, 31, 104, 105, 138, 151, 153, 254

[194] Les Thede. Analog and Digital Filter Design using C. Prentice–Hall, 1996. 204

[180] D.E. Seborg, T.F Edgar, and S.L. Shah. Adaptive Control Strategies for Process Control: A survey. American Inst. Chemical Engineers J, 32(6):881–913, 1986. 318 [181] Warren D. Seider, J.D. Seader, and Daniel R. Lewin. Process Design Principles: Synthesis, Analysis and Evaluation. John Wiley & Sons, 1999. 105 [182] Bahram Shahian and Michael Hassul. Control System Design Using Matrixx . Prentice–Hall, 1992. 67 [183] Kermit Sigmon. Matlab primer, 3rd edition. Dept. of Mathematics, University of Florida, 1993. 3, 4 [184] Jonas Sjoberg, ¨ Qinghua Zhang, Lennart Ljung, Albert Benveniste, Bernard Delyon, Pierre-Yves Glorennec, H˚akan Hjalmarsson, and Anatoli Juditsky. Nonlinear black-box modeling in system identification: a unified overview. Automatica, 31(12):1691–1724, 1995. Trends in System Identification. 238, 280 [185] S. Skogestad. Dynamics and Control of Distillation Columns– A Critical Survey. In DYCORD+, pages 11–35. Int. Federation of Automatic Control, 1992. 95 [186] Sigurd Skogestad. Simple analytic rules for model reduction and PID controller tuning. Journal of Process Control, 13(4):291–309, 2003. 134, 153 [187] Jean-Jacques E. Slotine and Weiping Li. Applied Nonlinear Control. Prentice–Hall, 1991. 74, 75, 380 [188] T. Soderstr ¨ om ¨ and P. Stocia. System Identification. Prentice–Hall, 1989. 236, 310 [189] Harold W. Sorenson, editor. Kalman filtering: Theory and Application. Selected reprint series. IEEE Press, 1985. 431 [190] Henry Stark and John W. Woods. Probability, Random Processes, and Estimation Theory for Engineers. Prentice–Hall, 2 edition, 1994. 432 [191] George Stephanopoulos. Chemical Process Control: An introduction to Theory and Practice. Prentice– Hall, 1984. 105, 145

[195] J. Villadsen and M.L. Michelsen. Solution of differential equation models by polynomial approximation. Prentice–Hall, 1978. 86 [196] Stanley M. Walas. Modeling with Differential Equations in Chemical Engineering. Butterworth– Heinemann, 1991. 86, 123, 401 [197] Liuping Wang. Model Predictive Control System Design and Implementation using Matlab. Springer, 2009. 477 [198] Liuping Wang and William R. Cluett. From Plant Data to Process Control. Taylor and Francis, 11 New Fetter Lane, London, EC4P 4EE, 2000. 259, 260 [199] Ya-Gang Wang, Zhi-Gang Shi, and Wen-Jian Cai. PID autotuner and its application in HVAC systems. In Proceedings of the American Control Conference, pages 2192–2196, Arlington, VA, 25–27 June 2001. 177 [200] P.E. Wellstead and M.B. Zarrop. Self-tuning Sytems: Control and Signal Processing. John Wiley & Sons, 1991. 245, 295, 300, 302, 308, 310, 312, 314, 322, 452 [201] David I. Wilson. Introduction to Numerical Analysis with Matlab or what’s a NaN and why do I care? Auckland University of Technology, Auckland, New Zealand, July 2007. 465pp. 3, 120, 197, 205, 280, 391, 478, 482 [202] R. K. Wood and M.W. Berry. Terminal Composition Control of a Binary Distillation Ccolumn. Chemical Engineering Science, 28:1707, 1973. 95 [203] Minta Yuwana and Dale E. Seborg. A New Method of On-line Controller Tuning. American Inst. Chemical Engineers J, 28(3):434–440, May 1982. 159 [204] J.G. Ziegler and N.B. Nichols. Optimum Settings for Automatic Controllers. Trans. ASME, 64:759– 768, 1942. 151

Index ⊗, see Kronecker product A/D, 13 Ackermann, 361, 364 adaptive control applications, 317 classification, 319 general scheme, 318 suitable, 318 affine, 380 AIC, see Akaike Information Criteria Akaike Information Criteria, 277 algebraic Riccati equation, 416 are, 416 solving, 415, 417 alias, 17 detecting, 18 ARMAX model, 263 arms race, 314 ARX model, 262 ATV tuning method, 167 auto-tuners, 321 autonomous systems, 46 back propagation, 499 balance arm, 7, 138 Bernoulli’s equation, 89 bilinear transform, 38 black-box, 175 blackbox, 6 Bode diagram, 40, 72 Bristol, 103 Bromwich integral, 31 bursting, 335 bvp4c, 402, 405 c2d.m, 61 canon, 55, 353 canonical form, 50, 55 controllable, 48 diagonal, 49 Jordan, 49 observable, 48 Cauchy form, 47

Cayley-Hamilton theorem, 361 ceiling function, 204 Chebyshev design, 206 Chebyshev filter, see filter Cholesky decomposition, 77, 80, 452 Cholesky matrix square root, 453 closed loop, 46 coloured noise, 300 Computer design aids, 3 confidence ellipses, 118 confidence intervals, 116 controllability, 352 computing, 355 covariance wind-up, 295 covariance matrix, 117, 284, 290, 433 reset, 292 cover-up rule, 26 curve fitting, 499 D/A, 13 DAEs, 123 dare, 443 dead time compensation, 185 deadbeat control, 364 deadtime, 277 difference equations, 20 differentiation noise, 196 digital filter, 212 aliasing, 17 diophantine convmtx, 328 Diophantine equation, 326 Dirac delta function, 22 direct method, see Lyapunov discrete algebraic Riccati equation, 443 distillation interaction, 102 model, 98 simulation, 101 dlqe, 443 DMC, see dynamic matrix control double integrator, 88 524

INDEX DSP, 209 dynamic matrix control, 468 etfe, 253 Euler relations, 222 exact feedback linearisation, 380 cautions, 382 design procedure, 382 exhaustive search, 394 expert systems, 487 languages, 488 process control, 490 extended Kalman filter, 454 FFT, see Fourier transform, 246 fft, 228 filter, 193, 209 bi-quad, 217 Butterworth, 201 characteristics, 204 cascade, 199 Chebyshev, 205 DFI, 215 DFII, 216, 219 digital, 212 elliptic, 201, 208 hardware, 215 ideal, 198 minimum order, 204 proto-type, 200 quantisation, 218 SOS, 217 final value theorem, 24 finite differences, 20 Euler, 20 first-order plus deadtime, 240 fixed-position, 459 flapper, 8 FOPDT, see first-order plus deadtime forgetting factor, 291, 292, 324 influence, 294 Fourier transform, 219, 250 definitions, 221 fast, 225 slow, 221 frequency pre-warping, 213 function approximation, 220 gain scheduling, 319 Gauss, 107 Gilbert’s criteria, 353 Hammerstein models, 280

525 Hankel matrix, 269, 470 Hardamard product, ⊗, 104 helicopter, 8 hidden layers, 498 identification, 235 black and white, 237 closed loop, 307 continuous models, 254 frequency response, 250 frequency testing, 246 graphical, 239, 254 model, 236 noise models, 300 nonlinear, 280 offline, 239 online, 280 parameters, 236 PRBS, 244 real-time, 238 state-space, 274 subspace, 276 step response, 240 system, 236 time, 239 two-dimensional, 114 initial value theorem, 24 integral states, 427 integral-only control, 135 inter-sample ripple, 364 interaction, 102 Internal Model Control, 153 inverse response, 181 invfreqs, 246 Jordan form, 61, 62 Jury test, 71 Kaczmarz, 306 Kalman filter, 438, 442 algorithm, 441 current estimation type, 444 extended, 454 prediction type, 443 steady-state, 442 Kronecker product, 77, 80, 417, 438 Kronecker tensor product, 77 Laguerre functions, 259 Laplace transform inverting numerically, 31 least-squares, 107 improvements, 110

INDEX

526 nonlinear, 112 partial, 111 recursive, 281 recursive estimation, 284 solution, 109 level control, 88 Liapunov, see Lyapunov Lie algebra, 380 limit oscillation, 168 linear program, 478 linear quadratic regulator, 409 continuous, 409 discrete, 418 steady-state, 415 time varying, 411 linearise, 125 finite difference, 127 linmod, 127 tank model, 127 Lissajou, 248 load disturbance, 158 loss function, see performance index LQR, see linear quadratic regulator LTI object, 36 Lyapunov, 74, 76, 458 continuous stability, 76 discrete, 438 discrete stability, 76 function, 75 matrix equation, 77 solving, 80 Maple, 3, 511 mapping, 21 Matlab, 2 Matlab alternatives Octave, 3 SciLab, 3 matrix exponential, 58 maximum likelihood, 280 Maxwell, 1 measurement noise, 116 Method of Areas, 240 micro-controllers, 13 minimum variance control, 323 dead-time, 341 MIT rule, 297 model CSTR, 92 distillation, 95 high purity, 101 Wood-Berry, 95 double integrator, 88 evaporator, 94

pendulum, 86 stirred heated tank, 90 validation, 276 model predictive control, 461 model reference control GMC, 374 modelling, 85, 86 cautions, 91 evaporators, 94 extrapolation, 91 models discrete, 260 linear, 237 MPC, see model predictive control algorithm, 463 horizons, 467 Toolbox, 464 toolbox, 478 MuPad, 511 Nader, Ralph, 4 Nelder-Mead, 113 neural networks, 493 activation function, 495 architecture, 495 neurons, 495 toolbox, 499 training, 498 Newell-Lee evaporator, see modelling Newton-Rhapson, 157 Nilpotent matrix, 364 noise industrial, 194 models, 300 non-minimum phase, 181, 336 nonlinear measure, 128 nonlinear models, 127, 280 nonlinearities types, 125 Nyquist diagram, 40, 41 frequency, 16, 17, 204, 210, 212 dimensionless, 17 Nyquist diagram, 72 observability, 352 OCP, 401 ODEs, 120 numerical solutions, 120 two-point boundary value problems, 123 OE model, see output-error model Opti toolbox, 112, 113 optimal control, 387 generic problem, 397

INDEX Hamiltonian, 400 linear programming, 478 PID tuning, 388 Pontryagin, 399 TPBVP, 401 optimal control problem, 399 optimal prediction, 341 optimisation, 113, 297, 387 cost function, 388 nonlinear, 112 Opti, 112 parametric, 388 output optimal control, 457 output variance, 5 output-error model, 264 packed matrix notation, 54 Pad´e approximation, 38 parameter optimisation, 296 parametric adaption, 298 Parseval, 221 partial fractions, 26, 27 Matlab, 27 partial least-squares, 111 PDEs, 120 pendulum, 86 simulation, 120 penicillin, 384 performance index, 107 IAE, 388 periodogram, 227 persistent excitation, 243, 308 PI-D, 138 PID, 131 cascade, 134 classical, 132 discrete, 143 parallel, 132, 134 position form, 145 programming, 143 standard, 133 textbook, 132 tuning, 150 pidtool, 153 pidtune, 153 closed loop, 155 Ziegler-Nichols, 155 velocity form, 145 pole excess, see time delay pole-placement, 325, 364 polyfit, 110 polynomial addition, 321 multiplication, 321

527 polynomial controller design, 321 poorly damped, 336 positive definite, 410 check, 452 lost, 452 power spectral density, 226, 228 process control economics, 4 psd, see power spectral density pseudo-inverse, 111 quadratic form, 410 quadratic program, 467 quantisation error, 14 random inputs, 243 receding horizon control, 461 recurrent networks, 498 recursive mean, 282 variance, 282 recursive estimation extended, 301 SI toolbox, 305 simplified, 306 Kaczmarz, 306 starting, 285 recursive extended least-squares, 302 recursive least squares, see least squares regression vector, 266 relative gain array, 103 dynamic, 105 relative order, 381 relay, 167, 175 autotuning, 170 example, 170 relay feedback, 166 noise, 173 RELS, see recursive estimation rels, 302 remembering factor, see forgetting factor residue, 26 RGA, see relative gain array Riccati equation algebraic, 416 computing solution, 419 differential, 411 time varying, 417 ringing, 336 ripple, 205 RLS, 281 robust fitting, 280 Routh table, 71

INDEX

528 safety, 4 sample and hold zoh, 36 sample time selection, 14 sampling, 14 sampling theorem, 16 alias, 16 SattControl, ECA400, 167 self tuning controllers relay feedback, 166 self tuning regulators, 322 problems, 346 sensitivity function, 188 shift register, 289 Simulink real-time, 10 single precision, 219 singular value decomposition, 110 SISO, single input/single output, 43 Slyvester’s criteria, 79, 80 Smith predictor, 185 Simulink, 186 smoothing fourier, 228 SOS, 217 spectral analysis, 224 experimental, 246 spectral plot, 226 spline, 197 stability, 69 BIBO, 70 closed loop, 72 continuous time, 70 definition, 69 discrete time, 73 Jury test, 71 Lyapunov, 74 nonlinear, 74 Routh array, 70 unit circle, 73 stacking, 81 state, 46 state reconstruction, 356 state space, 46 conversions, 50 definitions, 46 pole-placement, 359 state-space conversions, 47 statical networks, 498 statistic, t, 116 Statistics toolbox, 3 steady-state models, 86 steepest descent, 297

step tests, 239 Stixbox, 3 stochastic processes, 437 Sylvester equation, 77, 81 Sylvester matrix, 327 symbolic algebra, 3 Maple, 3 MuPad, 3 symbols, 505 System Identification toolbox, 302 system type, 427 tapped delay, 215 target set, 406 Technical support notes, 226 tides, 501 time delay discrete, 67 time series analysis project, 307 Toeplitz matrices, 269 trace of a matrix, 296 transfer function, 55 time constant, 55 transition matrix, 58 Tustin’s approximation, 38 Tustin’s method, see bilinear transform unstable zeros, 336, 338, 344 vectorisation, 81 waypoints, 32 Weierstrass approximation theorem, 497 well damped, 338 white noise, 286 Wiener models, 280 Wood-Berry column model, 95 X-15, 317 Yuwana-Seborg tuning, 159 z-transform, 22 geometric series, 23 inversion, 24 computational, 29 long division, 28 partial fractions, 26 zero-pole-gain, 55 zeroth-order hold, 40 Ziegler-Nichols closed loop, 155 example, 156 openloop, 151 zoh, see zeroth-order hold

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF