You are on page 1of 236

Copyright Information

June 2005
Second edition
Intended for use with Mathematica 4 or 5

Software and manual: Igor Bakshee

Product managers: Yezabel Dooley and Kristin Kummer


Project managers: Julienne Davison, Julia Guelfi, and Jennifer Peterson
Editor: Jan Progen
Proofreading: Richard Martin and Emilie Finn
Software quality assurance: Jay Hawkins, Cindie Strater, Angela Thelen, Rachelle Bergmann, and Shiho Inui
Package design: Jeremy Davis, Megan Gillette, and Kara Wilson

Includes Electrical Engineering Plots package by Steve Adams, Jeffrey Adams, and John M. Novak
Special thanks to John M. Novak, Leszek Sczaniecki, Todd Gayley, Roger Germundsson, Hans Hoelzer, Neil Munro,
David Smith, and Daniil Sarkissian

Published by Wolfram Research, Inc., 100 Trade Center Drive, Champaign, Illinois 61820-7237, USA
phone: +1-217-398-0700; fax: +1-217-398-0747; email: info@wolfram.com; web: www.wolfram.com

Copyright © 1996–2005 Wolfram Research, Inc.

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted, in any form
or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior written permission
of Wolfram Research, Inc.

Wolfram Research, Inc. is the holder of the copyright to the Control System Professional software and documentation
("Product") described in this document, including without limitation such aspects of the Product as its code, structure,
sequence, organization, "look and feel", programming language, and compilation of command names. Use of the
Product, unless pursuant to the terms of a license granted by Wolfram Research, Inc. or as otherwise authorized by
law, is an infringement of the copyright.

Wolfram Research, Inc. makes no representations, express or implied, with respect to this Product, including
without limitations, any implied warranties of merchantability, interoperability, or fitness for a particular purpose,
all of which are expressly disclaimed. Users should be aware that included in the terms and conditions under
which Wolfram Research, Inc. is willing to license the Product is a provision that Wolfram Research, Inc. and its
distribution licensees, distributors, and dealers shall in no event be liable for any indirect, incidental or consequen-
tial damages, and that liability for direct damages shall be limited to the amount of the purchase price paid for the
Product.

In addition to the foregoing, users should recognize that all complex software systems and their documentation
contain errors and omissions. Wolfram Research, Inc. shall not be responsible under any circumstances for
providing information on or corrections to errors and omissions discovered at any time in this document or the
package software it describes, whether or not they are aware of the errors or omissions. Wolfram Research, Inc.
does not recommend the use of the software described in this document for applications in which errors or
omissions could threaten life, injury, or significant loss.

Mathematica, MathLink, and MathSource are registered trademarks of Wolfram Research, Inc. All other trademarks used
herein are the property of their respective owners. Mathematica is not associated with Mathematica Policy Research,
Inc. or MathTech, Inc.

#T4070
New in Version 2

Version 2 of Control System Professional carries numerous internal changes that simplify the
addition of new packages to the Control System Professional Suite while maintaining the integ-
rity of a single Mathematica application. Version 2 also includes several new algorithmic and
interface features. Except as noted in the next section, the new version is fully compatible with
Version 1.

 Intuitive, traditional typesetting of control objects in the StateSpace and Transfer


Function forms; editable control objects; easy switching between automatic display
of the results in the traditional and standard forms.
 Support for constructing StateSpace realizations from TransferFunction
objects in different target forms.
 Support for different methods of reducing StateSpace objects to TransferFunc
tion objects.
 Support for analog simulations in StateResponse, OutputResponse, and
SimulationPlot.
 Faster discrete-time domain simulations.
 Simplified syntax for polling inputs of multi-input systems with the same input
signal in time-domain simulation functions.
 Support for interconnections of multi-input, multi-output TransferFunction
systems with SeriesConnect, ParallelConnect, and FeedbackConnect.
 Support for recovering the transformation matrix used to construct realizations of
special forms (such as KalmanControllableForm or InternallyBalanced
Form).
 Faster ordered Schur decomposition.
 Performance optimization through internal caching. Developers can use the same
mechanism to provide advanced services to their users.
 Fully indexed online documentation.
Incompatible Changes between Version 1 and Version 2

 Thirty-eight new functions, options, and symbols have been added, some of whose
names may conflict with names already being used.
 ReviewForm has been superseded by the built-in Mathematica function Tradition
alForm.
 MinimalRealization[transferfunction] no longer provides an interface to PoleZe
roCancel and uniformly returns the StateSpace object.
 The option InternallyBalanced of the function DominantSubsystem is now
obsolete. DominantSubsystem can automatically determine if the input system is
an output of the function InternallyBalancedForm.
 The syntax StateFeedbackGains[a, b, poles] is no longer supported; the first
argument to StateFeedbackGains must be the StateSpace object. Example:
StateFeedbackGains[StateSpace[a, b], poles].
 The option Iterations of the function StateFeedbackGains has been
superseded by the built-in Mathematica option MaxIterations.
 Symbol J, a default generic name for a summation index in a symbolic sum returned
by StateResponse and related functions, has been superseded by the built-in
Mathematica symbol K.
 By default, the random orthogonal complements are no longer selected using the
randomized algorithm. To revert to the behavior in the previous version, you can set
$RandomOrthogonalComplement = True.
Table of Contents

1. Getting Started ................................................................................................................ 1


1.1 Using the Application for the First Time .............................................................. 1
1.2 The Structure of the Application ............................................................................ 2
1.3 The Control Objects .................................................................................................. 3
1.4 Traditional Notations ............................................................................................... 5
1.5 The Control Format .................................................................................................. 7
1.6 The Notation for the Imaginary Unit .................................................................... 9
1.7 Numericalizing for Speed ....................................................................................... 9
1.8 Evaluating Examples in This Guide ...................................................................... 10
2. Introduction: Extending Mathematica to Solve Control Problems ................... 11
3. Description of Dynamic Systems ............................................................................... 27
3.1 Transfer Function Representations ........................................................................ 27
3.2 State-Space Representations ................................................................................... 33
3.3 Continuous-Time versus Discrete-Time Systems ................................................ 39
3.4 The Traditional Notations ....................................................................................... 41
3.5 Discrete-Time Models of Continuous-Time Systems .......................................... 44
3.5.1 The Conversion Methods ................................................................................ 48
3.6 Discrete-Time Models of Systems with Delay ..................................................... 53
3.7 Continuous-Time Models of Discrete-Time Systems .......................................... 54
4. Time-Domain Response ............................................................................................... 57
4.1 Symbolic Approach .................................................................................................. 57
4.2 Simulating System Behavior ................................................................................... 65
4.3 Step, Impulse, and Other Responses ..................................................................... 74
5. Classical Methods of Control Theory ....................................................................... 80
5.1 Root Loci .................................................................................................................... 80
5.2 The Bode Plot ............................................................................................................ 85
5.2.1 The Basic Function .......................................................................................... 85
5.2.2 Gain and Phase Margins ................................................................................. 89
5.3 The Nyquist Plot ....................................................................................................... 93
5.4 The Nichols Plot ....................................................................................................... 95
vi Control System Professional

5.5 The Singular-Value Plot .......................................................................................... 96


6. System Interconnections ............................................................................................... 98
6.1 Elementary Interconnections .................................................................................. 98
6.1.1 Connecting in Series ....................................................................................... 98
6.1.2 Connecting in Parallel ..................................................................................... 103
6.1.3 Closing Feedback Loop ................................................................................... 105
6.2 Arbitrary Interconnections ...................................................................................... 110
6.3 State Feedback .......................................................................................................... 114
6.4 Manipulating a System's Contents ........................................................................ 115
6.5 Using Interconnecting Functions for Controller Design .................................... 119
7. Controllability and Observability ............................................................................. 122
7.1 Tests for Controllability and Observability .......................................................... 122
7.2 Controllability and Observability Constructs ...................................................... 126
7.3 Dual System .............................................................................................................. 130
8. Realizations ...................................................................................................................... 132
8.1 Irreducible (Minimal) Realizations ........................................................................ 133
8.2 Kalman Canonical Forms ........................................................................................ 136
8.3 Jordan Canonical (Modal) Form ............................................................................ 138
8.4 Internally Balanced Realizations ............................................................................ 140
8.5 Dominant Subsystem ............................................................................................... 142
8.6 Pole-Zero Cancellation ............................................................................................ 144
8.7 Similarity Transformation ....................................................................................... 146
8.8 Recovering the Transformation Matrix ................................................................. 148
9. Feedback Control Systems Design ............................................................................ 150
9.1 Pole Assignment with State Feedback .................................................................. 150
9.1.1 Ackermann's Formula .................................................................................... 154
9.1.2 Robust Pole Assignment ................................................................................. 158
9.2 State Reconstruction ................................................................................................. 161
10. Optimal Control Systems Design ............................................................................ 165
10.1 Linear Quadratic Regulator .................................................................................. 166
10.2 Optimal Output Regulator .................................................................................... 171
10.3 Riccati Equations .................................................................................................... 172
10.4 Discrete Regulator by Emulation of Continuous Design ................................. 178
10.5 Optimal Estimation ................................................................................................ 181
10.6 Discrete Estimator by Emulation of Continuous Design ................................. 184
10.7 Kalman Estimator ................................................................................................... 185
10.8 Optimal Controller ................................................................................................. 192
11. Nonlinear Control Systems ....................................................................................... 197
11.1 Local Linearization of Nonlinear Systems .......................................................... 197
Table of Contents vii

11.2 Rational Polynomial Approximations ................................................................. 202


12. Miscellaneous ................................................................................................................ 204
12.1 Ordered Schur Decomposition ............................................................................. 204
12.2 Lyapunov Equations .............................................................................................. 206
12.3 Rank of Matrix ........................................................................................................ 210
12.4 Part Count and Consistency Check ..................................................................... 210
12.5 Displaying Graphics Array Objects Together .................................................... 211
12.6 Systems with Random Elements .......................................................................... 211
References .............................................................................................................................. 214
Index ....................................................................................................................................... 215
1. Getting Started

Control System Professional is a collection of Mathematica programs that extend Mathematica to


solve a wide range of control system problems. Both classical and modern approaches are
supported for continuous-time (analog) and discrete-time (sampled) systems. This guide
describes in detail the new data types introduced in Control System Professional and the new
functions that operate on these data types. Also given are a number of examples of how to use
the Control System Professional functions together with the rest of Mathematica. It is beyond the
scope of this guide to address those innumerable control problems that could be solved
simply with step-by-step application of the usual Mathematica functionality. Nor can the guide
be considered an introduction to control systems theory. Although an attempt was made to
put the new functions into the relevant control theory context, the guide is by no means a
substitute for standard texts such as the ones listed in the References.

The many illustrations, solved examples, and other included features should make it possible
for the interested reader to tackle most of the problems just after reading the corresponding
parts of this guide. However, the guide is definitely not an introduction to Mathematica itself.
To gain the most from this application package, the reader is advised to consult the standard
Mathematica reference by Stephen Wolfram, The Mathematica Book, 4th Edition (Wolfram
Media/Cambridge University Press, 1999).

 1.1 Using the Application for the First Time


Control System Professional is one of many available Mathematica applications and is normally
installed in a separate directory, ControlSystems, in parallel to other applications. If this
has been done at the installation stage, the application package should be visible to Mathemat-
ica without further effort on your part. Then, to make all the functionality of the application
package available at once, you simply load the Kernel/init.m package with the Get or
Needs command.

 This makes Control System Professional available.

In[1]:=  ControlSystems`
2 Control System Professional

If the previous command causes an error message, it is probably due to a nonstandard loca-
tion of the application on your system, and you will have to check that the directory enclosing
the ControlSystems directory is included in your $Path variable. Commands such as

AppendTo[$Path, theDirectoryControlSystemsIsIn]

can be used to inform Mathematica of how to find the application. You may want to add this
command to your init.m file to have it executed automatically at the outset of any of your
Mathematica sessions. The installation card that came with Control System Professional contains
the detailed instructions on the installation procedure.

 1.2 The Structure of the Application


Control System Professional consists of this guide and accompanying packages. The entire guide
is provided as Mathematica notebooks that are accessible from your Help Browser. The note-
books are located in the Documentation directory. The palette included with Control System
Professional can be found in the FrontEnd/Palettes directory.

The following packages are located in the main ControlSystems directory. The packages
listed in the first part of the table typically correspond to separate sections of this guide and
can be loaded into your Mathematica session independently (with or without prior loading of
the Kernel/init.m package). Supplemental packages are listed in the second part of the
table.
1. Getting Started 3

Common.m control systems objects and conversion between them


Conversions.m conversion between
continuous-time and discrete-time domains
Simulations.m investigating system behavior in the time domain
Plots.m classical methods—root locus and frequency response
Connections.m system interconnections and manipulating system contents
Properties.m controllability and observability properties
Realizations.m equivalent and reduced representations of the same system
PoleAssignment.m pole assignment using state feedback
LQdesign.m optimal linear quadratic design of control systems
Linearization.m local linearization of nonlinear systems
Lyapunov.m Lyapunov equations solver
Riccati.m Riccati equations solver
SolversCommon.m common definitions for the
Lyapunov and Riccati equations solvers
SchurOrdered.m ordered Schur decomposition
CycleOptions.m options handling routine
EEPlotsExtensions.m extensions to the Electrical 
Engineering Examples plotting routines
Kernelinit.m initialization file

Packages within Control System Professional .

 1.3 The Control Objects


Most Control System Professional functions operate on special data types, or control objects, that
contain the available information of the control system. These are TransferFunction ,
StateSpace, and ZeroPoleGain. The control objects are freely convertible from one to
another and are easy to pass from one function to another. You can think of control objects as
"active wrappers". On the one hand, they are containers, or wrappers, that conveniently
combine the information about the system in one Mathematica expression. On the other hand,
they work like functions when one is applied to another.
4 Control System Professional

 Let us create an integrator system in the transfer function form.


1
In[2]:= TransferFunction s,  
s
1
Out[2]= TransferFunctions,   
s

 We find a state-space realization of the transfer function object by applying the


StateSpace head to it. In this case, the resultant state-space system contains very
simple matrices A , B , and C . The percentage mark, % refers as usual to the result of
the preceding computation.
In[3]:= StateSpace% 

Out[3]= StateSpace0, 1, 1

 No special functions are needed to convert one control object to another. Simply apply
the desired head to the object you wish to convert.

Converting between control objects.

Along with the structural information about the system, control objects may contain a refer-
ence to the domain (continuous-time or discrete-time) the system is in and/or the period at
which the (discrete-time) system was sampled.

 This finds a discrete-time approximation to the integrator system. Notice that the
result is still the TransferFunction object, in which the discrete-time domain is
indicated by the option Sampled. For the convention for using internal variable in
TransferFunction, refer to Section 3.1 ff.
1
In[4]:= ToDiscreteTimeTransferFunction s,  , Sampled  Period T
s
T
Out[4]= TransferFunctions,   , Sampled  PeriodT 
1s

 This converts the discrete-time object back to continuous time.

In[5]:= ToContinuousTime% 

1
Out[5]= TransferFunctions,   
s
1. Getting Started 5

By default, the system is assumed to be in the continuous-time domain if the Sampled option
is not supplied. You can reverse this if you are mainly dealing with the discrete-time systems.
For a detailed description of the control objects, see Chapter 3.

 1.4 Traditional Notations


When using the notebook front end, you will often find it useful to represent the control
objects in their traditional typeset form. That can be done either by applying the Mathematica
function TraditionalForm or by selecting an expression that contains one or more control
objects and executing the menu command Cell  Convert To  TraditionalForm (or the corre-
sponding keyboard shortcut, as described in the documentation for your copy of Mathematica).
The Control Format palette provided in Control System Professional allows you to switch
between automatic display of results in the traditional form and standard Mathematica output.

 This is a single-input, two-output TransferFunction object in Traditional


Form. Since the object is believed to be in the continuous-time domain, the variable 
is used. The superscripted letter  distinguishes the result from a regular matrix.


1 1
In[6]:= 
system  TransferFunction s,   ,   
TraditionalForm
 s s Α
Out[6]//TraditionalForm=

  
1
  
 
 1 
 
  
 Α 

 This is the TraditionalForm of the discretized object. It displays using the


variable . The subscript gives the value of the sampling period.
In[7]:= ToDiscreteTime% , Sampled  Period 2 Simplify TraditionalForm

Out[7]//TraditionalForm=

 
2
  
   1 
 
 1  2 Α 
  
 Α  2 Α  Α 2
6 Control System Professional

 This is a possible state-space realization of the above system in TraditionalForm.


The superscripted letter  identifies the StateSpace object, while the small
subscripted bullet character denotes the continuous-time domain.
In[8]:= StateSpacesystem TraditionalForm

Out[8]//TraditionalForm=
0 1 0 
 
 0 Α 1 
 
 
 Α 1 0 
 
 
 0 1 0 •

Additionally, Control System Professional provides the function EquationForm that allows
you to display the StateSpace objects as the familiar state-space equations. These have the
conventional form for both continuous-time and discrete-time systems. Note that Equation
Form disregards the value of the sampling period.

 This represents the above StateSpace object as a pair of matrix state-space


equations.
In[9]:= % EquationForm

Out[9]//EquationForm=
 0 1   0
     
 0 Α   1
 Α 1 
  
 0 1

 For the discretized system, the state-space equations are displayed as difference
rather than differential equations.
In[10]:= ToDiscreteTime% , Sampled  Period Τ Simplify EquationForm

Out[10]//EquationForm=
Α Τ  Α Τ  1
1  Α Τ
 1     
    Α2 
  1   Α    

Α Τ
  1  Α Τ 
0    
 Α 
 Α 1 
  
 0 1
1. Getting Started 7

 Here is the same system in TraditionalForm.

In[11]:= % TraditionalForm

Out[11]//TraditionalForm=

1  Α Τ
 1  Α Τ  Α Τ  1 
  
 
 Α Α2 
 
 1  Α Τ 
 0 Α Τ  
 
 Α 
 
 Α 
 1 0 
 
0 1 0 Τ

Both TraditionalForm and EquationForm provide convenient formatting. Neither


changes the internal representation of the objects. In this respect, the functions behave much
like OutputForm or MatrixForm (and all other members of the $OutputForms list).

 Despite different formatting, the previous result is still the StateSpace object.

In[12]:= %

1  Α Τ
Out[12]= StateSpace1,  , 0, Α Τ ,
Α
1  Α Τ  Α Τ 1  Α Τ
 2 ,   , Α, 1, 0, 1, Sampled  PeriodΤ 
Α Α

Typically, you can freely copy, paste, and edit the typeset representations of control objects.
When editing, however, exercise caution to prevent destruction of the invisible tags that allow
an unambiguous interpretation of the object in typeset form. As a rule of thumb, you will
typically find it safe to select exactly the part of expression that you want to edit or to drag
across the entire object and choose Edit  Copy when you want to copy the object as a whole
(or, better yet, copy the entire cell that contains the control object).

 1.5 The Control Format

SetControlFormat display control objects and


matrices in TraditionalForm
SetStandardFormat restore the standard Mathematica output format

Two output modes.

Instead of applying TraditionalForm to every control object individually, you can switch
to displaying control objects in traditional form automatically. This can be done by issuing the
8 Control System Professional

command SetControlFormat[] or by simply clicking the "Control Format" button in the


Control Format palette, which is available under the Palettes submenu of the File menu (see
Figure 1.1). Additionally, SetControlFormat[] turns on the TraditionalForm display
for all matrices and some expressions that involve control objects and matrices. You can revert
to the standard Mathematica output format by issuing the command SetStandardFormat[]
or by clicking the "Standard Format" button in the Control Format palette. The SetControl
Format function sets an appropriate value for the built-in global variable $PrePrint. Set
StandardFormat restores the previous setting of that variable, if any.

Figure 1.1. Setting the display of control objects in TraditionalForm and matrices in MatrixForm.

In this guide we routinely use the control format, but switch to the standard one as needed to
highlight the underlying standard-form representation of the object in question. As the two
formats look quite different and can be easily distinguished, no notice is given in the text to
identify them. If you reevaluate the online documentation and your results appear in the
different format, simply switch to the appropriate format using the Control Format palette or
convert the individual cell to the appropriate format using the menu choice or the correspond-
ing keyboard shortcut.

 At this point, we switch to the control format. As a result, the matrix displays in the
traditional form and so does the StateSpace object.
In[13]:= Tablei  j, i, 2, j, 3

 2 3 4 
Out[13]=  
 3 4 5

In[14]:= StateSpace0, 1, 1

0 1 
Out[14]=  
 1 0 •
1. Getting Started 9

 1.6 The Notation for the Imaginary Unit


Mathematica uses the letter I ( in the notebook front end) for the imaginary unit 1 , which
is not the standard notation in the control literature. However, it is quite easy to set things up
differently. Recall that the expression 2 + 3 I, for example, is a shortcut for Co mplex[ 2, 3 ].
Therefore, to change the appearance of complex numbers, it is sufficient to change the format-
ting rule for Complex, as it is done in the following few lines. You may want to add an analo-
gous definition to your init.m file if you prefer an alternative to the built-in notation.

 This changes the way complex numbers appear on the screen.

In[15]:= 
UnprotectComplex;
" y;
FormatComplexx_, y_ : x  "
ProtectComplex;


 From now on, 1 appears as the letter .



In[16]:= 2  3 1

Out[16]= 23 

 1.7 Numericalizing for Speed


A word of common sense is in order before you start working with the application. As is the
case with many built-in Mathematica routines, the Control System Professional functions, unless
stated otherwise in this guide, accept both exact and inexact input (or a mix of the two) and
handle them appropriately, attempting to give an exact answer to a problem involving an
exact input. You do not have to worry about choosing the right algorithm; it is done in trans-
parent fashion. However, you do have to realize that the algorithms invoked with the two
types of input can be quite different, as can the computing time, with the exact computation
sometimes being considerably more time consuming. You are therefore advised, whenever
possible, to make sure that at least a part of the input contains an inexact expression to pre-
vent running into a long exact calculation unnecessarily.
10 Control System Professional

 Consider, for example, a random 4 4 exact matrix.

In[17]:= ArrayRandomInteger &, 4, 4

 1 0 0 0
 
 0 0 0 1 
Out[17]=  
 1
 0 1 0 

1 1 0 1

 These are its exact eigenvalues together with the time taken by the CPU to compute
the result.
In[18]:= Eigenvalues%  Timing

1
1

Out[18]= 0.1 Second, 1, 1,  1  5 ,  1  5 
2 2

 If an inexact result suffices for the particular purpose, considerable savings in


computing time can be realized just by using inexact input at the outset. (The double
percentage mark, %%, is the familiar reference to the result of the next-to-previous
computation.)
In[19]:= EigenvaluesN %%  Timing

Out[19]= 0. Second, 1.61803, 1., 1., 0.618034

 1.8 Evaluating Examples in This Guide


When evaluating examples in this guide on your computer system, you may sometimes find
that your results differ somewhat from the documentation. Differences in symbolic expres-
sions may come from different heuristic rules employed in different versions of Mathematica;
they usually vanish after a simplification. Small numerical residuals may be different because
of the different machine arithmetic. Further, some numerical results may be different if a
numerical algorithm, also based on the machine arithmetic, selects another possible value
from the universe of equivalent values. In such cases, you can usually confirm that you are
still getting a correct result by testing some property of the resulting system (e.g., eigenvalues
of the closed loop system after a pole placement). Finally, the concrete values after random
distortions will, of course, be different in your experiments.
2. Introduction: Extending Mathematica to Solve Control
Problems

In this chapter, using the classical example of controlling an inverted pendulum, we learn
how to formulate a control problem in Mathematica, solve the problem using the Control System
Professional functionality, and analyze the results using the standard Mathematica functions.
We will see that, by being seamlessly incorporated with the rest of Mathematica, this applica-
tion package provides a convenient environment for solving typical control engineering
problems. Additional solved examples will be given in later chapters when individual func-
tions are discussed.

The inverted pendulum shown in Figure 2.1 is a massive rod mounted on a cart that moves in
a horizontal direction in such a way that the rod remains vertical. The vertical position of the
rod is unstable, and the cart exerts a force to provide the attitude control of the pendulum.
This or a similar model is considered in many textbooks on control systems. We will follow
Brogan (1991), pp. 590–92.

xc

Figure 2.1. Inverted pendulum.


12 Control System Professional

Let us obtain a mathematical model for the system. Assume that the length of the pendulum is
L , and its mass and the moment of inertia about its center of gravity are m and J , respectively.
The mass of the cart is M . Then, summing the forces applied to the pendulum in horizontal
and vertical directions (Figure 2.2a), we have

 (2.1)
Fx  mxc


Fy  mg  myc (2.2)

where Fx and Fy are the components of the reaction force at the support point, and
xc  X  L  2sinΘ and yc  L  2cosΘ are the horizontal and vertical displacements of the
center of gravity of the pendulum; xc depends on the horizontal displacement X of the cart.
Summing all the moments around the center of gravity of the pendulum gives the dynamical
equation

Fy L Fx L 
 sinΘ   cosΘ  JΘ (2.3)
2 2
where J  m L2  12 , which corresponds to the case of uniform mass distribution along the
pendulum.

Fx

_fy _fy
2 2
Fy Fy
mg
Mg
fx

Fx
a b

Figure 2.2. Forces applied to the rod (a) and the cart (b) of the pendulum.

Finally, for the cart we have (see Figure 2.2b)

 (2.4)
fx  Fx  MX
2. Introduction: Extending Mathematica to Solve Control Problems 13

where fx is the input force applied to the wheels.

Translating the model into Mathematica is straightforward.

 This is the first equation. We will keep it as eq1 for future reference.

In[1]:= eq1  Fx  m xc t

Out[1]= Fx  m xc t

 The next equation translates almost verbatim as well.

In[2]:= eq2  Fy  m g  m yc t

Out[2]= Fy  g m  m yc t

 This is the dynamical equation.


1 1
In[3]:= eq3   Fy L Sin Θt   Fx L CosΘt  J Θ t
2 2
1 1
Out[3]=   Fx L CosΘt   Fy L SinΘt  J Θ t
2 2

 This gives the definition for the moment of inertia J.

m L2
In[4]:= J  
12
L2 m
Out[4]= 
12

 Here is the last equation.

In[5]:= eq4  fx  Fx  M X  t

Out[5]= fx  Fx  M X t

 We now define the horizontal displacement xc of the pendulum through the


displacement of the cart X and the angle Θ. As the two depend on time t, then so
does xc. The pattern notation t_ on the left-hand side makes the formula work for
any expression t.
1
In[6]:= xct_  Xt   L Sin Θt
2
1
Out[6]=  L SinΘt  Xt
2
14 Control System Professional

 Here is the corresponding assignment to the vertical displacement yc.


1
In[7]:= yct_   L CosΘt
2
1
Out[7]=  L CosΘt
2

Notice that we have defined eq1 … eq4 as logical equations (using the double equation mark
==) and the expressions for xc and yc as assignments to these symbols (using the single =). We
then have the benefit of not solving the differential equation against X t , but simply elimi-
nating it algebraically along with the other variables we no longer need.

 Eliminate takes the list of equations and the list of variables to eliminate. The
result is a nonlinear differential equation between the input force fx and the angular
displacement Θ and its first and second derivatives. It is solvable for Θ t .
In[8]:= Eliminateeq1, eq2, eq3, eq4, Fx, Fy, X  t

Out[8]= L m 6 g m SinΘt  6 g M SinΘt  3 L m CosΘt SinΘt Θ t2 


L m Θ t  L M Θ t  3 L M CosΘt2 Θ t 
3 L m SinΘt2 Θ t  3 L M SinΘt2 Θ t  6 fx L m CosΘt

 Solve returns a list of rules that give generic solutions to the input equation.

In[9]:= Solve% , Θ t

Out[9]= Θ t  3 2 fx CosΘt  2 g m SinΘt 


2 g M SinΘt  L m CosΘt SinΘt Θ t2 
L m  M  3 M CosΘt2  3 m SinΘt2  3 M SinΘt2 

 We have, in fact, just a single rule and we extract it from the lists.

In[10]:= sln  % 1, 1

Out[10]= Θ t  3 2 fx CosΘt  2 g m SinΘt 


2 g M SinΘt  L m CosΘt SinΘt Θ t2 
L m  M  3 M CosΘt2  3 m SinΘt2  3 M SinΘt2 
2. Introduction: Extending Mathematica to Solve Control Problems 15

As our next step, we create a state-space model of the system and linearize it for small pertur-
bations near the equilibrium position Θ  0. Then, based on the linearized model, we design
the state feedback controller that attempts to keep the pendulum in equilibrium. Finally, we
carry out several simulations of the actual nonlinear system governed by the controller and
see what such a controller can and cannot do.

The nonlinear state-space model of the system will be presented in the form

x  fx, u
(2.5)
y  hx, u

where Θ and Θ constitute the state vector x , fx is the only component of the input vector u ,
and Θ makes up the output vector y .

 This creates the state vector in Mathematica.

In[11]:= x  Θt, Θ t;

 This sets the input and output vectors.

In[12]:= u  fx; y  Θt;

To obtain f and h in Eq. (2.5), we observe that their Mathematica equivalents f and h are
simply the derivative D[x, t] and the output vector y expressed via the state and input
variables.

 The expression for the derivative contains an undesirable variable, Θ t , which is
among neither state nor input variables.
In[13]:= Dx, t

Out[13]= Θ t, Θ t

 The replacement rule stored as sln helps to get rid of Θ t .

In[14]:= f  % . sln

Out[14]= Θ t, 3 2 fx CosΘt  2 g m SinΘt 


2 g M SinΘt  L m CosΘt SinΘt Θ t2 
L m  M  3 M CosΘt2  3 m SinΘt2  3 M SinΘt2 
16 Control System Professional

 The expression for function h is trivial.

In[15]:= h  y

Out[15]= Θt

So far we have used the built-in Mathematica functions. Now it's time to make accessible the
library of functions provided in Control System Professional.

 This loads the application.

In[16]:=  ControlSystems`

For most Control System Professional functions, the input state-space model must be linear.
Therefore, our first task will be to linearize the model, that is, represent it in the form

x  Ax  Bu
(2.6)
y  Cx  Du
This is the purpose of the function Linearize, which, given the nonlinear functions f and h
and the lists of state and input variables, supplied together with values at the nominal point
(the point in the vicinity of which the linearization will take place), returns the control object
StateSpace[a, b, c, d], where matrices a, b, c, and d are the coefficients A, B, C , and D
in Eq. (2.6).

 This performs the linearization.

In[17]:= ss  Linearizef, h , Θt, 0, Θ t, 0, fx, 0

3 2 g m  2 g M
Out[17]= StateSpace 0, 1,   , 0

,
L m  4 M
6
0,  

, 1, 0, 0


L m  4 M

 Mapping the built-in Mathematica function Factor onto components of the


state-space object simplifies the result somewhat. (Here /@ is a shortcut for the Map
command.)
In[18]:= Factor  %

6 g m  M 6
Out[18]= StateSpace 0, 1,  , 0

, 0,  

, 1, 0, 0


L m  4 M L m  4 M
2. Introduction: Extending Mathematica to Solve Control Problems 17

 TraditionalForm often gives a more compact representation for control objects.

In[19]:= TraditionalForm% 

Out[19]//TraditionalForm=

 0 1 0

 6 g m  M 6
  0  

 L m  4 M L m  4 M 


 1 0 0

Now let us design a state feedback controller that will stabilize the pendulum in a vertical
position near the nominal point. One way to do this is to place the poles of the closed-loop
system at some points p1 and p2 on the left-hand side of the complex plane.

 In this particular case, Ackermann's formula (see Section 9.1) is used. The result is a
matrix comprising the feedback gains.
In[20]:= k  StateFeedbackGainsss, p1, p2

1 1
Out[20]=  6 g m  6 g M  L m p1 p2  4 L M p1 p2,  L m  4 M p1  p2

6 6

Note that we were able to obtain a symbolic solution to this problem and thus see immedi-
ately that, for example, only the first gain depends on g and so would be affected should our
pendulum get sent to Mars (and the change would be linear in g ). We also see that the first
gain depends on the product of pole values, the second gain on their sum, and so on.

To check if the pole assignment has been performed correctly, we can find the poles of the
closed-loop system, that is, the eigenvalues of the matrix A  BK.

 This extracts the matrices from their StateSpace wrapper.

In[21]:= a  ss1; b  ss2;

 We see that the eigenvalues of the closed-loop system are indeed as required.

In[22]:= Eigenvaluesa  b.k

Out[22]= p1, p2

With Control System Professional, we can also design the state feedback using the optimal
linear-quadratic (LQ) regulator (see Chapter 10). This approach is more computationally
intensive, so it is advisable to work with inexact numeric input. For convenience in presenting
results, we switch to the control print display (Section 1.5).
18 Control System Professional

 This is the particular set of numeric values (all in SI) we will use.

In[23]:= numericValues   m 2., M 8., L 1., g 9.8, p1 4., p2 5.

Out[23]= m  2., M  8., L  1., g  9.8, p1  4., p2  5.

 Here our system is numericalized.

In[24]:= nss  ss . numericValues


 0 1 0

Out[24]=  17.2941 0 0.176471

 1 0 0

 Let Q and R be identity matrices.

In[25]:= Q  IdentityMatrix2

 1 0
Out[25]= 
 0 1

In[26]:= R  1

Out[26]= 1

 LQRegulatorGains solves the Riccati equations and returns the corresponding


gain matrix.
In[27]:= LQRegulatorGainsnss, Q, R 

Out[27]=  196.005 47.1422 

 Here are the poles our system will possess when we close the loop.

In[28]:= Eigenvaluesa  b.% . numericValues

Out[28]= 4.24526, 4.07396

Let us make some simulations of the linearized system as well as the original, nonlinear
system stabilized with one of the controllers we have designed—say the one obtained with
Ackermann's formula. We start with the linearized system and compute the transient
response of the system for the initial values of Θ0 of 0.5, 1, and 1.2, assuming in all cases that

Θ0  0 . The same initial conditions will then be used for the nonlinear system, and the results
will be compared.
2. Introduction: Extending Mathematica to Solve Control Problems 19

 Here is the list of initial conditions for Θ.

In[29]:= Θ0  .5, 1., 1.2

Out[29]= 0.5, 1., 1.2

 This is the linearized system after the closing state feedback. The function State
FeedbackConnect is described in Chapter 6 together with other utilities for
interconnecting systems.
In[30]:= StateFeedbackConnectss, k  Simplify



0 1 0

 6
Out[30]=  p1 p2 p1  p2  

 L m  4 M

 1 0 0

To compute how the initial condition in Θ decays in the absence of an input signal, we can use
OutputResponse, which is one of the functions defined in Chapter 4.

 In this particular case, the input arguments to OutputResponse are the system to
be analyzed, the input signal (which is 0 for all t), the time variable t, and the initial
conditions for the state variables supplied as an option. The initial value for Θ is
denoted as angle.
In[31]:= OutputResponse% , 0, t, InitialConditions angle, 0

angle  p2 t p1  p1 t p2
Out[31]= 


p1  p2
20 Control System Professional

 Here is the plot of the previous function for the chosen values Θ0 . We store it as
plot for future reference.
In[32]:= plot  PlotEvaluate% . numericValues . angle Θ0 ,
t, 0, 4, PlotStyle RGBColor1, 0, 0;
1.2

0.8

0.6

0.4

0.2

1 2 3 4

The case of actual nonlinear system stabilized with the linear controller is more interesting,
but requires some work on our part. We note that when the control loop is closed, the input
variable—the force fx applied by the motor of the cart—tracks changes in state variables Θt

and Θt.

 First we prepare the input rules. As we have only one input, there is only one rule in
the list.
In[33]:= feedbackRules  Thread u k.x . numericValues

Out[33]= fx  211.333 Θt  51. Θ t

 Recall that we store the description of our nonlinear system as sln.

In[34]:= sln

Out[34]= Θ t  3 2 fx CosΘt  2 g m SinΘt 


2 g M SinΘt  L m CosΘt SinΘt Θ t2 
L m  M  3 M CosΘt2  3 m SinΘt2  3 M SinΘt2 
2. Introduction: Extending Mathematica to Solve Control Problems 21

 Now we numericalize the rule, substitute the feedback rules, and, to convert the rule
to an equation, apply the head Equal to it (@@ is the shorthand form of the Apply
function). The resultant differential equation is labeled de.
In[35]:= de  Equal  sln . numericValues . feedbackRules

Out[35]= Θ t  3. 196. SinΘt  2. CosΘt SinΘt Θ t2 


2 CosΘt 211.333 Θt  51. Θ t
10.  24. CosΘt2  30. SinΘt2 

 This solves the differential equation with the initial conditions for every value in the
list Θ0 one by one and returns a list of solutions. The time t is assumed to vary from
0 to 4 seconds.
In[36]:=
0  NDSolvede, Θ0  #, Θ 0  0, Θ, t, 0, 4 &  Θ0

Out[36]= Θ  InterpolatingFunction0., 4.,


,
Θ  InterpolatingFunction0., 4.,
,
Θ  InterpolatingFunction0., 4.,


 In several graphs that follow, we show the results for Θ0  0 as a solid line, for
Θ0  1 as a dashed-dotted one, and for Θ0  1.2 as a dashed line. This changes the
Plot options to reflect that convention and adjusts a few other nonautomatic values
for plot options.
In[37]:= SetOptionsPlot, PlotStyle Thickness.001,
Dashing .025, .0075, .0075, .0075, Dashing .01, .01, Frame
Automatic, Automatic, None, None, FrameLabel "Time s ", None;

 The results for Θ are now presented graphically. We can see that the controller
succeeds in driving the pendulum to its equilibrium position for all three initial
displacements. The plot is stored as plot1.
In[38]:= plot1  PlotEvaluateΘt .
0 , t, 0, 4, PlotLabel "Θ radian ";

Θ radian
1.2
1
0.8
0.6
0.4
0.2
0
0 1 2 3 4
Time s
22 Control System Professional

 We can also see that, once the angle Θ[t] has come to zero, the derivative Θ t
vanishes as well. This means that the pendulum is not about to oscillate around its
equilibrium position, at least not when driven from the displacements we are
considering for now.
In[39]:= PlotEvaluateΘ t .
0 , t, 0, 4, PlotLabel "Θ' radian s ";

Θ' radians
0
-0.2
-0.4
-0.6
-0.8
-1
-1.2
0 1 2 3 4
Time s

 Here is the plot of input force versus time.

In[40]:= PlotEvaluatefx . feedbackRules .


0 , t, 0, 4,
PlotLabel "Input Force Newton ", PlotRange All;

Input Force Newton


250

200

150

100

50

0
0 1 2 3 4
Time s
2. Introduction: Extending Mathematica to Solve Control Problems 23

 Finally, we compare the graphs of Θ for the nonlinear and linear systems and see
that the only case of smallest initial displacement is treated adequately by the linear
model.
In[41]:= Show plot1, plot;

Θ radian
1.2
1
0.8
0.6
0.4
0.2
0
0 1 2 3 4
Time s

The transient responses suggest that our linear feedback is not sufficiently prompt in reacting
to moderate and large initial displacements Θ0, and that may cause problems for still larger
angles. The case Θ0  1.2 rad is almost critical. Indeed, for a slightly larger displacement,
Θ0  1.25 rad, the system becomes hard to control.

 We solve the same equation for another set of initial conditions.

In[42]:= ΘBig  NDSolvede, Θ0  1.25, Θ 0  0, Θ, t, 0, 4, MaxSteps 1000

Out[42]= Θ  InterpolatingFunction0., 4.,




 In the following graphs, we will plot the results for Θ0  1.25 as a solid line and one
of our previous curves (namely, Θ0  1.2 ) as a dashed line. This sets the new
options.
In[43]:= SetOptionsPlot, PlotStyle Thickness.001, Dashing .01, .01;
24 Control System Professional

 We find that the pendulum still could be driven from Θ0  1.25 to Θ  0 , but now it
oscillates badly around the equilibrium point.
In[44]:= PlotEvaluateΘt . ΘBig ,
0 3, t, 0, 4, PlotLabel "Θ radian ";

Θ radian
6
4
2
0
-2
-4
-6
0 1 2 3 4
Time s

Of course, the cart in our particular model of the pendulum (as shown in Figure 2.1) would
not allow the pendulum to rotate in circles, but, for the sake of argument, we will assume that
it would.


 The variations in Θ become more complex and far more intense.

In[45]:= PlotEvaluateΘ t . ΘBig ,


0 3,
t, 0, 4, PlotLabel "Θ' radian s ";
Θ' radians
30
20
10
0
-10
-20
-30
0 1 2 3 4
Time s
2. Introduction: Extending Mathematica to Solve Control Problems 25

 This is the force the motor must exert to maintain the process.

In[46]:= PlotEvaluatefx . feedbackRules . ΘBig ,


0 3,
t, 0, 4, PlotLabel "Input Force Newton ", PlotRange All;

Input Force Newton

2000

1000

-1000

-2000

0 1 2 3 4
Time s

The real actuator may not be up to the task. If the maximum force the motor can provide is,
say, 1000 N, and the feedback saturates at that limit, the controller fails to balance the pendu-
lum.

 To model this situation, we create a clip function.

In[47]:= clip  IfAbs# 1000., #, Sign # 1000. &

Out[47]= IfAbs#1 1000., #1, Sign#1 1000. &

 Here is how it works: everything beyond the interval from 1000 to 1000 gets cut
off.
In[48]:= clip  1001, 999, 999, 1001

Out[48]= 1000., 999, 999, 1000.

 We use clip to saturate the feedback.

In[49]:= feedbackLtd  MapAtclip, feedbackRules, 1, 2

Out[49]= fx  IfAbs211.333 Θt  51. Θ t 1000.,


211.333 Θt  51. Θ t, Sign211.333 Θt  51. Θ t 1000.
26 Control System Professional

 This is the new differential equation for Θ under the saturated feedback.

In[50]:= de1  Equal  sln . numericValues . feedbackLtd

Out[50]= Θ t 


3. 2 CosΘt IfAbs211.333 Θt  51. Θ t 1000., 211.333 Θt 
51. Θ t, Sign211.333 Θt  51. Θ t 1000. 
196. SinΘt  2. CosΘt SinΘt Θ t2 
10.  24. CosΘt2  30. SinΘt2 

 This solves it.

In[51]:= ΘBig1  NDSolvede1, Θ0  1.25, Θ 0  0, Θ, t, 0, 4, MaxSteps 1000

Out[51]= Θ  InterpolatingFunction0., 4.,





 Finally, we plot the state response—for Θ as a solid line and for Θ as a dashed one. It
is clear that the controller fails to return the pendulum to its equilibrium position.
In[52]:= PlotEvaluateΘt, Θ t . ΘBig1 , t, 0, 4,
PlotStyle Thickness.001, Dashing .05, .01, Thickness.001,
PlotRange All, PlotLabel "State Response";

State Response
20
10
0
-10
-20
-30
-40
0 1 2 3 4
Time s
3. Description of Dynamic Systems

Control System Professional deals with state-space and transfer function models of
continuous-time (analog) and discrete-time (sampled) systems. The transfer function represen-
tations can be in rational polynomial or zero-pole-gain form. This chapter introduces the
available data types and the means to convert between them.

 3.1 Transfer Function Representations


The basic form for representing transfer function matrices is the TransferFunction data
structure. TransferFunction in many respects behaves like Function, the built-in Mathe-
matica pure function. Like Function, TransferFunction can have a formal parameter,
"variable", and is capable of operating on any Mathematica expression. Unlike Function,
TransferFunction currently accepts at most one formal parameter and does not accept the
list of attributes, but it does accept options.

TransferFunctionm a transfer function as a rational 


polynomial matrix m of a formal 
parameter # that behaves as a pure function
TransferFunctionvar, m a transfer function of a formal parameter var

Transfer function representation as a pure function.

 Load the application.

In[1]:=  ControlSystems`

 This is the transfer function representation of a two-input, one-output system. The


TransferFunction object comprises a variable and a matrix in that variable.
2 var
In[2]:= TransferFunction var,   ,  
1  var2 var  1
2 var
Out[2]= TransferFunctionvar,   ,  
1  var2 1  var
28 Control System Professional

 Supplying the variable to this function leads to a matrix in that variable.

In[3]:= % s

2 s
Out[3]=  
 ,  
1  s2 1  s

 If a particular numeric frequency is supplied, the value of the transfer matrix at that
frequency is obtained.
In[4]:= %%  10.

Out[4]= 0.020202, 0.990099  0.0990099 

 We can name the internal variable whatever we please or drop it altogether and still
have a mathematically identical object.
1
In[5]:= TransferFunction   
#
1
Out[5]= TransferFunction  
#1

 Without the formal parameter, TransferFunction behaves as a pure function in


#.
In[6]:= % s

1
Out[6]=   
s

TransferFunction deals with multiple-input, multiple-output (MIMO) systems. Scalar, or


single-input, single-output (SISO), transfer functions are "upgraded" to the matrix representa-
tion automatically.

 A scalar transfer function is represented as a 1  1 transfer matrix.


1
In[7]:= TransferFunction   
#
1
Out[7]= TransferFunction  
#1

It is often useful to factor the elements of a transfer matrix so that the zeros and poles of
individual elements become apparent. The factored form can be obtained by using the func-
tion FactorRational. The opposite function is ExpandRational, which expands the
individual numerators and denominators of transfer matrix elements.
3. Description of Dynamic Systems 29

FactorRationaltransferfunction
represent the transferfunction object in factored form

ExpandRationaltransferfunction
represent the transferfunction 
object in expanded form
Converting transfer function objects to standard forms.

 This is some rational polynomial transfer function.

2 6  5 s  s2
In[8]:= TransferFunction s,   ,  
1  s2 s4  1
2 6  5 s  s2
Out[8]= TransferFunctions,  
 ,  
1  s2 1  s4

 This factors the numerators and denominators of all elements.

In[9]:= FactorRational% 

2 3  s
2  s

Out[9]= TransferFunctions,   , 


 
  s
  s
1  s
  s
  s
1  s

 This expands the numerators and denominators of the previous result.

In[10]:= ExpandRational% 

2 6  5 s  s2
Out[10]= TransferFunctions,  
 ,  
1  s2 1  s4

Both FactorRational and ExpandRational can be viewed as means to transformation


arbitrary TransferFunction objects into their standard forms, whereas TransferFunc
tion itself behaves merely as a wrapper with respect to polynomial expressions.

 By itself, TransferFunction does not change polynomial expressions in a transfer


function matrix.
1 1
In[11]:= TransferFunction s,    
s s 1
1 1
Out[11]= TransferFunctions,     
1  s s
30 Control System Professional

 However, ExpandRational and FactorRational do convert arbitrary rational


polynomial matrices to the standard forms.
In[12]:= ExpandRational% 

1  2 s
Out[12]= TransferFunctions,   
s  s2

In[13]:= FactorRational%% 

2  12  s

Out[13]= TransferFunctions,  


 
1  s
s

The coefficients of the factored form of the individual transfer matrix elements (i.e., zeros,
poles, and gains) can be stored using the special data structure ZeroPoleGain. To allow
complete restoration of the transfer function object from its zero-pole-gain equivalent, Zero
PoleGain may optionally contain the variable used in the transfer function.

ZeroPoleGainzeros, poles, gains


a collection of matrices representing the zeros,
poles, and gains of the elements of a transfer matrix

ZeroPoleGainvar, zeros, poles, gains


use  variable var in the 
descendent TransferFunction objects
ZeroPoleGain data structure.

Structurally, both zeros and poles are matrices of vectors of the corresponding coefficients,
whereas gains is just a matrix of coefficients. All three of these matrices and the parent transfer
matrix have the same dimensions down to the second level.

 Here is another transfer function.


2 s
In[14]:= tf  TransferFunction s,   ,  
1  s2 s 1
2 s
Out[14]= TransferFunctions,  
 ,  
1  s2 1  s
3. Description of Dynamic Systems 31

 This picks up its zeros, poles, and gains. Notice that there are no finite zeros in the
first element of the transfer matrix, so the corresponding list of zeros is empty.
In[15]:= ZeroPoleGain % 

Out[15]= ZeroPoleGains, , 0, , , 1, 2, 1

 Applying TransferFunction to the ZeroPoleGain object brings out the transfer


function in its factored form.
In[16]:= TransferFunction % 

2 s
Out[16]= TransferFunctions,   ,  
  s
  s
1  s

 The same result can be arrived at directly.

In[17]:= FactorRationaltf

2 s
Out[17]= TransferFunctions,   ,  
  s
  s
1  s

Like TransferFunction objects, ZeroPoleGain objects need not have a named variable. If
a ZeroPoleGain object does not have one, neither will the descendent transfer function.

 This 1 1 system does not have finite zeros, has a single pole at the origin, and has
a unit gain. Therefore, it represents an ideal integrator.
In[18]:= ZeroPoleGain , 0, 1

Out[18]= ZeroPoleGain, 0, 1

 Here is its transfer function. As no variable was used in the parent ZeroPoleGain,
none appears here.
In[19]:= TransferFunction % 

1
Out[19]= TransferFunction  
#1

It is worth emphasizing that the variable in the TransferFunction and ZeroPoleGain


objects is a formal parameter and has nothing to do with distinguishing Laplace and
z -transform domains (which is what the Sampled option is for; see Section 3.3). The variable
may simply be omitted or easily renamed if desired using the built-in Mathematica functions.
Again, renaming does not change the domain of the object; to transform the system from one
domain to another, use either ToDiscreteTime (Section 3.5) or ToContinuousTime (Sec-
32 Control System Professional

tion 3.7), whichever is appropriate. Note, however, that interpretation of the TransferFunc
tion object in TraditionalForm obeys a different convention and does take the variable
into account (see Section 3.4).

 This is a transfer function in the variable var.


1
In[20]:= TransferFunction var,  
1  var2
1
Out[20]= TransferFunctionvar,   
1  var2

 This changes the variable to z. No change of domain has occurred.

In[21]:= % . var  z

1
Out[21]= TransferFunctionz,  
 
1  z2

Two additional utility functions, Zeros and Poles, return zeros and poles of transfer func-
tions for control objects. In the case of ZeroPoleGain objects, these functions simply extract
the relevant parts from the data structure.

Zerossystem gives the matrix of zeros of the 


transfer function corresponding to system
Polessystem gives the matrix of poles of the 
transfer function corresponding to system

Computing zeros and poles separately.

Both TransferFunction and ZeroPoleGain, as well as the head StateSpace described


in Section 3.2, work as "active wrappers". This means that, on the one hand, they keep system
components together allowing the system as a whole to be conveniently passed from one
function to another. They can also be used for conversion between the data structures when
one wrapper is applied over another.
3. Description of Dynamic Systems 33

TransferFunctionstatespace
find the TransferFunction object that
corresponds to the StateSpace object statespace

TransferFunctionstatespace, ReductionMethod  method


use the specified method for conversion
Converting from state-space to transfer function representation.

The straightforward, but computationally expensive, way of finding the transfer function
matrix of a state-space realization is based on the formula

Hs  C s I  A1 B  D (3.1)

The method involves computing the inverse of the matrix s I  A1 (the so-called resolvent
matrix) and is accessible by setting the option value ReductionMethodInverse . A better
alternative is often to scan the determinant expansion formula for a single-input, single output
system over all possible input-output pairs of a multi-input, multi-output system (cf. Kailath
(1980), Appendix A)

 s I  A  b j ci   dij  1  s I  A 
hij s  


 (3.2)
sI  A
Here the notation    stands for the determinant of the matrix, b j and ci are the column- and
row-vector components of the matrices B and C that correspond to the given input-output
pair, dij is the corresponding scalar part of the matrix D, and hij is the same for the transfer
function matrix H. This method is available under the option value DeterminantExpan
sion, which is the default value of the option ReductionMethod. Although the above
formulas refer to the continuous-time case, the implemented algorithms are equally applicable
to discrete-time systems.

For conversion and most other purposes, the elements of the transfer matrix must be rational
polynomials. However, nonrational polynomial terms can also be handled in some cases,
notably in some frequency response functions (Chapter 5) and system interconnection func-
tions (Chapter 6).

 3.2 State-Space Representations


Continuous-time state-space systems (Figure 3.1)
34 Control System Professional

x t  Axt  But


(3.3)
yt  Cxt  Dut
and discrete-time state-space systems (Figure 3.2)

xk  1  Axk  Buk


(3.4)
yk  Cxk  Duk
are represented by the StateSpace data structure; this guide refers to component matrices
using the same symbols, A , B, C , and D . Here A is the state (or evolution) matrix, B is the
input (or control) matrix, C is the output (or observation) matrix, and D is the direct transmission
(or feedthrough) matrix. Keeping the same notation for continuous- and discrete-time systems
is common in the literature and allows sharing many concepts and algorithms that are essen-
tially identical. (It is also common to use F, G, H, and J instead of A , B, C , and D for
continuous-time systems and  and  instead of A and B in the discrete-time case.)

To distinguish between the two types of systems, the option Sampled is introduced in
Section 3.3.

StateSpacea, b state-space object comprising two matrices, a and b


StateSpacea, b, c state-space object comprising matrices a,
b, and c, which assumes that the 
direct transmission term matrix d is zero
StateSpacea, b, c, d state-space object comprising matrices a, b, c, and d

State-space data structure.

ut .  yt
 xt xt 
B  C


Figure 3.1. State-space model of a continuous-time system.


3. Description of Dynamic Systems 35

uk  xk1 xk   yk


B Delay C


Figure 3.2. State-space model of a discrete-time system.

The StateSpace objects can contain as few as two matrices a and b, but for most functions, at
least matrix c and optionally d are required too. If matrices c and d are absent, no assumptions
are made about them; if only matrix d is absent, it is routinely assumed to be a zero matrix.
The truncated StateSpace[a, b] representation is, of course, of limited value, but contains
all the necessary information, for instance, for state feedback regulator design (Section 9.1).

 Here is a second-order SISO system with no direct transition term.

In[22]:= StateSpacea1 , a2 , a3 , a4 , b1 , b2 , c1 , c2 

Out[22]= StateSpacea1 , a2 , a3 , a4 , b1 , b2 , c1 , c2 

 This is the same system with a zero direct transition term added.

In[23]:= StateSpacea1 , a2 , a3 , a4 , b1 , b2 , c1 , c2 , 0

Out[23]= StateSpacea1 , a2 , a3 , a4 , b1 , b2 , c1 , c2 , 0

 The two systems yield the same transfer function and so correspond to the same
physical system.
In[24]:= SameQ  TransferFunction  % , %% 

Out[24]= True

StateSpacetransferfunction
the StateSpace realization of the
TransferFunction object transferfunction

StateSpacetransferfunction, TargetForm  form


the realization of the specified form
Obtaining state-space realizations of transfer functions.
36 Control System Professional

The state-space representation can be obtained directly from the differential equations of the
system (difference equations in the case of a discrete-time system) or from the transfer matrix.
In the latter case, the target form of the state-space model can be specified by the option
TargetForm, with the default value ControllableCompanion that corresponds to the
controllable companion form, constructed by inspection. The adopted definition of the controlla-
ble companion form is due to, for example, Gopal (1993). (In the literature, this form is some-
times referred to as the controllable canonical form.) For the strictly proper transfer matrix

Β1 sn1  Β2 sn2    Βn
Hs  

 (3.5)
sn  Α1 sn1    Αn
of size q  p , where Βi are of that size as well, p and q being the number of inputs and outputs,
respectively, the controllable companion realization is assumed to be




0 I 0  0 0


0 0 I  0 0

x      x   u

0
0 0  I 0

(3.6)

 Αn I Αn1 I Αn2 I  Α1 I  I

y  Β Β x  Du
n n1 Βn2  Β1

where 0 and I are zero and identity matrices of size p  p and the matrix D is zero. The dimen-
sion of the system is n p. If the transfer matrix Hs is proper (but not strictly proper), the
same representation of the strictly proper part of Hs holds while the matrix D can be found
as

D  H  (3.7)
Similarly, the observable companion realization is





0
0  0 Αn I Βn


I 0  0 Αn1 I
Βn1
x 

0 I  0 Αn2 I x  Βn2 u


     (3.8)


 0 0  I Α1 I  Β1

y  0 0  0 I x  Du
3. Description of Dynamic Systems 37

where 0 and I are zero and the identity matrices of size q q and the dimension of the system
is nq . This form can be obtained using the option TargetForm ObservableCompanion .
Note that the controllable and observable companion forms may not be of minimal order and,
as a rule, are ill-conditioned. Chapter 8 describes the methods to transform the model further.

 Here is a transfer function.


1 1
In[25]:= tf  TransferFunction s,   ,  
s a s b
1 1
Out[25]= TransferFunctions,   ,  
a  s b  s

 This produces the controllable companion realization.

In[26]:= StateSpace% 

Out[26]= StateSpace0, 0, 1, 0, 0, 0, 0, 1, a b, 0, a  b, 0, 0, a b, 0, a  b,


0, 0, 0, 0, 1, 0, 0, 1, b, a, 1, 1

 The structure of the state-space system is more transparent with the use of Tradi
tionalForm (Section 3.4). Clearly, this is not the minimal-order model.
In[27]:= TraditionalForm% 

Out[27]//TraditionalForm=
 0 0 1 0 0 0 
 
 0
 0 0 1 0 0 
 
 a b 0 a  b
 0 1 0 
 0 a b 
 0 ab 0 1 
 
 b a 1 1 0 0 •
38 Control System Professional

 This reduces the order of the system using the function MinimalRealization
described in Section 8.1. To obtain a simpler result, we assert that none of the
symbolic variables are complex.
In[28]:= MinimalRealization % , ComplexVariables  None Simplify
TraditionalForm
Out[28]//TraditionalForm=

 1
  
 a 0 0 
  

 1   
1
b2
 b 

 
 1 
  
 
 
  
 0 b 0 
    

 1   1
 a 

a2

 
 
   1 1 
   
 
1  2 b  1  2 a 0 0 
 b a •

 This produces the observable companion realization.

In[29]:= StateSpacetf, TargetForm  ObservableCompanion  TraditionalForm

Out[29]//TraditionalForm=
0 a b b a 
 
 1 a  b 1 1 
 
 
0 1 0 0 •

 It is easy to demonstrate that both realizations correspond to the initial system.

In[30]:= TransferFunction s, # &  % , %%  Simplify

1 1
Out[30]= TransferFunctions,   ,  ,
a  s b  s
1 1
TransferFunctions,   ,  
a  s b  s

By itself, StateSpace does not check the consistency of component matrices; however, the
consistency is the prerequisite for many other functions to operate in a meaningful way.
Consistency here means that matrix a must be square, n n , where n is the number of states;
matrix b must be n p , where p is the number of inputs; matrix c must be q n , where q is the
number of outputs; and matrix d, if used, must be q  p . When entering state-space objects
manually, these requirements should be kept in mind. The function ConsistentQ checks
that they are satisfied.

StateSpace, as well as other control objects, accepts options, which could, if so desired,
come wrapped in lists. Therefore, caution should be exercised to not confuse an empty list of
3. Description of Dynamic Systems 39

options with an empty matrix in a control object's description. For this reason, parsing an
empty list as a valid list of options is disallowed for all control objects as well as in other
functions in Control System Professional where this may cause a confusion.

 3.3 Continuous-Time versus Discrete-Time Systems


The way to to specify whether the TransferFunction , StateSpace, and ZeroPoleGain
objects to the continuous-time or discrete-time domain is to set the option Sampled to either
False, True, or Period[value]. Once set, the option remains a part of the data structure.
This allows the same set of functions to operate on both types of systems implementing an
object-oriented paradigm, according to which the method "knows" how to deal with the
object.

As with all other Mathematica options, setting of the option Sampled is not mandatory. If a
function does not find the option in a particular control object, it relies on the global variable
$Sampled to make the decision when necessary. The default value of $Sampled is False.
Changing the global domain specification makes sense if you deal primarily with the
discrete-time systems or, even more restrictively, with systems sampled primarily at one rate.
If this is the case, you may want to change the variable $Sampled in your Mathematica session
and/or include the corresponding line in your init.m file. It should be emphasized that
relying on the global variable, although convenient, may cause confusion if you save the
results of your Mathematica session to a file and later read it in after changing that variable, or
if you send your file to a colleague who prefers another global value. A useful precaution,
therefore, is to save the value of $Sampled together with your data or use the Sampled
option explicitly in all your data structures.
40 Control System Professional

Sampled False attributes the system to the continuous-time domain


Sampled True attributes the system to the discrete-time domain
Sampled PeriodT attributes the system to the continuous- or 
discrete-time domain depending on the  value of T;
a zero value refers to the continuous-time domain,
and everything else refers to the discrete-time domain
$Sampled global  variable that determines the 
domain in which a system is assumed to 
be in the absence of the Sampled option
ContinuousTimeQsystem test if system is in the continuous-time domain
DiscreteTimeQsystem test if system is in the discrete-time domain
SamplingPeriodsystem find the sampling period of system

Options, global variables, and test functions pertaining to domain specification.

 There is no domain-specifying option in this StateSpace object, so it is attributed


to continuous-time by default.
In[31]:= ContinuousTimeQStateSpacea, b, c

Out[31]= True

 Now the system is explicitly set to be in the discrete-time domain.

In[32]:= ContinuousTimeQStateSpacea, b, c, Sampled  True

Out[32]= False

 This is another way to attribute the system to the discrete-time domain—by using
Period[T] with a nonzero value of T.
In[33]:= ContinuousTimeQStateSpacea, b, c, Sampled  Period T

Out[33]= False

 This changes the default domain. From now on the system will be assumed to be
discrete-time if not specified otherwise with the Sampled option (until $Sampled is
changed back).
In[34]:= $Sampled  Period 1

Out[34]= Period1
3. Description of Dynamic Systems 41

 The same system as before is now considered to be in the discrete-time domain.

In[35]:= ContinuousTimeQStateSpacea, b, c

Out[35]= False

 This restores the default behavior.

In[36]:= $Sampled  False

Out[36]= False

 3.4 The Traditional Notations

TraditionalFormsystem traditional form of the 


state-space or transfer-function system

Traditional representation of the control objects.

In the notebook front end, you can display and manipulate control objects in their traditional
typeset form. The TransferFunction and StateSpace objects are represented as transfer
 A B 
function matrices and a block matrices   , correspondingly. By convention, control
C D
objects are distinguished from regular matrices by their superscripts, which are the script
letters  for TransferFunction and  for StateSpace.

The objects can also have a subscript that indicates the time domain or the sampling period.
The default subscripts for continuous-time and discrete-time objects are • and  (the Mathemat-
ica characters [Bullet] and [EmptyUpTriangle]). By setting the values of global
variables $ContinuousTimeToken and $DiscreteTimeToken, you can choose a different
notation. The subscript is typically omitted if the domain can otherwise be unambiguously
determined from the contents of the control object.

The traditional form of the TransferFunction object uses the variable  (the Mathematica
character [ScriptS]) to represent the complex variable of the Laplace-transform domain
and the variable  ( [ScriptZ]) for the z-transform domain. You can choose different
symbols by setting the global variables $ContinuousTimeComplexPlaneVariable and
$DiscreteTimeComplexPlaneVariable.
42 Control System Professional

Note that contrary to the standard representation of the TransferFunction object, which
does not require a formal variable (nor does it take the variable into account for the time
domain identification purposes), interpretation of the TransferFunction object in Tradi
tionalForm is based on the domain variable. However, should the variable in the body of
the TransferFunction point to the domain that is different from the one indicated by the
subscript of the control object, the domain is determined by the value of the subscript.

$ContinuousTimeToken the token of the continuous-time domain in the


subscript of the control objects in TraditionalForm
$DiscreteTimeToken the token of the discrete-time domain
• the default value of $ContinuousTimeToken
 the default value of $DiscreteTimeToken

$ContinuousTimeComplexPlaneVariable
the complex  variable in the TraditionalForm 
representation of continuous-time control objects

$DiscreteTimeComplexPlaneVariable
the discrete-time variable
 the default value of 
$ContinuousTimeComplexPlaneVariable
 the default value of 
$DiscreteTimeComplexPlaneVariable
Customizing TraditionalForm of control objects.

 Here is a discrete-time state-space object.

In[37]:= StateSpacea1 , a2 , a3 , a4 , b1 , b2 , c1 , c2 , Sampled  True

Out[37]= StateSpacea1 , a2 , a3 , a4 , b1 , b2 , c1 , c2 , Sampled  True

 This is its TraditionalForm representation. The discrete-time domain is indicated


by the small triangle.
In[38]:= TraditionalForm% 

Out[38]//TraditionalForm=
a a b 
 1 2 1 
 a a b 
 3 4 2 
 
 c1 c2 0 
3. Description of Dynamic Systems 43

 This is a continuous-time TransferFunction object.


1
In[39]:= TransferFunction   
#
1
Out[39]= TransferFunction  
#1

 This is its TraditionalForm representation. The variable  indicates the


continuous-time domain.
In[40]:= TraditionalForm% 

Out[40]//TraditionalForm=
1 
  


 Here we copy the previous output cell and paste it into the input cell. The expression
is interpreted as a continuous-time object because of the variable .

In[41]:= ContinuousTimeQ
 
1


Out[41]= True

EquationFormstatespace the state-space system 


statespace in the form of matrix equations

Representing StateSpace objects as state-space equations.

Several options allow you to customize the appearance of a state-space system in Equation
Form. By default, the state, input, and output variables are, correspondingly,  (the Mathemat-
ica character [ScriptX]),  ( [ScriptU]) and  ( [ScriptY]). The default time variables
for the continuous-time and discrete-time systems are  ( [ScriptT]) and  ( [ScriptK]),
respectively.

option name default value

StateVariables  the state variables to use in equations


InputVariables  the input variables
OutputVariables  the output variables
TimeVariable Automatic the time variable

Specifying the variables for the StateSpace objects in EquationForm.


44 Control System Professional

 Here is a state-space system.

In[42]:= StateSpacea1 , a2 , a3 , a4 , b1 , b2 , c1 , c2 

Out[42]= StateSpacea1 , a2 , a3 , a4 , b1 , b2 , c1 , c2 

 These are the corresponding state-space equations.

In[43]:= EquationForm% 

Out[43]//EquationForm=
 a1 a2   b1 
      
 a3 a4   b2 
   1 2 
c c

 This uses the specified variables to represent the system.


In[44]:= EquationForm% , StateVariables  Θ, Θ, InputVariables  ∆

Out[44]//EquationForm=

 Θ   a1 a2   Θ   b1 
       ∆
 Θ   a3 a4   Θ   b2 
Θ
   c1 c2  
Θ

 3.5 Discrete-Time Models of Continuous-Time Systems


If an analog system is to be analyzed in the discrete-time domain, the problem arises of find-
ing a discrete-time representation of the system such that the output variables sampled at
times t0 , t1 , …, tk , … suitably approximate the ones of the original system. A possible way to
make such a conversion is to apply the function ToDiscreteTime to a continuous-time
system. ToDiscreteTime operates on all control objects. Note that the built-in functions
LaplaceTransform and ZTransform can, in principle, perform similar tasks. However, the
procedures in Control System Professional use the state-space approach and so the conversion
is, as a rule, more efficient.
3. Description of Dynamic Systems 45

ToDiscreteTimesystem find the discrete-time approximation 


of continuous-time system sampled 
with the default sampling period

ToDiscreteTimesystem, Sampled PeriodT


find the discrete-time approximation of 
continuous-time system sampled with period T
$SamplingPeriod default numeric value of sampling period
Finding discrete-time equivalents of continuous-time systems.

 Consider a simple continuous-time system.


a
In[45]:= tf  TransferFunction s,  
s a
a
Out[45]= TransferFunctions,   
as

 This is a possible discrete-time approximation. As noted previously, the formal


internal variable (in this case s) does not indicate the domain, but the Sampled
option does.
In[46]:= hz  ToDiscreteTime% , Sampled  Period T Simplify

1  a T
Out[46]=  , Sampled  PeriodT
TransferFunctions,  
1  a T s

 Should the need arise, it is easy to rename the formal variable.

In[47]:= % . s  z

1  a T
Out[47]=  , Sampled  PeriodT
TransferFunctionz,  
1  a T z

 Consider a state-space continuous-time system.

In[48]:= cont  StateSpace0, 1, 0, 1, 0, 1, 1, 0
TraditionalForm
Out[48]//TraditionalForm=

 0 1 0 
 
 0 1 1 
 
 
 1 0 0 •
46 Control System Professional

 This is its discrete-time approximation. The result is still a StateSpace object that is
in the discrete-time domain as indicated by the option Sampled.
In[49]:= disc  ToDiscreteTime% , Sampled  Period Τ

Out[49]= StateSpace1, 1  Τ , 0, Τ ,


1  Τ  Τ, 1  Τ , 1, 0, Sampled  PeriodΤ

 Here is the same system in TraditionalForm.

In[50]:= TraditionalForm% 

Out[50]//TraditionalForm=
 1 1  

Τ  Τ  1 
 
 0
 Τ
1  Τ 
 
1 0 0 Τ

The default value for the option Sampled in ToDiscreteTime is the global variable $Sam
plingPeriod. This variable also provides a fallback where some functions retreat in situa-
tions when the sampling period does not evaluate to a number, but the numeric value is
needed to perform the task (for example, to simulate the transient behavior of a system). Thus,
$SamplingPeriod must never be set to anything that has no numeric value. If it is desirable
for ToDiscreteTime to use a symbolic sampling period T by default, this can be easily
achieved by using the standard Mathematica mechanism, say with a command
SetOptionsToDiscreteTime, Sampled  PeriodT .

It is worth emphasizing that the "conversion" from an analog to a sampled system is merely
an approximation, the quality of which depends on the method used and the sampling period.
The time-domain response functions described in Chapter 4 can make the difference
between the original and approximated system readily apparent.

 This is the analog output response of the original system to the sinusoidal input
signal.
In[51]:= OutputResponsecont, Sin t, t Simplify

1
Out[51]=   2  t  Cost  Sint

2
3. Description of Dynamic Systems 47

 Here is a piece of that curve on the time interval from 0 to 10 seconds.

In[52]:= Plot% , t, 0, 10;

1.5

1.25

0.75

0.5

0.25

2 4 6 8 10

 This plots the simulated response of the discrete-time system for the sampling
period Τ of 0.5 seconds over the same time interval. For reference, we include the
analog response from the previous plot (structurally, the line is the first element of
the Graphics object returned by the previous command and is extracted with
First).
In[53]:= SimulationPlotdisc . Τ  .5, Sin t, t, 0, 10,
PlotJoined  False, PlotStyle  PointSize.015,
PlotLabel  "Output Response", Epilog  First% ;

Output Response

1.5
1.25
1
0.75
0.5
0.25

2 4 6 8 10

We can see that the sampled values systematically lag behind corresponding points on the
analog curve, which is typical for the default ZeroOrderHold method. Choosing smaller
values for Τ can make the lag less noticeable.
48 Control System Professional

3.5.1 The Conversion Methods

The conversion from the continuous-time domain to the discrete-time domain can be per-
formed using the following methods (see Franklin et al. (1990), Section 4). The method can be
selected with the Method option.

• Hold equivalence methods—zero- and first-order (triangle) hold, implemented with


ZeroOrderHold and FirstOrderHold, respectively
• Numerical integration methods—forward and backward rectangular rules,
implemented with ForwardRectangularRule and BackwardRectangular
Rule, respectively, and bilinear (Tustin) transformation with and without
prewarping, implemented with BilinearTransform
• Zero-pole mapping, implemented with ZeroPoleMapping

option name default value

Method ZeroOrderHold method to use for transformation


CriticalFrequency Automatic critical frequency, if any,
at which to make comparisons

Options related to continuous- to discrete-time conversion.

 This is the result of conversion with the forward rule of the transfer function system
tf defined earlier in this chapter.
In[54]:= ToDiscreteTimetf, Sampled  Period T, Method  ForwardRectangularRule

aT
Out[54]= TransferFunctions,   , Sampled  PeriodT
1sa T

 This is the conversion of the same transfer function using the backward rule.

In[55]:= ToDiscreteTimetf, Sampled  Period T,


Method  BackwardRectangularRule Simplify
asT
Out[55]= TransferFunctions,   , Sampled  PeriodT
1  s  a s T
3. Description of Dynamic Systems 49

 This conversion uses the bilinear transformation.

In[56]:= ToDiscreteTimetf, Sampled  Period T,


Method  BilinearTransform Simplify

a 1  s
T
Out[56]= TransferFunctions,  
 , Sampled  PeriodT
2  a T  s 2  a T

 This uses the zero-pole mapping.

In[57]:= ToDiscreteTimetf, Sampled  Period T, Method  ZeroPoleMapping 

1  a T
Out[57]=  , Sampled  PeriodT
TransferFunctions,  
a T  s

 This is the first-order-hold equivalent of the transfer function Hs  1  s2 .


1
In[58]:= ToDiscreteTimeTransferFunction s,  ,
s2
Sampled  Period T, Method  FirstOrderHold  Simplify

1  4 s  s2
T2
Out[58]= TransferFunctions,  
 , Sampled  PeriodT
6 1  s
2

 Yet another example, which uses a lag network, illustrates the effect of the option
CriticalFrequency on accuracy of the conversion.
a s 1
In[59]:= lag  TransferFunction s,  
b s 1
1a s
Out[59]= TransferFunctions,   
1b s
50 Control System Professional

 Here is the Bode plot for the network for some set of parameters.

In[60]:= lagplot  BodePlotlag . a  1, b  5;

Magnitude dB

-2
-4
-6
-8
-10
-12
-14
0.01 0.05
0.1 0.51 5 10
Frequency Rad Second

Phase deg

-10

-20

-30

-40
0.01 0.05
0.1 0.5 1 5 10
Frequency Rad Second

 This is the network after the bilinear transformation.

In[61]:= dlag  ToDiscreteTimelag ,


Sampled  Period T, Method  BilinearTransform Simplify

2 a 1  s
 1  s
T
Out[61]= TransferFunctions,  
 , Sampled  PeriodT
2 b 1  s
 1  s
T
3. Description of Dynamic Systems 51

 This computes the Bode plots for continuous and sampled lag networks—and
displays them together using a utility function DisplayTogetherGraphicsArray
(see Section 12.5). The responses coincide for the low frequencies but differ
somewhat near the Nyquist frequency.
In[62]:= DisplayTogetherGraphicsArray
lagplot, BodePlotdlag . a  1, b  5, T  1,
PlotStyle  RGBColor1, 0, 0, Dashing .02;

Magnitude dB
0
-2
-4
-6
-8
-10
-12
-14
0.01 0.05
0.1 0.51 5 10
Frequency Rad Second

Phase deg

-10

-20

-30

-40
0.01 0.05
0.1 0.5 1 5 10
Frequency Rad Second

 We again use BilinearTransform, this time with frequency prewarping at some


critical frequency Ωc .
In[63]:= ToDiscreteTimelag , Sampled  Period T,
Method  BilinearTransform, CriticalFrequency  Ωc  Simplify
T Ωc
a 1  s
Ωc  1  s
Tan  
Out[63]= TransferFunctions,  

T Ω
2 , Sampled  PeriodT
b 1  s
Ωc  1  s
Tan  2
c

52 Control System Professional

 We have achieved a perfect match at that frequency at the expense of less accurate
behavior at other frequencies.
In[64]:= DisplayTogetherGraphicsArray
lagplot, BodePlot% . a  1, b  5, T  1, Ωc  2,
PlotStyle  RGBColor1, 0, 0, Dashing .02;

Magnitude dB

-2
-4
-6
-8
-10
-12
-14
0.01 0.05
0.1 0.51 5 10
Frequency Rad Second

Phase deg

-10

-20

-30

-40
0.01 0.05
0.1 0.5 1 5 10
Frequency Rad Second

Except for zero-pole mapping, which naturally operates on ZeroPoleGain objects, the
conversion from the continuous- to the discrete-time domain is implemented with state-space
algorithms. Therefore, the transformation to and from StateSpace objects can be avoided if
the system is represented in StateSpace in the first place.

 This is our lag system as a StateSpace object.

In[65]:= lag1  StateSpacelag  Simplify TraditionalForm

Out[65]//TraditionalForm=

   1 
1
 
 b 

 b  a
  a 

 b2 b •
3. Description of Dynamic Systems 53

 This converts the system to discrete time using the bilinear transformation.

In[66]:= ToDiscreteTimelag1, Sampled  Period T, Method  BilinearTransform


Simplify TraditionalForm
Out[66]//TraditionalForm=
 2 b  T 2 b 
   
 2 b  T 2 b  T 
 
 2 b  a T 2 a  T 
   

 b 2 b  T 2 b  T T

 3.6 Discrete-Time Models of Systems with Delay


ToDiscreteTime can also find the discrete-time approximation of analog state-space sys-
tems of the form

x t  Axt  But  Λ


(3.9)
yt  Cxt
which corresponds to systems with time delay Λ. The systems can be represented as conven-
tional StateSpace objects with a Delay option added. The conversion implements the
modified z -transform algorithm described in Franklin et al. (1990), Section 2.4.4.

Currently, ToDiscreteTime is the only function that takes the Delay option into consider-
ation and, even more restrictively, it handles the only case of numerical values of the ratio
Λ  Ts , where Ts is the sampling period. Negative delay is equivalent to prediction of the
system's behavior and can be used as long as the delay is not longer than the sampling period.

option name default value

Delay 0 time delay in the state-space model

Option in StateSpace to introduce a delay in control.

 Here is a simple state-space system with delay of Λ.

In[67]:= ss  StateSpace1, 1, 1, Delay  Λ

Out[67]= StateSpace1, 1, 1, Delay  Λ


54 Control System Professional

 This is its discrete-time approximation when the delay equals the sampling period.

In[68]:= ToDiscreteTimess . Λ  Τ, Sampled  Period Τ

Out[68]= StateSpaceΤ , 1  Τ , 0, 0, 0, 1, 1, 0, Sampled  PeriodΤ

 If the delay increases, then so does the dimension of the state space.

In[69]:= ToDiscreteTimess . Λ  2 Τ, Sampled  Period Τ

Out[69]= StateSpaceΤ , 1  Τ , 0, 0, 0, 1, 0, 0, 0,


0, 0, 1, 1, 0, 0, Sampled  PeriodΤ

 This is an example of the transformation of a system with a negative delay.


Τ
In[70]:= ToDiscreteTimess . Λ    , Sampled  Period Τ
2
Out[70]= StateSpaceΤ , Τ 2 1  Τ 2
 Τ 1  Τ 2
,
1, 1  Τ 2 , Sampled  PeriodΤ

 3.7 Continuous-Time Models of Discrete-Time Systems


The function ToContinuousTime , when applied to discrete-time objects, converts them to
the continuous-time domain. In many respects ToContinuousTime behaves as an inverse
function to ToDiscreteTime and applies inverse algorithms to those described previously in
Section 3.5. Again, the methods can be chosen through the Method option, which accepts the
same values. The conversion attempts to find the slowest possible continuous-time model the
outputs of which would match the ones of the discrete-time model at the sample time.

ToContinuousTimesystem find the continuous-time model


of the discrete-time object system

Finding continuous-time equivalents of discrete-time systems.

 Here a continuous-time system from an earlier example is converted to the


discrete-time domain.
In[71]:= ToDiscreteTime
StateSpace0, 1, 0, 1, 0, 1, 1, 0, Sampled  Period T

Out[71]= StateSpace1, 1  T , 0, T ,


1  T  T, 1  T , 1, 0, Sampled  PeriodT
3. Description of Dynamic Systems 55

 This brings the system back to continuous time.

In[72]:= ToContinuousTime% 

LogT  LogT 
Out[72]= StateSpace0,   , 0,  ,
T T
T  LogT  LogT 
  ,   , 1, 0
T T

 As our sampling period T is real-valued, we can simplify the result and see that the
system is the same as the one we started with.
In[73]:= ComplexExpand  %

Out[73]= StateSpace0, 1, 0, 1, 0, 1, 1, 0

 Here is the lag system used earlier.


1 a  b a
In[74]:= lag1  StateSpace  , 1,   ,   
b b2 b
1 a  b a
Out[74]= StateSpace  , 1,  2 ,   
b b b

 This converts the system to the discrete-time domain using the bilinear
transformation with frequency prewarping.
In[75]:= ToDiscreteTime% , Sampled  Period T,
Method  BilinearTransform, CriticalFrequency  Ωc  Simplify
T Ωc
b Ωc  Tan   b Ωc
Out[75]= T Ωc  ,  
StateSpace 
2
T Ωc  ,

b Ωc  Tan  2
 b Ωc  Tan  2

T Ωc T Ωc
2 a  b
Tan   a Ωc  Tan  
 
T Ωc  ,  

2
T Ωc  , Sampled  PeriodT

2
b b Ωc  Tan  2

b Ω c  Tan 
2


 This brings the system back to continuous time.

In[76]:= ToContinuousTime% , Method  BilinearTransform,


CriticalFrequency  Ωc  Simplify

1 a  b a
Out[76]= StateSpace  , 1,  2 ,   
b b b
56 Control System Professional

 This is the discrete-time approximation of the lag system obtained with the
first-order hold.
In[77]:= ToDiscreteTimelag1, Sampled  Period T,
Method  FirstOrderHold  Simplify
2T T 2
b2  
T
 
b 1   b 

Out[77]= StateSpace b ,  
 ,
T
  
T   
 b 1 b 
 
  

a  a  b
 

 1  
   



 T 
a  b  
 2 ,    , Sampled  PeriodT
b b

 This converts the result back to continuous time.

In[78]:= ToContinuousTime% , Method  FirstOrderHold  Simplify

1 a  b a
Out[78]= StateSpace  , 1,  2 ,   
b b b

Note that in the case of the FirstOrderHold method, ToContinuousTime cannot use the
inverse of the state-space algorithm implemented in ToDiscreteTime and, as an exception,
resorts to the conversion using transfer functions, which is less efficient.
4. Time-Domain Response

Control System Professional provides the means to analyze linear systems in both time and
frequency domains. This chapter deals with the time dependencies of the state and output
vectors. Refer to Chapter 5 for the description of frequency-domain analysis tools. Two
approaches, symbolic and simulation-based, are implemented and will be introduced in the
following sections. The functions StateResponse and OutputResponse, which compute
the state and output responses, are capable of performing both operations and choose their
mode depending on the supplied input. SimulationPlot, on the other hand, always uses
the simulation approach.

 4.1 Symbolic Approach


For the continuous-time system

x t  Axt  But (4.1)


StateResponse, when supplied with the symbolic input ut, attempts to find the solution

t
xt  ett0 A xt0    etΤA BΤuΤ Τ (4.2)
t0

The first term in this equation represents the zero-input response (also called the free, natural,
unforced, or homogeneous response) and the second is the zero-state (or particular, forced)
response. Once the state response xt is found, the output response yt can computed
directly from the equation

yt  Ctxt  Dtut (4.3)

OutputResponse, therefore, calls StateResponse first and then proceeds according to


Eq. (4.3). The preceding solution is valid for constant-coefficient matrices A , whereas matrices
B , C , and D may be time dependent.

The state response for the discrete-time system

xk  1  Axk  Buk (4.4)


58 Control System Professional

is computed according to

k
xk  Ak x0   Ak j Bj  1uj  1 (4.5)
j1

and the output response is found by

yk  Cxk  Duk (4.6)


Again, matrices B, C , and D may be time dependent, but matrix A may not.

StateResponsesystem, u, var
compute the state response of system to the input 
signals u given as functions of the time  variable var

OutputResponsesystem, u, var
compute the output response

OutputResponsec, d, x, u
compute the output response 
given the system matrices c and d,
state response x, and input u
OutputResponsec, x compute the output 
response assuming matrix d is zero
State and output responses to an input function.

For both functions, the input system can be supplied in either state-space or transfer function
form; however, the computation is always carried out in the state-space form and the transfer
functions are converted to state-space form first. Because matrices C and D are not needed to
compute the state response, their presence in the input system for StateResponse is
optional.

 Load the application.

In[1]:=  ControlSystems`
4. Time-Domain Response 59

 Consider a transfer function with a simple pole.


1
In[2]:= TransferFunction s,  
s 1

1
Out[2]=  
1

 This finds the output response to the sinusoidal input function sin10t . We can see
that the first exponential term (the natural response) will vanish, leaving only the
harmonic (forced) signal in the output.
In[3]:= OutputResponse% , Sin 10 t, t

10 t 1
Out[3]=     10 Cos10 t  Sin10 t
101 101

 The built-in Mathematica function Plot plots the result on some time interval.

In[4]:= Plot% , t, 0, 10;

0.15

0.1

0.05

2 4 6 8 10
-0.05

-0.1

The zero-input response in Eq. (4.2) or Eq. (4.5) depends on the initial conditions on the state
vector xt0  or x0, respectively. By default, StateResponse and OutputResponse
assume zero initial conditions. If this is not the case, the initial conditions can be supplied
using the option InitialConditions . The typical format is InitialConditions

vector, where vector must have the same length as matrix A . Also acceptable is InitialCondi
tions
value, which will cause all state variables to have the same initial value.

Using the option ControlInputs you can effectively cycle through the subsystems that
correspond to the specified list of inputs. For ControlInputs
Automatic, StateRe
sponse and OutputResponse apply the input function to all inputs in turn. Another option,
ResponseVariable , allows you to name the internal variable if the state or output response
should contain unevaluated integral(s) or sum(s). The default value for this option is Auto
60 Control System Professional

matic, which corresponds to the internal integration variable Tau or summation index K for
the continuous- and discrete-time cases, correspondingly.

option name default value

InitialConditions 0 initial state conditions


ControlInputs Automatic inputs to use in turn
ResponseVariable Automatic internal variable to
use in the integral or sum

Specifying initial conditions and the response variable in StateResponse and OutputResponse.

As an example consider the simple production and inventory control model from Brogan
(1991):

 1 k
 k 0
 c


x  x 
 0 1   u2


 1 0

which can be represented schematically as shown in Figure 4.1. The model assumes that u1 t
and u2 t are the scheduled production rate and the sales rate, respectively, x1 t and x2 t
represent the actual production rate and inventory level, and c is the desired inventory level.

u2 t

c  u1 t x1 t
_
x2 t
yt
 
k  
_ _

Figure 4.1. Simple production and inventory control system.

 Here is the production and inventory control model.

In[5]:= StateSpace1, k, 1, 0, k, 0, 0, 1


 1 k k 0 
Out[5]=  
 1 0 0 1 •
4. Time-Domain Response 61

Initially the system was in equilibrium, with the production rate x1 0 equal to the sales rate
and x2 0  c . We denote x1 0 as x10. At t  0, sales increase by 10 percent.

 This finds the state response for the particular value of k 


3
16
. The initial conditions
are specified using the option InitialConditions.
3
In[6]:= StateResponse% . k   , c, 1.1 x10,
16
t, InitialConditions  x10, c  Simplify

Out[6]= 1.1  2.05 3 t4  2.15 t4  x10,


1. c  5.86667  2.73333 3 t4  8.6 t4  x10

 This plots the results for particular values of the initial production rate x1 0 and
inventory level c . To distinguish the graphs for production rate and for inventory
level, we set PlotStyle for them differently. The first is plotted as a solid line and
the second as a dashed one.
In[7]:= PlotEvaluate% . x10  1, c  6, t, 0, 50,
PlotStyle  Thickness.005, Dashing .05, .01,
PlotRange  All, PlotLabel  "State Response";

State Response
6

10 20 30 40 50

We can see that (within this model) keeping initial inventory relatively large allows us to
stabilize production rate at a new level.

Note that if multiple input signals are supplied to StateResponse and OutputResponse,
the number of signals must be equal to the number of inputs. For multi-input systems, an
input signal must be supplied as a vector of functions, but for single-input systems, a function
without the List wrapping is also acceptable (in the simulation mode, the same rule of
correspondence between the number of input signals and the number of inputs applies—see
Section 4.2). If only the response from one or several inputs or outputs must be studied, the
function Subsystem (or DeleteSubsystem) may be used to select the subsystem of interest.
62 Control System Professional

For further examples when the same input signal is to be applied to all inputs in turn, see
Section 4.3.

 Here is a two-output system.


1 1
In[8]:= TransferFunction s,   ,   
s s2  2 s  10

 1

 
  
Out[8]=  

 1 

 2  2   10 

 This selects the subsystem associated with the second output and computes the
output response to a delayed step function.
In[9]:= resp  OutputResponseSubsystem% , All, 2, UnitStept  1, t

1 
Out[9]= 
  
60 60
3  3   1  2  13  1t  2   13  1t  UnitStep1  t

 We can use ComplexExpand to reduce the complex exponentials to the


trigonometric functions.
In[10]:= ComplexExpand resp

1 1
Out[10]=   UnitStep1  t   1t Cos3 1  t UnitStep1  t 
10 10
1
 1t Sin3 1  t UnitStep1  t
30

 This simplifies the result.

In[11]:= %  Simplify

1
Out[11]=   t 3 t  3  Cos3  3 t   Sin3  3 t UnitStep1  t
30
4. Time-Domain Response 63

 This is a plot of the response.

In[12]:= Plot% , t, 0, 7, PlotRange  All;

0.12

0.1

0.08

0.06

0.04

0.02

1 2 3 4 5 6 7

 Here is a discrete-time system.


1 1 1 1
In[13]:= system  StateSpace  ,  ,   ,  ,
2 4 4 2
DiagonalMatrix1, 1, 1, 2, Sampled  Period 1


 1 0 
1 1

 2 4 
 
Out[13]=  1 1 
 0 1 
 4 2 
 
 1 2 0 0 1

 In this input vector, the components are a ramp function and a decaying exponential
e t both sampled at a unit-time interval.
In[14]:= inputs  k, k 

Out[14]= k, k


64 Control System Professional

 This is the state response for the particular set of initial conditions. Since k is a real
valued parameter, the expression can be simplified with ComplexExpand.
In[15]:= StateResponsesystem, inputs, k, InitialConditions  1, 2 
ComplexExpand  Simplify

1
Out[15]=  

9 4   4  3 
12 k k
2  9 232 k 2  3 47  5 252 k  2k  55 3 2k  9 4 2k k 
32 1k 10  34k  5 42k  3 232 k k 
1
16 k 11  5 252 k  17 32k  3 42k k, 

9 4   4  3 
212 k k 9 252 k   9 42k 2  55 3 2k  3 2k 47  272 k  3 232 k k 
16 k 11  272 k  17 32k  3 232 k k  32 1k 10  34k  43k  3 41k k 

 Once the state response vector is available, the output response can be found.

In[16]:= OutputResponse1, 2, %   Simplify

1
Out[16]=  

9 4   4  3 
12 k k
2  9 43k   27 232 k 2  3 2k 47  13 252 k  55 32k  3 252 k k  16 k
11  13 252 k  17 33k  3 252 k k  32 1k 10  35k  13 42k  3 42k k

 The same result can be obtained directly.

In[17]:= OutputResponsesystem, inputs, k, InitialConditions  1, 2 


ComplexExpand  Simplify

1
Out[17]=  

9 4   4  3 
212 k k 9 43k   27 232 k 2  3 2k 47  13 252 k  55 32k  3 252 k k  16 k
11  13 252 k  17 33k  3 252 k k  32 1k 10  35k  13 42k  3 42k k
4. Time-Domain Response 65

 4.2 Simulating System Behavior


Once input signals are supplied to StateResponse or OutputResponse in the form of a
function in the specified variable, as described in Section 4.1, a symbolic solution based on Eq.
(4.2) or Eq. (4.5) is attempted. There are, however, situations when the symbolic solution is
either impossible or just too time consuming. In such cases, StateResponse and OutputRe
sponse can be used to carry out a simulation of the state and output responses. For continuous-
time systems, the simulation is based on the approximate numerical solution of the underly-
ing differential equations using the built-in function NDSolve and is invoked when the range
for the time-domain variable in the form of {t, 0, tmax}, or simply {t, tmax}, is given instead of
the variable t. The result then appears in terms of InterpolatingFunction objects. This
regime is referred to as the analog simulation.

For discrete-time systems, the same input syntax causes the input functions to be sampled on
a uniform time grid. The grid starts at time t  0 (or k  0 ). The discrete simulation then pro-
ceeds in a straightforward manner according to Eq. (4.4) starting from the initial conditions for
k  0 and then iterating for k  1, 2, … . Instead of supplying the input functions and the
range for the time variable, you can give the input sequences explicitly. Note that if you
supply the input signals in the form of input sequences for the continuous-time system, the
system is first converted to discrete time, and then the simulation is performed. To facilitate
the conversion, the response functions accept the options pertinent to ToDiscreteTime,
notably Sampled may be used to set the sampling period, and Method to choose the conver-
sion method.

When input signals are discretized, the input sequences u must represent a matrix each row of
which corresponds to a signal at one input, and the number of rows must be equal to the
number of inputs. For single-input systems, the matrix may be reduced to a vector.
66 Control System Professional

StateResponsesystem, u, t, tmax


find the approximation of the state response for 
the time  variable t in the range from 0 to tmax

OutputResponsesystem, u, t, tmax


find the approximation of the output
response for the specified period of time

StateResponsesystem, u
find the state response 
to the discrete input sequences u

OutputResponsesystem, u
find the output response 
to the specified input sequences

OutputResponsec, d, x, u
find the output response for the system 
matrices c and d from the simulated 
state response x and input sequences u
OutputResponsec, x find the output response when d is a zero matrix
State and output responses in the simulation mode.

Let us simulate the output of the T-bridge network in Figure 4.2 to a square-wave signal.

C2

R R
Vi Vo
C1

Figure 4.2. A T-bridge.


4. Time-Domain Response 67

 This is the transfer function for the T-bridge network.

r 2 c1 c2 s 2  2 r c2 s  1
In[18]:= bridge  TransferFunction s,   

r2 c1 c2 s 2 
r c1  2 r c2 s  1

 r2 c1 c2 2  2 r c2   1 
Out[18]= 


 r c1 c2 2  r c1  2 r c2    1
2


 Here is the transfer function for a given set of parameters.


1
In[19]:= bridge1  % . r  1, c1  10, c2  
10

 2  5  1 
Out[19]= 
51 

 2   1
5 

 This utility function creates a square wave with period Τ.


2 Π t
In[20]:= squaret_, Τ_ : Sign Sin   
Τ

 Supplying the input signal together with both the time variable and the duration of
time period causes OutputResponse to perform in the simulation mode. The
output is a list of simulated responses. In this case, there is only one element in the
list since we are dealing with a single-output system.
In[21]:= outs  OutputResponsebridge1, squaret, 1, t, 3

Out[21]= SignSin2 Π t  10 InterpolatingFunction0., 3. ,


t

 This plots the input (the solid line) and the output (the dashed line) signals.

In[22]:= plot  PlotEvaluateFlatten squaret, 1, % , t, 0, 3,


PlotStyle  Thickness.0075, Dashing .05, .01;
2

0.5 1 1.5 2 2.5 3

-1

-2
68 Control System Professional

 This produces the output of the circuit using the discrete simulation with the
sampling period Τ. Note that the sampling period is supplied to OutputResponse
to specify the distance between points in the input vector (produced by the Table
function); this is necessary to convert the system to discrete time properly. The
output is a list of simulated responses. In this case, there is only one vector in the list.
In[23]:= Τ  .1;

In[24]:= OutputResponsebridge1,
Tablesquaret, 1, t, 0, 3, Τ, Sampled  Period Τ

Out[24]= 0., 1., 0.374159, 0.152404, 0.0777489, 0.0566053, 1.94511,


0.688127, 0.236818, 0.0788588, 0.0276691, 1.9847, 0.73131,
0.281026, 0.12316, 0.0717262, 1.94101, 0.688021, 0.238155,
0.0807077, 0.029691, 1.98263, 0.729233, 0.278961, 0.121112,
0.0696968, 1.94302, 0.690011, 0.240126, 0.082659, 0.031623

 The result can be drawn with the built-in Mathematica function ListPlot
(MultipleListPlot for multiple outputs). Here, however, we use a utility
function, SimulationPlot, described later in this section.
In[25]:= SimulationPlot% , Sampled  Period Τ, PlotStyle  Hue0;

0.5 1 1.5 2 2.5 3

-1

-2
4. Time-Domain Response 69

 This compares the results of the analog and discrete simulations. Clearly, the chosen
sampling period is too large to accurately approximate the behavior of the circuit.
In[26]:= Show plot, % ;

0.5 1 1.5 2 2.5 3

-1

-2

SimulationPlotv plot the  vector or list of  vectors v


SimulationPlotsystem, u, t, tmax 
plot the simulated output response of system to 
the input u as a function of t from 0 to tmax

SimulationPlotsystem, u
simulate the output response 
to the discrete input sequences u
Output response simulation plots.

SimulationPlot provides a convenient way to compute and plot the output response of a
system with a single function call. The syntax for SimulationPlot closely resembles the one
for OutputResponse. As with OutputResponse, SimulationPlot produces the analog
or discrete simulation depending on the type of input system, unless the input signal is
specifically given as input sequences, in which case the discrete simulation takes place. You
can also force the discrete simulation of a continuous system by giving the option Sampled to
SimulationPlot. The option is ignored if the input signal is already sampled. For the
purpose of simulation, the sampling period cannot take symbolic values.
70 Control System Professional

As an exception, simulation of the response of continuous-time systems to the Dirac delta


function is always performed in the discrete-simulation mode. To carry out analog simulation,
you can mimic the Dirac delta function with a continuous impulse of small width. See the
impulse response examples in Section 4.3. Note that, for a continuous-time system, the
impulse response is simulated as a decay of some initial state conditions in the absence of the
input signal. The initial conditions are determined by the components of the matrix B .

To facilitate computation of the output response and conversion to discrete-time, if necessary,


SimulationPlot takes the options for OutputResponse and ToDiscreteTime. Addition-
ally, SimulationPlot accepts the options for the built-in plotting functions Plot, List
Plot, or MultipleListPlot and routes the options to appropriate functions.

 This is an analog simulation of the output response of the bridge circuit to a square-
wave input signal for another set of parameters of the bridge.
In[27]:= SimulationPlotbridge . r  1, c1  10, c2  1, squaret, 1, t, 3;

0.5

0.5 1 1.5 2 2.5 3

-0.5

-1
4. Time-Domain Response 71

 This is a discrete simulation for the same parameters. The input system is discretized
using the specified sampling period.
In[28]:= SimulationPlotbridge . r  1, c1  10, c2  1,
squaret, 1, t, 3, Sampled  Period .1;

0.5

0.5 1 1.5 2 2.5 3

-0.5

-1

 This is a square pulse function.

In[29]:= UnitStep
t  1 2
1  t 

1
Out[29]= UnitStep1  t
   t 
2

 This simulates the behavior of the bridge for yet another set of parameters. To
ensure the correct result of NDSolve, which is called internally to compute the
output response, we limit the value of MaxRelativeStepSize.
In[30]:= SimulationPlotbridge . r  1, c1  1, c2  1,
% , t, 5, MaxRelativeStepSize  .1;

0.8

0.6

0.4

0.2

1 2 3 4 5
-0.2
72 Control System Professional

 This converts a particular bridge circuit to the discrete-time domain.

In[31]:= ToDiscreteTimebridge . r  1, c1  10, c2  1, Sampled  Period .2

Out[31]= TransferFunctions,
0.980382 0.0563042   s 0.980382  0.0563042   s
0.800931  s 0.982142  s , Sampled Period0.2

 Here is the response of this circuit to random noise. Note that SimulationPlot
picks up the sampling period from the input system.
In[32]:= SimulationPlot% , TableRandom  .5, 100;

0.6

0.4

0.2

5 10 15 20
-0.2

-0.4

-0.6

Although SimulationPlot generates only output response curves, it is a simple matter to get
it to plot the state response as well. This can be done by adding an appropriate matrix C to the
StateSpace object composed of only matrices A and B . In the rest of the section we give an
example.

Let us consider the linearized state-space system for the depth control problem of a submarine
(see Figure 4.3) for small angles Θ and constant velocity v  25 ft/s as described in Dorf (1992).

We will assume that the state variables are x1  Θ, x2  Θ , and x3  Α, where Α is the angle of
attack and the input variable u is ∆s , the deflection of the stern plane. We will compute the
state response of the system to a step command for the stern plane of 0.3deg from zero initial
conditions using the discrete-time approximation with sampling period 2 seconds.
4. Time-Domain Response 73

Θ
Α
Velocity v

Center of gravity

∆s

Figure 4.3. Depth control of a submarine.

 Here is the two-matrix state-space model.

In[33]:= StateSpace0, 1, 0, .0071, .111, .12, 0, .07, .3,


0, .095, .072

 
0 1 0 0

Out[33]=  0.0071 0.111 0.12 0.095 
 
 0 0.07 0.3 0.072 •

 To compute the state response, we insert a diagonal matrix C containing some


weighting coefficients.
In[34]:= Insert% , DiagonalMatrix.01, 1, 1, 1


 0 1 0 0 
 
 0.0071 0.111 0.12 0.095 
 
 0 0.07 0.3 0.072 

Out[34]=  

 0.01 0 0 0 
 
 0 
 1 0 0 
 
 0 0 1 0 •

 This finds the discrete-time approximation of the system.

In[35]:= ToDiscreteTime% , Sampled  Period 2

 0.986793 1.79374 0.183892 0.167272 


 
 0.0127356 0.800561 0.160081 0.157165 
 
 0.000761621 0.0986635 
 0.0933806 0.559313
Out[35]=  

 0.01 0 0 0 
 
 0 
 1 0 0 
 
 0 0 1 0 2
74 Control System Professional

 This plots the state response. We numericalize the input function to avoid supplying
Degree (°) in symbolic form. Note that SimulationPlot automatically picks up
as many points as needed for the discrete simulation to cover the specified time
frame.

In[36]:= SimulationPlot% , N .3 °, t, 150,


PlotLabel  "State Response of Submarine";

State Response of Submarine

0.001
0.0005

20 40 60 80 100 120 140


-0.0005
-0.001
-0.0015
-0.002

 4.3 Step, Impulse, and Other Responses


Using the general time-domain response functions defined in this chapter, it is easy to investi-
gate typical problems such as step, impulse, and ramp responses. This section presents some
examples.

 Let us create the second-order system with the natural frequency Ω and damping
ratio Ζ.
Ω2
In[37]:= s2Ω_, Ζ_  TransferFunction s,  
s 2  2 Ζ Ω s  Ω2

Ω2
 
Out[37]= 
  2  2 Ζ Ω   Ω2


 Here is the symbolic form of the step response for the critically damped case.

In[38]:= OutputResponses2Ωn , 1, UnitStept, t

Out[38]= t Ωn 1  t Ωn  t Ωn  UnitStept


4. Time-Domain Response 75

 This is the analog simulation of the step response for the system with the natural
frequency equal to unity and a particular value of Ζ from the underdamped case
region.
In[39]:= SimulationPlots21, .1, UnitStept, t, 50,
PlotLabel  "Underdamped Second Order System", PlotRange  All;

Underdamped SecondOrder System


1.75
1.5
1.25
1
0.75
0.5
0.25

10 20 30 40 50

 This plots the response for various values of the damping ratio Ζ. We can see that the
response changes from pure oscillation for Ζ= 0 (undamped case) to the exponential
for Ζ = 1.5 (overdamped case).
In[40]:= Plot3DEvaluateOutputResponses21, Ζ, 1, t 1 ,
t, 0, 20, Ζ, 0, 1.5, PlotLabel  "Second Order System",
AxesLabel  t, "Ζ 10", "y
t ", ViewPoint  0.920, 3.110, 1.750,
PlotRange  All, PlotPoints  50;

SecondOrder System
0

0.5
Ζ10
1

1.5
2
1.5
yt 1

0.5
0
20
15
10
5
t 0
76 Control System Professional

 Here is a third-order system. In the next inputs, we compute the step response for a
few values of the parameter Β defined as Β  p  ΖΩn  for the particular case of
Ζ  1  2.
Ω2 p
 
In[41]:= s3Ω_, Ζ_, p_  TransferFunction s, 

s 2  2 Ζ Ω s  Ω2
s  p

 p Ω2 
Out[41]= 

 p   2  2 Ζ Ω   Ω2  

 For Β  , the system degenerates to the second-order one.

In[42]:= MapAtLimit#, p   &, % , 2


 Ω2 
Out[42]= 

  2  2 Ζ Ω   Ω2


 This is its step response.


1
In[43]:= OutputResponse% . Ω  1, Ζ   , UnitStept, t  ComplexExpand 
2
Simplify
 
  3 t 
3 t2  3 Cos    3 Sin  
  t2 
1 3 t
Out[43]=  UnitStept
3  2 2 

 This is the step response for Β  2 .


1
In[44]:= OutputResponses31,  , 1, UnitStept, t  ComplexExpand  Simplify
2


 2 3 t 
t2 Sin  
Out[44]= 


t
1    
   2 

 UnitStept
 3 

 Finally, here is the step response for Β  1.


1 1
In[45]:= OutputResponses31,  ,  , UnitStept, t  ComplexExpand  Simplify
2 2
 

  3 t 
4  3 t2  Cos    3 Sin  
1 3 t
Out[45]=   t2  UnitStept
3  2 2 
4. Time-Domain Response 77

 This combines the three previous results. The solid, dashed, and dashed-dotted lines
represent the respective curves for Β  1 , 2 , and  .
In[46]:= PlotEvaluateJoin % , %% , %%% , t, 0, 8, PlotStyle 
Thickness.005, Dashing .03, Dashing .05, .02, .01, .02,
PlotLabel  "Step Response";

Step Response

0.8

0.6

0.4

0.2

2 4 6 8

 This is the simulation of a ramp response of the third-order system for a particular
set of parameters. To visualize the steady-state error, we include the dashed straight
line.
In[47]:= SimulationPlots31., .5, 1., t, t, 0, 20,
Epilog  Dashing 0.025, Line0, 0, 20, 20,
PlotLabel  "Ramp Response";

Ramp Response
17.5
15
12.5
10
7.5
5
2.5

5 10 15 20

 Consider a two-input, second-order system.

In[48]:= system  StateSpace0, 2, 1, 1, 1, 1, 1, 0, 1, 2


 0 2 1 1 
 
Out[48]=  1 1 1 0 
 
 1 2 0 0 •
78 Control System Professional

 This applies the impulse function to all inputs in turn and simplifies the result.

In[49]:= OutputResponse% , DiracDeltat, t  ComplexExpand  Simplify

t 
 
 7 t 
11 7 Sin    7 Cos  
   2 
1 7 t
Out[49]=  UnitStept,
7  2 2 
 
1  t2  7 t  7 t 
7 Cos    5 7 Sin  
     UnitStept
7  2 2 

 Here is the plot of the impulse responses. Note that we have joined the lists in the
previous result to plot all curves in one graph. The impulse responses for the first
and second inputs are shown as a solid and a dashed line, respectively.
In[50]:= PlotEvaluateJoin  % , t, 0, 10, PlotRange  All,
PlotStyle  Thickness.005, Dashing .05, .02,
PlotLabel  "Impulse Response";

Impulse Response

1.5

0.5

2 4 6 8 10
-0.5

-1
4. Time-Domain Response 79

 This is the simulated (rather than computed symbolically) impulse response for the
first input. As mentioned in Section 4.2, SimulationPlot performs the discrete
simulation for the input signal in a form of the Dirac delta function.
In[51]:= SimulationPlotsystem, DiracDeltat,
t, 10, ControlInputs  1, Sampled  Period .25,
PlotLabel  "Discrete Simulation of Impulse Response";

Discrete Simulation of Impulse Response

1.5

0.5

2 4 6 8 10
-0.5

-1

 To perform the analog simulation, we can introduce an approximation of the Dirac


delta function by an impulse with a finite width. In myDiracDelta, the parameter Τ
determines the offset of the impulse along the time axis and Α determines the width
of the impulse.
Α
In[52]:= myDiracDeltat_, Τ_: 0, Α_: 100. :  UnitStept  Τ

tΤ

In[53]:= SimulationPlotsystem, myDiracDeltat, t, 10, ControlInputs  1,


PlotPoints  50, PlotLabel  "Analog Simulation of Impulse Response";

Analog Simulation of Impulse Response

1.5

0.5

2 4 6 8 10
-0.5
5. Classical Methods of Control Theory

This chapter introduces several classical control theory tools available in Control System Profes-
sional. Some of the functions described here are routines adapted from the Mathematica Applica-
tions Library package Electrical Engineering Examples; the proper extensions have been added
to allow handling of the control objects. If you already have Electrical Engineering Examples
installed, all the functionality you are accustomed to should still be available.

 5.1 Root Loci

RootLocusPlotsystem, k, kmin, kmax


generate a root locus plot for system 
when parameter k  varies from kmin to kmax
Plotting the root loci.

RootLocusPlot graphs the roots of the characteristic equation (the root loci) while some
parameter, typically (but not necessarily) the gain, varies. The input system may be in
state-space or transfer function form and may or may not depend on the parameter k. In the
latter case, the parameter is assumed to be the gain of the open-loop system. Both discrete-
and continuous-time systems can be analyzed using this function. As in the Electrical Engineer-
ing Examples, RootLocusPlot (as well as BodePlot, NyquistPlot, and NicholsPlot)
also accepts the body of the transfer function object as the input system.

 Load the application.

In[1]:=  ControlSystems`

 Here is a double-integrator system.


s 1
In[2]:= TransferFunction s,  
s2
1 
Out[2]=  2 

5. Classical Methods of Control Theory 81

 This plots the root loci. Note that because the system does not contain the parameter
k, it is assumed to be the gain.
In[3]:= RootLocusPlot% , k, 0, 10;

Im
1

0.5

Re
-8 -6 -4 -2

-0.5

-1

RootLocusPlot accepts the options for ListPlot as well as several specific options that
define the appearances of poles and zeros, and the number of points at which to sample the
range for k.

option name default value

PoleStyle Automatic styles for poles


ZeroStyle Automatic styles for zeros
PlotPoints 10 number of times the parameter is sampled

Options specific to RootLocusPlot.

As an example of using RootLocusPlot in feedback design, consider the system shown in


Figure 5.1, for which we find coefficients k such that the damping ratio of the dominant
closed-loop poles is 0.4 (cf. Ogata (1990)). The input or reference signal is denoted as r, the
output or controlled signal is c, and the actuating or error signal is e.

r  e 20 c
Gs 
ss 1 s  4


Hs  1  ks

Figure 5.1. Example system for root locus construction.


82 Control System Professional

 This describes the block with the transfer function Gs .


20
In[4]:= g  TransferFunction s,  
s s  1 s  4

20
Out[4]=  
 
   1   4

 This defines the transfer function Hs .

In[5]:= h  TransferFunction s, 1  k s


Out[5]= k1

 The open-loop system is formed by the serial connection of the blocks.

In[6]:= SeriesConnectg , h 

20 k   1 
 
Out[6]=  
    1   4

The suitable values of k correspond to intersections of the root locus curve with the straight
line depicting the locus of poles of the generic second-order system

Ω2n
Hs  

s2  2ΖΩn s  Ω2n

for the chosen value of Ζ , where Ωn is the natural frequency and Ζ is the damping ratio.
5. Classical Methods of Control Theory 83

 This plots root loci together with the line for the chosen value of Ζ. The natural
frequency Ω has been picked quite arbitrarily, just to display the line in some
bounds. Note that in this case parameter k is not the gain. As we can see, the line
intersects the root locus branch somewhere between 5 and 6 points, and then again
between points 14 and 15.
In[7]:= RootLocusPlot% , k, 0, 2, PlotPoints  20, PoleStyle  PointSize.005,

2
Epilog  Line 0, 0, Ζ Ω, Ω 1  Ζ . Ω  10, Ζ  .4 ,
PlotLabel  "Root Loci";

Root Loci Im
6

Re
-4 -3 -2 -1
-2

-4

-6

 Roughly estimating that the intersections are 0.2 and 0.5 off the respective points, we
get some estimates of parameter k that provide the required damping ratio.
kmax
In[8]:= kmax  2; points  20;  #  1 &
5.2, 14.5
points  1

Out[8]= 0.442105, 1.42105

 Here are the corresponding expressions for the closed-loop system.

In[9]:= results  FeedbackConnectg , h  . List


Thread k  %  Simplify

 
20 20
Out[9]=   ,  
   
  5   12.8421   20
3 2   5   32.4211   20
3 2

 This simulates the step responses for the chosen values of k. The first system exhibits
a faster response with reasonable overshoot compared to the second system.
In[10]:= SimulationPlot#, UnitStept, t, 5,
PlotRange  All, PlotLabel  "Step Response" &
results;
84 Control System Professional

Step Response

0.8

0.6

0.4

0.2

1 2 3 4 5

Step Response

0.8

0.6

0.4

0.2

1 2 3 4 5

RootLocusAnimation complements RootLocusPlot and provides information on the


direction of the evolution of root loci. The syntax for the two function is identical; the only
exception is that the option PlotPoints is meaningless for the animation and is replaced by
Frames, which determines the number of frames the animation should contain.

RootLocusAnimationsystem, k, kmin, kmax


generate a sequence of root locus plots for system 
with parameter k running from kmin to kmax
Animating the root loci.
5. Classical Methods of Control Theory 85

 5.2 The Bode Plot

5.2.1 The Basic Function

The Bode plot is the first example of the frequency response analysis tools that we consider in
this chapter. By frequency response, we mean the response to purely sinusoidal signals. Bode
Plot depicts, in the form of GraphicsArray, the frequency dependence of the magnitude
and phase response. The magnitude response is the ratio of the span of the output sinusoid to
the input one, and the phase response is the phase difference between them. The magnitude
and phase dependencies are plotted in the double-logarithmic and semilogarithmic scales,
respectively.

BodePlotsystem generate a Bode plot for system

BodePlotsystem, w, wmin, wmax


generate a Bode plot for 
frequency w running from wmin to wmax
Creating the Bode plots.

Like all other plotting routines in Control System Professional, BodePlot accepts a system in
state-space or transfer function form in the continuous- or discrete-time domain. Specifying
the frequency range is optional. If it is not supplied, BodePlot will try to determine a suitable
range automatically. Also optional is the naming of the frequency variable in supplying the
desired frequency range; {w, wmin, wmax works as well as {wmin, wmax. This should come
as no surprise if you recall that the variable in TransferFunction is an internal parameter
and does not have any meaning outside the scope of the TransferFunction object.

 Consider again the second-order system.

Ω2
In[11]:= s2Ω_, Ζ_  TransferFunction s,  ;
s2  2 Ζ Ω s  Ω2
86 Control System Professional

 This is the Bode plot for the unity natural frequency and damping ratio. The
frequency range is not specified and is determined automatically.
In[12]:= BodePlots21, 1;

Magnitude dB
-10
-20
-30
-40
0.1 0.2 0.5 1 2 5 10
Frequency RadSecond

-25
Phase deg

-50
-75
-100
-125
-150
0.1 0.2 0.5 1 2 5 10
Frequency RadSecond

 This gives the Bode plot over a wider frequency range.

In[13]:= BodePlots21, 1, .01, 100;

0
Magnitude dB

-20
-40
-60
-80
0.01 0.1 1 10 100
Frequency RadSecond

0
Phase deg

-25
-50
-75
-100
-125
-150
-175
0.01 0.1 1 10 100
Frequency RadSecond

By default, BodePlot tries to unwrap the phase in order to present a smooth phase curve
should branch cuts be detected. The value Automatic for the option PhaseRange typically
5. Classical Methods of Control Theory 87

(unless the gain and phase margins are to be plotted—see below) corresponds to such behav-
ior. PhaseRange allows also to shift the graph to another phase range which must be speci-
fied in the form PhaseRange  {min, max, with the new limits min and max given in degrees.
Very rapid changes in phase dependence may cause errors in phase unwrapping. The safest
(and fastest) choice is PhaseRange  {-180, 180}, in which case no additional processing
of the phase is performed.

Another way to eliminate possible errors in phase unwrapping is to increase the number of
points at which the transfer function is sampled by changing the option PlotPoints; this is
also useful if rapid changes in the magnitude or phase curve are not plotted satisfactorily
otherwise. For some plots, you may wish to use linear spacing between samples instead of the
default logarithmic spacing. This can be done by using PlotSampling  LinearSpacing.

The option PhaseRange is in no way a substitute for the standard Mathematica plotting
option PlotRange and, in fact, works quite differently. If, for example, a plot does not have
any part in the range specified in PlotRange, nothing will appear in the graph. On the other
hand, PhaseRange will bring the graph into the specified range based on the principle that
all 360° intervals are physically equivalent.

option name default value

PhaseRange Automatic the range for plotting the phase curve


PlotPoints 30 how many points
of the graph are required
PlotSampling LogSpacing distribute points evenly on
the logarithmic or linear scale
Margins False whether to compute and
show gain and phase margins
MarginStyle Automatic a list of lists of graphics
primitives to use for each margins

Options specific to BodePlot.

BodePlot also accepts options pertinent to ListPlot and GraphicsArray. Because a plot
consists of two subplots, certain options—namely, AspectRatio, AxesLabel, AxesOrigin,
FrameLabel, Epilog, Prolog, FrameTicks, GridLines, Ticks, and PlotRange—are
handled in a nonstandard fashion. Given a list of two items as input, they will apply the first
item to the magnitude plot and the second to the phase plot. Other options are applied equally
to both plots or to GraphicsArray itself.

BodePlot operates on MIMO systems by grouping the graphs related to each input and
88 Control System Professional

plotting as many graphs as there are inputs. You may specify options for each input differ-
ently by wrapping option values into additional lists. By default, the graphs related to different
outputs in one plot are distinguished by the Hue value. This can be changed using the stan-
dard PlotStyle option.

 Here is a single-input, multiple-output system, of which each input-output pair is a


second-order system with a different value of damping ratio.
1
In[14]:= TransferFunction s, Table  , Ζ, .05, .8, .25
s2  2 s Ζ  1


1
 

 2  0.1   1

 1
 

 2  0.6   1
Out[14]= 

 1
 

   1.1   1
 2


 1
 

 2  1.6   1

 This is its Bode plot.

In[15]:= BodePlot% , .1, 10,


PlotStyle  Dashing .05, .01, .01, .01, Dashing .05, .01,
Dashing .05, Thickness.001, PlotPoints  200;

20
Magnitude dB

10
0
-10
-20
-30
-40
0.1 0.2 0.5 1 2 5 10
Frequency RadSecond

0
Phase deg

-25
-50
-75
-100
-125
-150
-175
0.1 0.2 0.5 1 2 5 10
Frequency RadSecond

 Of course, you can always supplement the results from BodePlot with diagrams
obtained using the built-in Mathematica functions. This plots the gain versus
5. Classical Methods of Control Theory 89

frequency and damping ratio for the generic second-order system. To make a more
attractive graphic, we picked up some coefficients for the x and y axes.
In[16]:= ParametricPlot3D
Evaluate10 Log 10, Ω, Ζ 50, 20 Log 10, Abss21, Ζ Ω1, 1,
Ω, .005, 5, Ζ, 0, 1.5, PlotPoints  40, 20,
AxesLabel  "10 Log 10, Ω", "Ζ 50", "Gain dB", Boxed  False;

60

Ζ50 40

20

0
20

Gain dB 0

-20

-10
10-5
0 5
10 Log10, Ω

5.2.2 Gain and Phase Margins

Important insight into the stability of the closed-loop system can be achieved by analyzing the
gain and phase margins of the system before closing the loop. The margins can be computed
using GainPhaseMargins and displayed on the Bode plot using the option Margins, which
accepts either the result of GainPhaseMargins (if it was computed prior to the call to Bode
Plot) or True to compute the margins transparently. The MarginStyle option can be used
to specify the graphics primitive for margins in a manner similar to the PlotStyle option. If
Margins is set to False, the margins are not computed (the default).
90 Control System Professional

GainPhaseMarginssystem compute gain and phase margins for system

BodePlotsystem, Margins  margins


show precomputed gain and
phase margins on the Bode plot

BodePlotsystem, Margins  True


compute and show gain and phase margins
Gain and phase margins.

As an exercise, let us select gain k for the system shown in Figure 5.2 such that the phase
margin is greater than 30° and the gain margin is greater than 10 dB (Brogan (1991)).

r  e ks  50 c
ss  10


1
s  20

Figure 5.2. Example system for gain and phase margin selection.

 This defines the plant.


k s  50
In[17]:= g  TransferFunction s,  
s s  10

k   50 
Out[17]=  
    10

 This is the regulator.


1
In[18]:= h  TransferFunction s,  
s  20

1
Out[18]=   
  20
5. Classical Methods of Control Theory 91

 Here is the open-loop system formed from the above blocks.

In[19]:= SeriesConnectg , h 


 k   50
Out[19]= 
 
    10   20

 This is the Bode plot for a particular value of k.

In[20]:= BodePlot% . k  4.;

20
Magnitude dB

0
-20
-40
-60
-80
-100
0.1 1 10 100 1000
Frequency RadSecond

-100
Phase deg

-120
-140
-160
-180
0.1 1 10 100 1000
Frequency RadSecond

We observe that at Ω  10 the phase is around 150° , which would give the desired phase
margin of 30° if we increase the gain by 24 dB, the value by which the current gain at this
frequency is less than zero. That would lead to a gain margin somewhat more than 10 dB at
Ω  24, the current crossover frequency, which would satisfy the specification.
92 Control System Professional

 This is the Bode plot for the increased gain, with the gain and phase margins
displayed. We can see that the specifications are met.

In[21]:= BodePlot%% . k  4. 10 , Margins  True;


24 20

Magnitude dB
40
20
0
-20
-40
-60
-80
0.1 1 10 100 1000
Frequency RadSecond

-100
Phase deg

-120
-140
-160
-180
0.1 1 10 100 1000
Frequency RadSecond

Gain and phase margins are determined by finding the crossover points of the frequency
response, which can be done either analytically or from the interpolation of the response
curve computed on a frequency grid. The method can be selected using the option Method,
which accepts values Analytic or Interpolation. The freedom of choosing the method is
restricted to continuous-time systems; for discrete-time systems, the margins are always
computed via interpolation.

option name default value

Method Automatic whether the margins should be


computed analytically or by interpolation

Options specific to GainPhaseMargins.

When margins are to be plotted, the Automatic value for PhaseRange corresponds to the
phase range of {-360, 0} degrees. Using the option PhaseRange, you may set the phase
range differently.
5. Classical Methods of Control Theory 93

 5.3 The Nyquist Plot


The Nyquist plot allows us to gain insight into the stability of the closed-loop system by
analyzing the contour of the frequency response function on the complex plane.

NyquistPlotsystem generate a Nyquist plot for system

NyquistPlotsystem, w, wmin, wmax


generate a Nyquist plot for 
frequency w running from wmin to wmax
Creating the Nyquist plots.

If no frequency range is specified, NyquistPlot will try to plot the graph for both negative
and positive frequencies (a task that can be avoided by plotting only half of the curve and
then reflecting it over the real axis).

Note that jumps may appear in the Nyquist plot when the frequency response changes rap-
idly. That may be corrected by choosing a higher value for the PlotPoints option.

 Consider an open-loop transfer function.


1
In[22]:= TransferFunction s,  
s  12

 
1
Out[22]=
   1

2
94 Control System Professional

 This is the corresponding Nyquist plot. The contour does not encircle the  1, 0
point and the transfer function does not have unstable poles; therefore, the
closed-loop system will be stable.
In[23]:= NyquistPlot% ;

Im

0.6

0.4

0.2

Re
0.2 0.4 0.6 0.8 1

-0.2

-0.4

-0.6

Like the other frequency response plotting functions, NyquistPlot is capable of handling
nonpolynomial transfer functions. Note, however, that such systems must be supplied in
transfer function form and the desired frequency range must be specified, since conversion
from the state space works for linear systems only and so does the routine that determines
the default frequency range.

 Here is a system consisting of a transport lag e Τs and first-order lag 1  1  Ts , for
the unit values of Τ and T .
s
In[24]:= TransferFunction s,  
1s
 
Out[24]=   
1
5. Classical Methods of Control Theory 95

 This is the Nyquist plot for this system.

In[25]:= NyquistPlot% , .01, 20, PlotPoints  500;

Im

0.2

Re
-0.4 -0.2 0.2 0.4 0.6 0.8 1

-0.2

-0.4

-0.6

-0.8

Like BodePlot, NyquistPlot accepts the PlotPoints and PlotSampling options, as


well as options pertinent to ListPlot.

 5.4 The Nichols Plot


NicholsPlot gives yet another way to depict frequency response information—by plotting
the magnitude versus phase curve in the semilogarithmic scale.

NicholsPlotsystem generate a Nichols plot for system

NicholsPlotsystem, w, wmin, wmax


generate a Nichols plot for 
frequency w running from wmin to wmax
Creating the Nichols plots.

 Here is an open-loop transfer function for the spacecraft attitude control system,
compensated with a PID controller from Franklin et al. (1991).
.05 10 s  1 s  .005 .9 2
 
In[26]:= TransferFunction s, 
s s 2 s  2

0.09   0.005 10   1 


Out[26]=  

 3   2

96 Control System Professional

 This is the Nichols plot for the system.

In[27]:= NicholsPlot% ;

0
Gain dB
-20

-40

-60

-80
-180 -170 -160 -150 -140 -130 -120
Phase degrees

NicholsPlot accepts the options PlotPoints, PlotSampling, and PhaseRange, as does


BodePlot, as well as the options pertinent to ListPlot.

 5.5 The Singular-Value Plot


For MIMO systems, BodePlot returns a total of p q individual Bode plots, and conse-
quently, the amount of information quickly grows with the number of inputs p and outputs q .
SingularValuePlot provides a means to generalize this information by generating a plot
of the frequency dependence of singular values of the transfer matrix evaluated at different
values of s  jΩ (or z  e jΩT for discrete-time systems, T being the sampling period).

SingularValuePlotsystem
generate a singular-value plot for system

SingularValuePlotsystem, w, wmin, wmax


generate a singular-value plot for 
frequency w running from wmin to wmax
Creating the singular-value plots.
5. Classical Methods of Control Theory 97

 Here is a mixing tank system (see Section 10.1).

In[28]:= StateSpace.01, 0, 0, .02,


1, 1, .004, .002, .01, 0, 0, 1

0.01 0

1 1
 0 0.02 0.004 0.002

Out[28]= 

 0.01 0 0 0

 0 1 0 0

 This plots the frequency dependence of the singular values.

In[29]:= SingularValuePlot% ;
Singular Values dB

-10

-20

-30

-40

0.001 0.005
0.01 0.050.1 0.5 1
Frequency RadSecond
6. System Interconnections

This chapter introduces the tools needed to construct a composite system based on a given
system topology and descriptions of the blocks. SeriesConnect, ParallelConnect ,
FeedbackConnect, and StateFeedbackConnect perform elementary interconnections;
GenericConnect handles these as well as more convoluted cases. The auxiliary functions
Subsystem, DeleteSubsystem, and MergeSystems provide a means of manipulating
system contents other than interconnections. All the functions accept (and operate analo-
gously on) continuous- and discrete-time objects, but the systems to be connected must be in
the same domain (and sampled at the same rate, if discrete-time) to produce a meaningful
result. It is, therefore, the responsibility of the user to perform the necessary conversions prior
to calling the interconnecting functions.

The interconnection procedures do not necessarily result in minimal state models, so some
model reduction techniques (see Chapter 8) may be appropriate.

 6.1 Elementary Interconnections


Elementary interconnections include serial (cascade), parallel, and feedback interconnections.
The subsystems can be supplied in either state-space or transfer function form. If of two
subsystems one is in state space, the other is transformed to that form too, and a state-space
object is returned. If both systems are entered as transfer functions, this is the form of the
resultant system. If the transfer functions of the blocks are defined using differently named
variables, the first variable encountered is used in the result. In elementary and other intercon-
nections, inputs and outputs are referred to by their index in the input or output vectors.

6.1.1 Connecting in Series

SeriesConnect finds the description of an aggregate system composed of two subsystems


connected in series, as shown in Figure 6.1. The aggregate has inputs of system i , outputs of
 x 
 i 
system j , and states of both systems, x   . Note that not all outputs of the first system
 x j 
should necessarily be connected to inputs of the second system.
6. System Interconnections 99

yi  u j
ui yj
System i System j

Figure 6.1. Series interconnection.

SeriesConnectsystem1 , system2 
find the aggregate system by connecting all outputs
of system1 to corresponding inputs of system2

SeriesConnectsystem1 , system2 , o, i


connect the output o of
system1 to the input i of system2

SeriesConnectsystem1 , system2 , o1 , i1 , o2 , i2 , …


connect outputs ok of system1 to inputs ik of system2

Series connection of two systems.

 Load the application.

In[1]:=  ControlSystems`

 Here are two systems in state-space form.

In[2]:= ss1  StateSpacea11 , a12 , a21 , a22 ,


b11 , b12 , b21 , b22 , c11 , c12 , c21 , c22 , d11 , d12 , d21 , d22 

 a11 a12 b11 b12




a21
a22 b21 b22
Out[2]=
c11
c12 d11 d12

 c21 c22 d21 d22 •

In[3]:= ss2  StateSpaceA11 , A12 , A21 , A22 ,


B1 , 0, 0, B2 , C11 , C12 , D11 , D12 

 A11 A12 B1 0



Out[3]= A21 A22 0 B2

 C11 C12 D11 D12 •
100 Control System Professional

 This connects the systems in series.

In[4]:= SeriesConnectss1, ss2


 a11 a12 0 0 b11 b12


a21 a22 0 0 b21 b22


Out[4]= B1 c11 B1 c12 A11 A12 B1 d11 B1 d12


B c B c A A B d B d
2 21 2 22 21 22 2 21 2 22


 c11 D11  c21 D12 c12 D11  c22 D12 C11 C12 d11 D11  d21 D12 d12 D11  d22 D12 •

 The result is, of course, the familiar StateSpace object.

In[5]:= %  StandardForm

Out[5]//StandardForm=
StateSpacea11 , a12 , 0, 0, a21 , a22 , 0, 0,
B1 c11 , B1 c12 , A11 , A12 , B2 c21 , B2 c22 , A21 , A22 ,
b11 , b12 , b21 , b22 , B1 d11 , B1 d12 , B2 d21 , B2 d22 ,
c11 D11  c21 D12 , c12 D11  c22 D12 , C11 , C12 , d11 D11  d21 D12 , d12 D11  d22 D12 

 Now the second output of the first system is connected to the first input of the
second system. Another output and input remain loose.
In[6]:= SeriesConnectss1, ss2, 2, 1

 a11 a12 0 0 b11 b12




a21
a22 0 0 b21 b22

Out[6]= B1 c21 B1 c22 A11 A12 B1 d21 B1 d22

0
0 A21 A22 0 0

 c21 D11 c22 D11 C11 C12 d21 D11 d22 D11 •

 Now all the outputs and inputs are connected again, but this time in the reverse
order.
In[7]:= SeriesConnectss1, ss2, 2, 1, 1, 2


 a11 a12 0 0 b11 b12


a21 a22 0 0 b21 b22


Out[7]= B1 c21 B1 c22 A11 A12 B1 d21 B1 d22


B c B c A A B d B d
2 11 2 12 21 22 2 11 2 12


 c21 D11  c11 D12 c22 D11  c12 D12 C11 C12 d21 D11  d11 D12 d22 D11  d12 D12 •
6. System Interconnections 101

 Here is an integrator given in transfer function form.


1
In[8]:= integrator  TransferFunction s,  
s
1 
Out[8]=  


 This attaches the integrator to the first output of system ss1. Notice that SeriesCon
nect returns the result in state-space form as soon as one of the input systems is
given in that form.
In[9]:= SeriesConnectss1, integrator, 1, 1


 a11 a12 0 b11 b12


a21 a22 0 b21 b22
Out[9]=


c11 c12 0 d11 d12


 0 0 1 0 0 •

 Here both input systems are in transfer function form, and so is the result.

In[10]:= SeriesConnectintegrator, integrator

1 
Out[10]= 2 


 This is a slightly more complicated connection—the integrator is connected to the


third output of the transfer function system tf.

In[11]:= tf  TransferFunction s,


s s s s 1 s
  ,  ,   ,   ,   ,  
s  1
s  2

2 2
s  2
2
s  2
2
s  2
2
s  2
2
s  1
2

  


2 2
  1   22
  2

 
 2  2
Out[11]=

  2   2

1 
2 2

   2   1

In[12]:= SeriesConnecttf, integrator, 3, 1


  2

1 1
Out[12]=
    2   1
2
102 Control System Professional

SeriesConnect can cascade only two systems. However, the Mathematica language makes
extensions to any number of systems fairly straightforward.

 Here is a function that connects any number of matching subsystems in series.

In[13]:= cascades__ : Fold SeriesConnect, Firsts, Rests

 Using the new function, this command cascades a set of four abstract systems.
Notice that the aggregate remains partially unevaluated until the systems are
specified.
In[14]:= cascades1, s2, s3, s4

Out[14]= SeriesConnectSeriesConnectSeriesConnects1, s2, s3, s4

 This built-in function reveals the structure of the cascade.

In[15]:= TreeForm% 

Out[15]//TreeForm=
SeriesConnect  , s4
SeriesConnect  , s3
SeriesConnects1, s2

 We prepare a set of first-order systems with simple poles to be used instead of the
abstract systems.
1
In[16]:= TableTransferFunction s,  , i, 0, 3
s i
   
1 1 1 1
Out[16]=    ,   ,   ,   
 1 2 3

 Now the cascade can be found in closed form. The cascade is shown in Figure 6.2.

In[17]:= %% . Thread s1, s2, s3, s4  % 


1
Out[17]= 
 
   1   2   3

u 1 1 1 1 y

s s 1 s 2 s 3

Figure 6.2. Cascade of first-order systems.


6. System Interconnections 103

6.1.2 Connecting in Parallel

The parallel interconnection of subsystems according to Figure 6.3 can be accomplished with
the function ParallelConnect. The subsystems may or may not have some shared inputs
and some summed outputs. The aggregate has these shared inputs and summed outputs as
well as other inputs and outputs of the components. The states of the aggregate come from
both subsystems. As with all elementary interconnection functions, the systems may be in
either state-space or transfer function form, or both.

u System i y
yi 
ui

uj yj

System j

Figure 6.3. Parallel interconnection.

ParallelConnectsystem1 , system2 
connect all inputs of system1  with all inputs of 
system2  and sum all corresponding outputs

ParallelConnectsystem1 , system2 , i1 , i2 , o1 , o2 


connect the input i1 of system1 with the input i2 of
system2 and sum outputs o1 of system1 and o2 of system2

ParallelConnectsystem1 , system2 ,
i11 , i21 , i12 , i22 , …, o11 , o21 , o12 , o22 , …
connect the inputs i1k  of system1 
with the inputs i2k  of system2  and sum outputs 
o1k  of system1  with outputs o2k  of system2

Parallel connection of two systems.


104 Control System Professional

 These are two state-space systems defined earlier.

In[18]:= ss1  StateSpacea11 , a12 , a21 , a22 ,


b11 , b12 , b21 , b22 , c11 , c12 , c21 , c22 , d11 , d12 , d21 , d22 

a12 b11 b12



 11
a

a a22 b21 b22
21
Out[18]=
c11
c12 d11 d12

 c21 c22 d21 d22 •

In[19]:= ss2  StateSpaceA11 , A12 , A21 , A22 ,


B1 , 0, 0, B2 , C11 , C12 , D11 , D12 

 A11 A12 B1 0


Out[19]= A21 A22 0 B2

 C11 C12 D11 D12 •

 This connects correspondingly numbered inputs of the subsystems and adds the first
output of ss2 to both outputs of ss1.
In[20]:= ParallelConnectss1, ss2, 1, 1, 2, 2, 1, 1, 2, 1


 a11 a12 0 0 b11 b12


a21 a22 0 0 b21 b22


0 0 A11 A12 B1 0
Out[20]=

0 0 A21 A22 0 B2

c c12 C11 C12 d11  D11 d12  D12
11

 c21 c22 C11 C12 d21  D11 d22  D12 •

 This takes two systems represented by the same transfer function tf and connects
all inputs and sums all outputs in the criss-cross order.
In[21]:= tf  TransferFunction s,
s s s s 1 s
  ,  ,   ,   ,   ,  
s  1
s  2

2 2
s  2
2
s  2
2
s  2
2
s  2
2
s  1
2
  
 
 2

  12   22   2

 

Out[21]=  2  2

  2   2

1 
2 2

   2   1
6. System Interconnections 105

In[22]:= ParallelConnecttf, tf,


1, 2, 2, 1, 1, 3, 2, 2, 3, 1  Simplify

  2  4   5 1


2 2
  12     2
2

2  2
Out[22]=
 2  2

  2   2



1  2  4   5
2 

 
 
   2   12   22

ParallelConnect can be used to sum the outputs or just to connect the inputs without
summing the outputs. Examples of such usage are given in Section 10.7.

6.1.3 Closing Feedback Loop

Feedback interconnections of the types shown in Figure 6.4 are performed with the function
FeedbackConnect. The function may just close the loop (Figure 6.4a), or may include a
second system (typically a controller) in the feedback (Figure 6.4b). Either negative (default),
positive, or mixed feedback can be formed. The connection specifications may be omitted if all
corresponding inputs and outputs are to be used. The inputs and outputs of the aggregate are
the ones of the first system. The states come from all subsystems.

u System y u System i y
 ui yi  ui yi

 

yj uj
a b System j

Figure 6.4. Feedback interconnections.


106 Control System Professional

FeedbackConnectsystem
feed all the outputs of system back to the 
corresponding inputs with a negative sign

FeedbackConnectsystem, type
form either negative or 
positive feedback depending on type

FeedbackConnectsystem, o, i


feed the output o of system back to the input i

FeedbackConnectsystem, o, i, type


use type for the connection

FeedbackConnectsystem, o1 , i1 , o2 , i2 , …


connect several outputs ok  and inputs ik

FeedbackConnectsystem, o1 , i1 , o2 , i2 , …, type


use type for all connections

FeedbackConnectsystem, o1 , i1 , type1 , o2 , i2 , type2 , …


use typek  when connecting output ok  to input ik

Closing the feedback loop.


6. System Interconnections 107

FeedbackConnectsystem1 , system2 
put system2  in the negative feedback loop for system1

FeedbackConnectsystem1 , system2 , type


create feedback specified by type

FeedbackConnectsystem1 , system2 , o1 , o2 , …, i1 , i2 , …


close the negative feedback loop for system1 
with system2  by connecting outputs ok  of 
system1  to sequentially numbered inputs of 
system2  and sequentially numbered outputs of 
system2  to inputs ik  of system1

FeedbackConnectsystem1 , system2 , o1 , o2 , …, i1 , i2 , …, type


use type for all connections

FeedbackConnectsystem1 , system2 ,
o1 , o2 , …, i1 , type1 , i2 , type2 , …
use typek when connecting input ik

Feedback interconnections with second system.

The type descriptor for FeedbackConnect should be one of the reserved words Positive or
Negative.

 Consider a second-order system with two inputs and two outputs.

In[23]:= ss  StateSpaceDiagonalMatrixa1 , a2 , DiagonalMatrixb1 , b2 ,


DiagonalMatrixc1 , c2 , DiagonalMatrixd1 , d2 

a 0 b1 0

 1
0 a 0 b2

Out[23]=
2
c1 0 d1 0

 0 c2 0 d 2 •
108 Control System Professional

 This forms the negative feedback by connecting corresponding outputs and inputs.

In[24]:= FeedbackConnectss


b1 c1 d2  1 b1 d1 d2  1
 a1   
 0 b1  

 0

d2 d1  d1  d2  1 d2 d1  d1  d2  1

b2 c2 d1  1 b2 d1  1 d2
0 a2  

 0 b2  


d2 d1  d1  d2  1 d2 d1  d1  d2  1

Out[24]=
c1 d1 d2  1 d12 d2  1
c1  

 0 d1  

 0
d2 d1  d1  d2  1 d2 d1  d1  d2  1


c2 d1  1 d2 d1  1 d22
0 c2  

 0 d2  


 d2 d1  d1  d2  1 d2 d1  d1  d2  1 •

 We can use built-in Mathematica functions to simplify the result.

In[25]:= Together  %


 d1 a1  a1  b1 c1 b1


 0  0
d1  1 d1  1

d2 a2  a2  b2 c2 b2

0 
 0 
d2  1 d2  1
Out[25]=

c1 d1

 0  0
d1  1 d1  1


c2 d2
0  0 
 d2  1 d 2  1 •

 This forms the closed loop for the first two inputs and outputs of the transfer
function tf.

In[26]:= tf  TransferFunction s,


s s s s 1 s
  ,  ,   ,   ,   ,  
s  1
s  2

2 2
s  2
2
s  2
2
s  2
2
s  2
2
s  1
2

  


2 2
  1   22
  2

 
 2  2
Out[26]=

  2   2

1 
2 2

   2   1
6. System Interconnections 109

In[27]:= FeedbackConnecttf, 1, 1, 2, 2  Simplify


  2    2    12   2



 


  7   22 3  34 2  28   8
5 4 5  7 4  22 3  34 2  28   8


   12   2  3  3 2  5   2
Out[27]=  

  



  7   22 3  34 2  28   8
5 4   7 4  22 3  34 2  28   8
5


2 4  9 3  15 2  11   4  6  10 5  40 4  85 3  102 2  64   15



 


 
   2 5  7 4  22 3  34 2  28   8   12   2 5  7 4  22 3  34 2  28   8

 Now we plug the system ss in the positive feedback loop for ss1 (assuming, for
simplicity, that there is no direct transmission term in ss).
In[28]:= ss1  StateSpacea11 , a12 , a21 , a22 ,
b11 , b12 , b21 , b22 , c11 , c12 , c21 , c22 , d11 , d12 , d21 , d22 

a12 b11 b12



 11
a

a a22 b21 b22
21
Out[28]=
c11
c12 d11 d12

 c21 c22 d21 d22 •

In[29]:= FeedbackConnectss1, ss . d_  0, Positive

 a11 a12 b11 c1 b12 c2 b11 b12




a21
a22 b21 c1 b22 c2 b21 b22

b1 c11 b1 c12 a1  b1 c1 d11 b1 c2 d12 b1 d11 b1 d12
Out[29]=
b2 c21 b2 c22 b2 c1 d21 a2  b2 c2 d22 b2 d21 b2 d22

c11 c12 c1 d11 c2 d12 d11 d12

 c21 c22 c1 d21 c2 d22 d21 d22 •

 This connects ss1 and ss according to Figure 6.5 (under the same simplifying
assumption).
 1 1
u   ss1 y
 2 2

1 1
ss
2 2

Figure 6.5. Example of feedback interconnection.


110 Control System Professional

In[30]:= FeedbackConnectss1, ss . d_  0, 1, 2, 2, Positive, 1, Negative

b11 c2 b12

 11
a a12 b12 c1 b11

a b21 c2 b22
21 a22 b22 c1 b21

b1 c11 b1 c12 a1  b1 c1 d12 b1 c2 d11 b1 d11 b1 d12

Out[30]=
b2 c21 b2 c22 b2 c1 d22 a2  b2 c2 d21 b2 d21 b2 d22

c11
c12 c1 d12 c2 d11 d11 d12

 c21 c22 c1 d22 c2 d21 d21 d22 •

The connection functions described in this section accept transfer functions in arbitrary (rather
than rational polynomial) form as long as no type conversion or subsystem selection has to be
made.

 This is the serial connection of two systems described by the transfer functions g[s]
and h[s].
In[31]:= SeriesConnectTransferFunction s, g s, TransferFunction s, h s


Out[31]=  g h 

 Here are the same systems connected in parallel.

In[32]:= ParallelConnectTransferFunction s, g s, TransferFunction s, h s


Out[32]=  g  h 

 This is the negative feedback connection.

In[33]:= FeedbackConnectTransferFunction s, g s, TransferFunction s, h s


 


g
Out[33]=
 g h  1

 6.2 Arbitrary Interconnections


Systems more complex than the types described in the previous section can be constructed
using GenericConnect. As with the elementary interconnecting functions, subsystems in
GenericConnect can be supplied in either state-space or transfer function form. The result
will be a state-space object if at least one system is in the StateSpace form. Note that, unlike
elementary interconnections, GenericConnect always uses the state-space algorithm so it is
advantageous to supply all input systems in the StateSpace form from the outset.
6. System Interconnections 111

GenericConnectsystem 1 , system 2 , …, connections, ins, outs


construct a composite system from blocks systemk 
using the connection specification connections so 
that the aggregate has inputs ins and outputs outs
Building a complex system.

A necessary step in preparing the connections specification for GenericConnect is number-


ing all the inputs and all the outputs of the subsystems according to the order of the systems
in the argument list (which can be arbitrary). The elements of the specification connections can
be supplied as (1) a list of integers in the form {i, o1 , o2 , …  indicating that input i gets its
signal from summed outputs ok , (2) a list in the form {i, {o1 , type1  , {o2 , type2  , …  that
allows the sign (negative or positive) for output ok to be set differently according to typek , or
(3) a mix of the two. The type specification can be one of the reserved words Negative or
Positive, with the default value depending on the option DefaultInputPort.

As an example, consider connecting the three systems according to the block diagram in
Figure 6.6. The subsystems were numbered in some order, and then the inputs and outputs
were numbered sequentially in the order of the subsystems. In this way, the two inputs of
system 2 (ss2) receive numbers 3 and 4, and the only output of this subsystem becomes
output 3. The interconnections are then constructed using these numbers. Input 3 receives its
signal from outputs 2 and 4, the latter taken with a negative sign, and input 5 is connected to
output 3. The aggregate has three external inputs, 1, 2, and 4 , and two external outputs, 1
and 3 .

1 1
1
ss  3
y
u 2 3
2 2  ss2
4

3
4 s 5

sΑ

Figure 6.6. Example of an arbitrary interconnection.


112 Control System Professional

 These are the components.

In[34]:= ss  StateSpacea1 , 0, 0, a2 ,


b1 , 0, 0, b2 , c1 , 0, 0, c2 , d1 , 0, 0, d2 

a 0 b1 0

 1
0 a 0 b2

Out[34]=
2
c1 0 d1 0

 0 c2 0 d 2 •

In[35]:= ss2  StateSpaceA11 , A12 , A21 , A22 ,


B1 , 0, 0, B2 , C11 , C12 , D11 , D12 

 A11 A12 B1 0


Out[35]= A21 A22 0 B2

 C11 C12 D11 D12 •

 This creates the aggregate.


s
In[36]:= GenericConnectss, ss2, TransferFunction s,  ,
s a
3, 2, 4, Negative, 5, 3, 1, 2, 4, 1, 3


 a1 0 0 0 0 b1 0 0


0 a2 0 0 0 0 b2 0


B1 c2 B1 C11 B1 C12 a B1 B1 d2 B1 D12
0  A11   A12    0   
D11  1 D11  1 D11  1 D11  1 D11  1 D11  1


0 0 A21 A22 0 0 0 B2
Out[36]=

c2 D11 C11 C12 a D11 d2 D11 D12
0      a 0  
D11  1 D11  1 D11  1 D11  1 D11  1 D11  1


c1 0 0 0 0 d1 0 0


c2 D11 C11 C12 a D11 d2 D11 D12
0     0  
 D11  1 D11  1 D11  1 D11  1 D11  1 D11  1 •

The algorithm implemented in GenericConnect (in which signals originate necessarily at


the outputs of the blocks) imposes a limitation on the block diagram that GenericConnect
can compute directly. The limitation is easy to overcome, however, by the addition of dummy
blocks with a unit gain. For example, to construct a system containing the feed-forward and
feedback paths as shown in Figure 6.7a, dummy blocks may be added as shown in Figure 6.7b.
6. System Interconnections 113


u  y
Β 



a
Α

 y
u 1 1 2 2  3 3 4 4
1 Β  1
1 2 3
 4


5 5

b Α
5

Figure 6.7. Example of interconnection with dummy blocks added.

 This computes the aggregate system shown in Figure 6.7. The output is a Transfer
Function object since all input systems are supplied as transfer functions. Note that
the variable from the first TransferFunction object, if any, is used in the result.
Since, in this case, the first TransferFunction does not have a named variable,
the result is the pure-function object. To emphasize the structure of the result we
turn off the Control Format display.

In[37]:= GenericConnectTransferFunction 1, TransferFunction b,


1
TransferFunction s,  , TransferFunction 1, TransferFunction a,
s
2, 1, 3, 2, 5, Negative, 4, 1, 3, 5, 4, 1, 4

b  #1
Out[37]= TransferFunction  
a  #1

Unless instructed otherwise, GenericConnect assumes that the outputs ok in the connection
specification {i, o1 , o2 , …  come to the summing input i with negative or positive signs as
determined by the option DefaultInputPort . The default value of DefaultInputPort is
Positive, which means that the outputs should be summed uninverted.

option name default value

DefaultInputPort Positive default port for interconnections

Option to GenericConnect.
114 Control System Professional

 6.3 State Feedback


When the state variables become known (either through measurement or estimation), it is
sometimes desirable to feed their values back to the inputs via a controller to change the
dynamics of the system in a certain way (see Chapter 9). Figure 6.8 shows such a connection
for a continuous-time system; the diagram for a discrete-time system is structurally similar.
This type of connection can be formed using StateFeedbackConnect.

System


. 
 x x 
B  C
 u  y


Controller

Figure 6.8. State feedback schematic.

StateFeedbackConnectsystem, controller
feed all states of system back to its inputs 
via controller forming negative feedback

StateFeedbackConnectsystem, controller, connections


use connections to form the state feedback
State feedback connections.

To form state feedback, system must be in state-space form; controller can be supplied in
either state-space or transfer function form, or simply as a gain matrix (such as that returned
by StateFeedbackGains, for example); connections can be specified using the same format
as for FeedbackConnect.
6. System Interconnections 115

 6.4 Manipulating a System's Contents


Subsystem and DeleteSubsystem can be used to select or delete a desired part of the
system; Subsystem can also rearrange the order of inputs, outputs, or states. The system can
be in either state-space or transfer function form (although manipulating state contents is
possible for state-space objects only). The element specifications can be either vectors of
integers corresponding to indices or the reserved words All or None.

Subsystemsystem, inputs
select the part of system 
associated with the specified inputs

Subsystemsystem, inputs, outputs


select the subsystem with
the specified inputs and outputs

Subsystemsystem, inputs, outputs, states


select the subsystem with the specified inputs,
outputs, and states
Selecting a part of the system.

 Consider a state-space system.

In[38]:= ss  StateSpaceDiagonalMatrixa1 , a2 , a3 , DiagonalMatrixb1 , b2 , b3 ,


DiagonalMatrixc1 , c2 , c3 , DiagonalMatrixd1 , d2 , d3 

 a1 0 0 b1 0 0


0 a2 0 0 b2 0


0 0 a3 0 0 b3
Out[38]=

c1 0 0 d1 0 0

0 c 0 0 d 0

2 2

 0 0 c3 0 0 d 3 •
116 Control System Professional

 This picks the subsystem that has only the first and third inputs.

In[39]:= Subsystemss, 1, 3


 a1 0 0 b1 0


0 a2 0 0 0


0 0 a3 0 b3
Out[39]=
c1 0 0 d1 0

0 c 0 0 0

2

 0 0 c3 0 d3 •

 This swaps the second and third inputs.

In[40]:= Subsystemss, 1, 3, 2

a 0 0 b 1 0 0

 1
0 a 0 0 0 b
2

2
0 0 a3 0 b3 0

Out[40]=
c1 0 0 d1 0 0

0 c 0 0 0 d
2
2

 0 0 c3 0 d 3 0 •

 This selects the subsystem that has all inputs, the first output, and the first and third
states of the original system ss.
In[41]:= Subsystemss, All, 1, 1, 3


 a1 0 b1 0 0


Out[41]= 0 a3 0 0 b3

 c1 0 d1 0 0 •

DeleteSubsystem is complementary to Subsystem and has similar syntax.


6. System Interconnections 117

DeleteSubsystemsystem, inputs
delete the part of system 
associated with the specified inputs

DeleteSubsystemsystem, inputs, outputs


delete the specified inputs and outputs

DeleteSubsystemsystem, inputs, outputs, states


delete the specified inputs, outputs, and states
Deleting a part of the system.

 Here is a transfer function of a system with two inputs and three outputs.

In[42]:= TransferFunction Arrayf, 3, 2


 f 1, 1 f 1, 2


Out[42]= f 2, 1 f 2, 2

 f 3, 1 f 3, 2 •

 This deletes the first and third outputs, leaving all the inputs intact.

In[43]:= DeleteSubsystem% , None, 1, 3


Out[43]=  f 2, 1 f 2, 2 •

MergeSystems merges several systems into one by appending their inputs and outputs (and,
for state-space systems, states). The result is in state-space form if at least one of the systems is
in this form.

MergeSystems system1 , system2 , …


merge the systems systemi

Merging several systems.

 Here are two state-space systems.

In[44]:= ss1  StateSpacea11 , a12 , a21 , a22 ,


b11 , b12 , b21 , b22 , c1 , c2 , d1 , d2 

 a11 a12 b11 b12


Out[44]= a21 a22 b21 b22

 c1 c2 d1 d2 •
118 Control System Professional

In[45]:= ss2  StateSpaceA11 , A12 , A21 , A22 ,


B1 , B2 , C11 , C12 , C21 , C22 , D1 , D2 

 A11 A12 B1


A21 A22 B2
Out[45]=


C11 C12 D1

 C21 C22 D2 •

 This merges them into one. The aggregate has all the inputs, outputs, and states of
its components.
In[46]:= MergeSystemsss1, ss2

 a11 a12 0 0 b11 b12 0




a21 a22
0 0 b21 b22 0

0 0 A11 A12 0 0 B1

Out[46]=
0 0 A21 A22 0 0 B2

c1 c2
0 0 d1 d2 0

0 0 C11 C12 0 0 D1

 0 0 C21 C22 0 0 D 2 •

 Here are two transfer functions for the two-input, one-output and the one-input,
two-output systems, respectively.
1 1
In[47]:= tf1  TransferFunction s,   ,  
s s 1

1 1
Out[47]=   
 1

1 1
In[48]:= tf2  TransferFunction s,   ,   
s 2 s 3

 1



2
Out[48]=

1

 3
6. System Interconnections 119

 This merges the two transfer functions into one.

In[49]:= MergeSystemstf1, tf2


 1

1


0
 1

1
Out[49]= 0 0 

  2
1
0 0 
 3

 6.5 Using Interconnecting Functions for Controller Design


Due to their symbolic capabilities, the interconnecting functions described in this chapter can
be especially useful for design purposes. In a typical scenario, the designer chooses the struc-
ture of the controller and then determines the particular values of its parameters to meet the
specifications. Several design functions are described in details later in Chapters 9 and 10. The
example given here illustrates that the ready-made set of design tools can be easily expanded
and outlines possible steps in that process.

We consider a double-integrator model of the satellite control system and design a PID
(proportional-integral-derivative) controller that would place the poles of the closed-loop
system in some predefined positions (cf. Section 9.1). The block diagram of a PID controller
connected to the system is shown in Figure 6.9. Only the propagation of the reference signal r
to the controlled output c is taken into account. A typical system would also have a distur-
bance input, not shown on the diagram. The prefilter can be used to further correct the dynam-
ics of the system, for example, by eliminating unwanted zeros from the closed-loop transfer
function. Note that the derivative part of the controller includes the term 1  Τs  1, with a
presumably small time constant Τ . Otherwise that part would not be physically realizable.
120 Control System Professional

PID Controller

Kp

r    c
Prefilter Ki System
 s 

Kd s
Τ s  1

Figure 6.9. PID controller example.

 Here is a double integrator plant.

In[50]:= plant  StateSpace0, 1, 0, 0, 0, 1, 1, 0


 0 1 0


Out[50]= 0 0 1

 1 0 0 •

 This describes the PID controller.


ki kd s
In[51]:= pid  TransferFunction s, kp     
s 1Τ s

 kd ki
Out[51]= 
    k p 
Τ1 

 This connects the controller to the plant, closes the feedback loop, and simplifies the
result.
In[52]:= SeriesConnectpid , plant  FeedbackConnect  Simplify




0 1 0 0 0

1
0   1 0 1
Τ


Out[52]= 0 0 0 1 0

kd  Τ k p
ki kd kd
 ki  2   0   k p
Τ Τ Τ Τ

 0 0 1 0 0 •
6. System Interconnections 121

 This finds the transfer function of the closed-loop system.

In[53]:= TransferFunction s, %   ExpandRational


 kd 2  Τ k p 2  Τ ki   k p   ki

Out[53]= 
 

 Τ   3  kd 2  Τ k p 2  Τ ki   k p   ki
4

 Here is the denominator of the transfer function as a polynomial in the variable s.

In[54]:= Denominator% s 1, 1

Out[54]= s3  s4 Τ  s2 kd  ki  s Τ ki  s kp  s2 Τ kp

 This makes the polynomial monic.


%
In[55]:= d1  Expand   
Τ
s3 s2 kd ki s kp
Out[55]= s4    
  s ki    s2 kp  
Τ Τ Τ Τ

 Suppose now that the closed-loop system with desired dynamics has poles at p1 ,
p2 , p3 , and p 4 . This is the denominator of the corresponding transfer function.
In[56]:= d2  s  p1
s  p2
s  p3
s  p4

Out[56]=
s  p1
s  p2
s  p3
s  p4

 To find the unknown parameters ki , kd , k p , and Τ we equate the coefficients of


powers of s in the denominators and solve the resultant system of equations.
In[57]:= SolveCoefficientListd1  d2 , s 0, ki , kd , kp , Τ  Simplify


p1  p2  p3
p1  p2  p4
p1  p3  p4
p2  p3  p4
Out[57]= kd  


 ,

p1  p2  p3  p4 3
p1 p2 p3 p4
ki  
 , kp 
p2 p3 p4
p2  p3  p4  p21
p3 p4  p2
p3  p4 
p1  p2  p3  p4
p1
p22
p3  p4  p3 p4
p3  p4  p2
p23  3 p3 p4  p24
1

p1  p2  p3  p4 2 , Τ  
p1  p2  p3  p4

 This is a simplified result for negligible Τ.

In[58]:= % . k_  expr_

k  Limitexpr, p1   

Out[58]= kd  p2  p3  p4 , ki  p2 p3 p4 , kp  p3 p4  p2
p3  p4 , Τ  0
7. Controllability and Observability

This chapter describes the tools related to controllability and observability of state-space
systems, including the test functions themselves and other necessary constructs.

 7.1 Tests for Controllability and Observability


A linear system is said to be completely controllable if, for all initial times t0 and all initial states
xt0 , there exists some input function (or sequence for discrete systems) that drives the state
vector to any final state xt1  at some finite time t1  t0 . Controllability of the system is deter-
mined by matrices A and B . The function Controllable performs the test.

Another kind of controllability may be useful from a practical perspective, namely, complete
output controllability, which is defined as the ability to drive the output vector to the origin in
finite time. This property involves all matrices A, B, C, and D . The test can be done using the
function OutputControllable.

Analogously, a linear system is said to be completely observable if, for all initial times t0 , the
state vector xt0  can be determined from the output function (or sequence) yt1 , defined
over a finite time t1  t0 . Consequently, observability involves the matrices A and C. Observ
able performs the test.

Controllablestatespace test if the system statespace is controllable

OutputControllablestatespace
test if the system 
statespace is output controllable
Observablestatespace test if the system statespace is observable
Testing controllability and observability properties.

 Load the application.

In[1]:=  ControlSystems`
7. Controllability and Observability 123

 It is easy to show that this system is neither controllable nor output controllable.

In[2]:= ss  StateSpace0, 1, 1, 2, 1, 1, 1, 0, 1, 1


 0 1 1 
 
 1 2 1 
Out[2]= 
 

 1 0 0 
 
 1 1 0 •

 This tests the controllability.

In[3]:= Controllabless

Out[3]= False

 And here is the test for output controllability.

In[4]:= OutputControllabless

Out[4]= False

 On the other hand, the system is completely observable.

In[5]:= Observabless

Out[5]= True

If for some reason the controllability and observability tests cannot be evaluated to True or
False, they are returned partially unevaluated. In this sense, the tests behave more like the
Mathematica built-in functions Positive, Negative, or Equal rather than the *Q functions,
which always return True or False.

 Controllability and observability tests do not necessarily return True or False.

In[6]:= Controllableundefinedsystem

Out[6]= Controllableundefinedsystem
124 Control System Professional

option name default value

ControllabilityTest Automatic test to apply to find if


the system is controllable
ObservabilityTest Automatic test to apply to find if
the system is observable

Options specific to controllability and observability test functions.

Controllability and observability can be determined by testing if the controllability or observ-


ability matrix has rank n, where n is the dimension of the state space, or if the controllability
or observability Gramian is singular. The tests can be chosen through the options Controlla
bilityTest and ObservabilityTest . Both accept a pure function or a list of pure func-
tions to be applied in turn until one gives True or False or the list is exhausted. By default,
both first try to see if the controllability or observability information for the system is available
(see below in this section) and then proceed with the matrix test and further with the Gramian
test as needed. To disable this feature, simply select one desired method.
7. Controllability and Observability 125

ControllabilityTest  FullRankControllabilityMatrix
test if the controllability matrix is
full rank in order to test controllability

ControllabilityTest  NonSingularControllabilityGramian
test if the controllability Gramian is
nonsingular in order to test controllability

ControllabilityTest  test
use the pure function test

ControllabilityTest  test1 , test2 , …


try testi in turn until one succeeds

ObservabilityTest  FullRankObservabilityMatrix
test if the observability matrix is
full rank in order to test observability

ObservabilityTest  NonSingularObservabilityGramian
test if the observability Gramian is
nonsingular in order to test observability

ObservabilityTest  test
use the pure function test

ObservabilityTest  test1 , test2 , …


try testi in turn until one succeeds
Selecting controllability and observability tests.

Controllability and observability can also be inferred from the structure of certain special-type
realizations, such as the Kalman controllable or observable forms (see Section 8.2). In fact, in
some cases the size of the controllable or observable subspace is computed internally when
arriving at the realization of the special form. This information can be retrieved with the
functions ControllableSpaceSize and ObservableSpaceSize and then used for
alternative controllability and observability tests.

In their turn, ControllableSpaceSize and ObservableSpaceSize take the option


ReductionMethod that allows you to specify the method to use for those functions. The
126 Control System Professional

option operates analogously in ControllableSubsystem and ObservableSubsystem


and is described in Section 8.1.

ControllableSpaceSizestatespace
the size of the controllable
subspace of the state-space system

ObservableSpaceSizestatespace
the size of the observable subspace
The controllable and observable subspace sizes.

 This determines the size of the controllable subspace.

In[7]:= ControllableSpaceSizess

Out[7]= 1

 As the size of the controllable subspace is less than the number of states, the system
is not controllable.
In[8]:= %  CountStatesss

Out[8]= False

 7.2 Controllability and Observability Constructs


The controllability matrix of a linear system is defined as

  B AB A2 B  An1 B
(7.1)

and can be obtained with ControllabilityMatrix. The output controllability matrix

  CB CAB CA2 B  CAn1 B D


(7.2)

can be found with OutputControllabilityMatrix. The observability matrix


7. Controllability and Observability 127

C 


CA 


  CA 
2
 (7.3)

 


CAn1 

is obtainable with ObservabilityMatrix.

ControllabilityMatrixstatespace
returns the controllability 
matrix for the system statespace

OutputControllabilityMatrixstatespace
returns the output controllability matrix

ObservabilityMatrixstatespace
returns the observability matrix
Finding controllability and observability matrices.

 This is a simple test system.

In[9]:= system 
StateSpace3, 1, 0, 5, 0, 1, 3, 0, 0, 1, 2, 3, 1, 0, 0

 3 1 0 1 
 
 5
 0 1 2 
Out[9]=  
 3 0 0 3 
 
 1 0 0 0 •

 This is its controllability matrix.

In[10]:= ControllabilityMatrixsystem

 1 1 1 
 
Out[10]=  2 2 2 
 
 3 3 3 
128 Control System Professional

 Clearly, this is not a full-rank matrix and, therefore, the system is not completely
controllable.
In[11]:= Rank% 

Out[11]= 1

 We can come to this conclusion directly.

In[12]:= Controllablesystem

Out[12]= False

 This is the observability matrix for the system.

In[13]:= ObservabilityMatrixsystem

 1 0 0 
 
 3 1 0 
Out[13]=  
 
 4 3 1 

 This is a full-rank matrix, so the system is completely observable.

In[14]:= Rank% 

Out[14]= 3

 Again, we can come to this conclusion directly.

In[15]:= Observablesystem

Out[15]= True

Equally important in controllability and observability studies are the corresponding Grami-
ans, which may be defined as (see, e.g., Moore (1981))


T
W2c   eAΤ BBT eA Τ dΤ (7.4)
0

(the controllability Gramian) and


T
W2o   eA Τ CT CeAΤ dΤ (7.5)
0

(the observability Gramian). Examples of using the Gramians can be found later in Section 8.4.
7. Controllability and Observability 129

ControllabilityGramianstatespace
find the controllability 
Gramian for the system statespace

ObservabilityGramianstatespace
find the observability Gramian
Finding controllability and observability Gramians.

 This is a mixing tank system (described in Section 10.1).

In[16]:= StateSpace0.9512, 0, 0, 0.9048, 4.88, 4.88, 0.019, 0.0095,


0.01, 0, 0, 1, Sampled  Period 5.

 0.9512 0 4.88 4.88 


 
 0
 0.9048 0.019 0.0095 
Out[16]=  

 0.01 0 0 0 
 
0 1 0 0 5.

 Here is its controllability Gramian.

In[17]:= ControllabilityGramian % 

0.332677 

500.205
Out[17]= 
 0.332677 0.00248846 

ControllabilityGramian and ObservabilityGramian rely on the function Lyapunov


Solve (see Section 12.2) to solve Lyapunov equations regarding W2c and W2o :

AW2c  W2c AT  BBT (7.6)

AT W2o  W2o A  CT C (7.7)

Consequently, these functions accept the same options as LyapunovSolve does. For
discrete-time systems, ControllabilityGramian and ObservabilityGramian call
DiscreteLyapunovSolve appropriately.

The Gramian functions sometimes must reconstruct the full orthogonal basis of the vector
space given a few orthogonal vectors belonging to the basis—a problem that may have more
than one solution. In such cases, the choice between equivalent vectors can be made ran-
domly. You may enable this feature by setting the option RandomOrthogonalComplement
to True. The same mechanism is used by several other functions, for example, Kalman trans-
130 Control System Professional

form functions and the KNVD algorithm in StateFeedbackGains . To have them all utilize
the randomized algorithm, you may change the global variable $RandomOrthogonalComple 
ment to True. Of course, reseeding the random number generator with some number (using
the Mathematica built-in function SeedRandom), while employing the randomized algorithm,
provides a random, yet reproducible solution.

RandomOrthogonalComplement True
use the randomized algorithm for constructing
an orthogonal basis in a particular function

$RandomOrthogonalComplement  True
use the randomized algorithm in all
functions that construct orthogonal bases
Enabling the random choice between equivalent orthogonal vectors.

 7.3 Dual System


The function DualSystem returns the system that is dual to the input system. It is useful
because observability tests are often implemented as controllability tests of the system dual to
the one in question.

DualSystemstatespace a system that is dual to the system statespace

Finding the dual system.

 This is a system in state-space form.

In[18]:= StateSpace0, 1, a1, a2, 1, 1, 1, 0, 1, 1


 0 1 1 
 
 a1 a2 1 
Out[18]= 
 
 1 0 0 
 
 1 1 0 •
7. Controllability and Observability 131

 This is its dual system.

In[19]:= DualSystem% 


 0 Conjugatea1 1 1 
 
Out[19]=  1 Conjugatea2 0 1 
 
1 1 0 0 •

By default, DualSystem assumes that all symbolic entries in state-space representation can be
complex. The user may disable this feature by setting the option ComplexVariables to
None, in which case the built-in function ComplexExpand will be applied to the result.
ComplexVariables accepts also a list of variables which may be complex. In this case, all
other variables are assumed to be real valued.

 If we assume that none of the symbolic entries are complex, a simpler result is
returned.
In[20]:= DualSystem%% , ComplexVariables  None


 0 a1 1 1 
 
Out[20]=  1 a2 0 1 
 
 1 1 0 0 •

 Finally, here is the dual system if only a1 may be complex.

In[21]:= DualSystem%%% , ComplexVariables  a1


 0 Rea1 
Ima1 1 1 
 
Out[21]=  1 a2 0 1 
 
 1 1 0 0 •

option name default value

ComplexVariables All which symbolic entries


in state-space representation
should be assumed to be complex

Option to DualSystem.
8. Realizations

A realization is any pair of equations

x t  Axt  But


(8.1)
yt  Cxt  Dut
or the corresponding quadruple of the matrices A, B , C , D  , or, for the purposes of this
guide, the corresponding state-space object StateSpace[a, b, c, d] that leads to the required
input-output relations for the system (usually specified as a transfer function matrix Hs). A
realization can also refer to a discrete-time state-space realization (with the obvious change
from the differential to difference in the equations). Because there can be innumerable ways to
satisfy the input-output relations, a physical system can have an infinite number of realiza-
tions. In this chapter, several means of converting between different realizations are described,
including means of obtaining realizations of a smaller order. All the functions operate on
continuous- and discrete-time objects.

The first group of functions represents the means to convert between different types of realiza-
tions. By convention, their names end with Form. For example, to convert a system to Kalman
controllable form, the function KalmanControllableForm would be applied to the system.
The list of all forms available in Control System Professional can be obtained with ?Control
Systems`*`*Form.

The other group comprises functions that select a subsystem (typically a subspace) possessing
certain properties. These functions end with Subsystem (e.g., ControllableSubsystem or
DominantSubsystem ). The exception to this convention is MinimalRealization , used for
computing a minimal realization, which represents the intersection of the controllable and
observable subspaces; therefore, this function does effectively select a subsystem. Also intro-
duced is SimilarityTransform , a function that transforms between equivalent realizations
of the same system.
8. Realizations 133

 8.1 Irreducible (Minimal) Realizations


The internal structure of a system may allow some of the integrators (or delay elements) to be
shared by several input-output pairs and still result in the same transfer matrix. The system
that realizes the maximum possible degree of sharing (and, consequently, the smallest possi-
ble dimension of the associated state space) is called the irreducible (or minimal) realization
(see, e.g., Brogan (1991), Section 12.4). The function MinimalRealization tries to find such
a realization.

MinimalRealizationsystem
find a minimal realization for system
Finding the irreducible (minimal) realization.

The input system for MinimalRealization can be in either state-space or transfer function
form; the resultant system is always a state-space one. For SISO transfer function systems,
MinimalRealization constructs a state-space realization after an attempt to cancel com-
mon pole-zero pairs (the underlying function, PoleZeroCancel, can also be accessed
directly, see Section 8.6). Otherwise, MinimalRealization constructs a state-space realiza-
tion first and then uses the functions ControllableSubsystem and ObservableSub
system consecutively to select first the controllable and then the observable subspaces. The
result is therefore a subsystem that is both completely observable and controllable. See
Section 8.2 for more on the definitions of the controllable and observable subspaces. In con-
trast, DominantSubsystem eliminates weakly controllable and observable modes (see Section
8.5).

ControllableSubsystemstatespace
select the controllable subspace of statespace

ObservableSubsystemstatespace
select the observable subspace of statespace
Selecting controllable and observable subspaces.

 Load the application.

In[1]:=  ControlSystems`
134 Control System Professional

 Consider a third-order state-space system with two inputs and two outputs. The first
mode is uncontrollable, and the second one is unobservable. These modes, then,
have no effect on the input-output relations and so can be dropped without
changing the transfer function matrix.
In[2]:= ss  StateSpaceDiagonalMatrixa1 , a2 , a3 ,
0, 0, b1 , 0, 0, b2 , c1 , 0, 0, 0, 0, c3 , d11 , d12 , d21 , d22 

 a1 0 0 0 0 



 0 a2 0 b1 0



Out[2]=  0 0 a3 0 b2



 c1 0 0 d11 d12




 0 0 c3 d21 d22 •

 We can verify that this system is not controllable.

In[3]:= Controllabless

Out[3]= False

 Neither is it observable.

In[4]:= Observabless

Out[4]= False

 This selects the controllable subspace.

In[5]:= ControllableSubsystemss

a 0 b 1 0 
 2

 0 a 0 b2


Out[5]= 

3
 0 0 d11 d12



 0 c3 d21 d22 •

 This selects the observable subspace.

In[6]:= ObservableSubsystemss

 a1 0 0 0 


 0 a3 0 b2

Out[6]= 



 c1 0 d11 d12



 0 c3 d21 d22 •
8. Realizations 135

 By selecting the observable subspace of the controllable subspace, we arrive at a


minimal realization.
In[7]:= ObservableSubsystem%% 


 a3 0 b2 



Out[7]=  0 d11 d12



 c3 d21 d22 •

 The same result can be obtained directly.

In[8]:= MinimalRealization ss

0 b 2 
 3
a

 0 d

Out[8]=  11 d12



 c3 d21 d22 •

 The minimal realization is both controllable and observable.

In[9]:= Controllable%   Observable%   True

Out[9]= True

The method that ControllableSubsystem and ObservableSubsystem use to reduce the


dimension of the system can be chosen through the option ReductionMethod. Reduction
Method  Kalman specifies that the Kalman decomposition is to be used. With the default
option value Automatic, the functions first try to use the structural information about the
input system that might be already available. Additionally, ControllableSubsystem takes,
and passes along, the options specific to the method it employs. ObservableSubsystem
takes both the options for ControllableSubsystem and DualSystem. MinimalRealiza
tion, as an interface function, inherits options from its constituents ControllableSub
system and ObservableSubsystem or PoleZeroCancel, whichever is applicable.

option name default value

ReductionMethod Automatic method to use to reduce


the dimension of the system

Specifying the reduction method.


136 Control System Professional

 8.2 Kalman Canonical Forms


The state equations in Eq. (8.1) can be transformed to the Kalman controllable canonical form
(see, e.g., Brogan 1991, Section 11.7)

w 1  T  T 
T1 AT1 TT1 AT2  w
1

 T B 



  
   1  u
w2  0  w2  0 
2 
T
T 2 AT   (8.2)
w 
1 
y   CT1 CT2    D u
w2 

using a similarity transformation x  T w , where the orthogonal transformation matrix


T   T1 T2  is constructed and partitioned in such a way that T1 represents the subspace
spanned by the columns of the controllability matrix and T2 is the subspace orthogonal to T1 .
w 
1 
The space vector w is partitioned into two corresponding parts, too: w  . It is seen from
w2 
Eq. (8.2) that state variables w2 are uncontrollable, since there is no way to change w2 either
directly through input u or indirectly through w1 coupling.

Similarly, in the Kalman observable canonical form

v 1  T  T 
V1 AV1  v1  



  T
0 
   V1 B  u
v2  V AV1 VT AV2   VTB 
v2 
2 2  2  (8.3)
v1 
y   CV1 0    D u,
v2 

the state space is divided into observable v1 and unobservable v2 subspaces. Kalman controlla-
ble and observable canonical forms can be arrived at by using the functions KalmanControl
lableForm and KalmanObservableForm.

KalmanControllableFormstatespace
find the Kalman controllable 
canonical form of the system statespace

KalmanObservableFormstatespace
find the Kalman observable 
canonical form of the system statespace
Finding Kalman canonical forms.
8. Realizations 137

 This is an example system defined previously.

In[10]:= ss  StateSpaceDiagonalMatrixa1 , a2 , a3 ,


0, 0, b1 , 0, 0, b2 , c1 , 0, 0, 0, 0, c3 , d11 , d12 , d21 , d22 

 1


a 0 0 0 0
 0 a 0 b

 0

 2 1


Out[10]=  0 0 a3 0 b2



 c1 0 0 d11 d12



 0 0 c3 d21 d22 •

 This is the Kalman controllable canonical form of an example system defined


previously. We can see that the uncontrollable mode (the third one) is moved to the
end of the state vector.
In[11]:= KalmanControllableFormss


 a2 0 0 b1 0 



 0 a3 0 0 b2



Out[11]=  0 0 a1 0 0



 0 0 c1 d11 d12




 0 c3 0 d21 d22 •

 This is the Kalman observable canonical form of the same system. Now the
unobservable mode (the second one) is moved to the end.
In[12]:= KalmanObservableFormss


 a1 0 0 0 0 



 0 a3 0 0 b2



Out[12]=  0 0 a2 b1 0



 c1 0 0 d11 d12




 0 c3 0 d21 d22 •

The decomposition into controllable and uncontrollable (or observable and unobservable)
subspaces can be performed using several methods that are accessible through the option
DecompositionMethod . The default Automatic value for this option invokes the built-in
function RowReduce for exact systems and SingularValues for inexact ones. Other avail-
able option values are QRDecomposition and NullSpace. Like all other functions in Control
System Professional, the functions related to Kalman canonical forms accept the options belong-
ing to the employed method and pass them on to their destinations. Kalman
decomposition-related functions also accept the option RandomOrthogonalComplement.
138 Control System Professional

option name default value

DecompositionMethod Automatic method to perform


the decomposition

Specifying the decomposition method.

KalmanControllableForm and KalmanObservableForm are similar to the functions


ControllableSubsystem and ObservableSubsystem described in Section 8.1. However,
the two former functions merely rearrange the order of variables in the state vector, whereas
the latter two select controllable or observable subspaces of the given system. Similarly to
ObservableSubsystem , KalmanObservableForm takes the options of KalmanControlla
bleForm as well as the options of DualSystem.

 8.3 Jordan Canonical (Modal) Form

JordanCanonicalFormstatespace
find the  Jordan canonical 
form of the system statespace
Finding the Jordan canonical form.

 Let us create a diagonal matrix.

In[13]:= m  DiagonalMatrix1, 2, 3

 1 0 0 



 0 2 0

Out[13]= 

 0 0 3

 Here is some nonsingular matrix.

In[14]:= t  0, 1, 0, 1, 0, 1, 1, 1, 0

 0 1 0 



Out[14]=  1 0 1



 1 1 0
8. Realizations 139

 This creates a matrix with the predefined set of eigenvalues.

In[15]:= Inverset.m.t

 3 2 0 



 0 1 0

Out[15]= 

 1 2 2

 We use the previous matrix as matrix A in our test state-space object ss.

In[16]:= ss  StateSpaceDiagonalMatrixa1 , a2 , a3 ,


0, 0, b1 , 0, 0, b2 , c1 , 0, 0, 0, 0, c3 , d11 , d12 , d21 , d22 

 a1 0 0 0 0 



 0 a2 0 b1 0



Out[16]=  0 0 a3 0 b2



 c1 0 0 d11 d12




 0 0 c3 d21 d22 •

In[17]:= ReplacePartss, %% , 1


 3 2 0 0 0 



 0 1 0 b1 0



Out[17]=  1 2 2 0 b2



 c1 0 0 d11 d12




 0 0 c3 d21 d22 •

 This finds the Jordan canonical form of the preceding system.

In[18]:= JordanCanonicalForm% 


 3 0 0 b1 0 



 0 2 0 0 b

 2

Out[18]=  0 0 1 b1 0



 c1 0 c1 d11 d12




 c3 c3 c3 d21 d22 •

In the case of an exact input system, JordanCanonicalForm relies on the built-in function
JordanDecomposition ; otherwise the eigenvalue decomposition is used. The latter method
may lead to significant numerical errors if eigenvalues happen to be multiple.
140 Control System Professional

 8.4 Internally Balanced Realizations


The Kalman minimal realization algorithm may result in structurally unstable models. In such
cases another model reduction technique, based on the internally balanced realization, may be
applied (Moore (1981)). The controllable and observable realization is said to be internally
balanced if its controllability and observability Gramians are represented by the same
(positive definite) diagonal matrix. InternallyBalancedForm attempts to construct such a
realization.

InternallyBalancedFormstatespace
find the internally balanced 
realization of the system statespace
Finding the internally balanced form.

 Consider a SISO system in its controllable canonical form (see Example 1 in the
above-cited paper of Moore (1981)). Evidently, the realization is poorly balanced.
In[19]:= original 
StateSpace0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 50, 79, 33, 5,
0, 0, 0, 1, 50, 15, 1, 0  N

 0. 1. 0. 0. 0. 


 0.
 0. 1. 0. 0.

Out[19]=  0. 0. 0. 1. 0.



 50. 79. 33. 5. 1.



 50. 15. 1. 0. 0 •

 This finds the internally balanced realization.

In[20]:= balanced  InternallyBalancedForm% 

 0.518282 1.45031 0.391098 0.350054 0.772915 




 1.45031 2.19539 4.75334


 1.21805 0.804697

Out[20]=  0.391098 4.75334 0.629679 1.19628 0.337348



 0.350054 1.21805
 1.19628 1.65665 0.252316

 0.772915 0.804697 0.337348 0.252316 0 •


8. Realizations 141

 We can verify that the realization has equal and diagonal controllability and
observability Gramians. The built-in function Chop rounds small numerical errors
down to the exact zeros.
In[21]:= ControllabilityGramian %   Chop




0.576324 0 0 0
 0

 0.147477 0 0

Out[21]= 

 0

 0 0.0903667 0

0 0 0 0.0192144

In[22]:= ObservabilityGramian %%   Chop

 0.576324 0 0 0 



 0 0.147477 0 0

Out[22]= 


 0 0 0.0903667 0

0 0 0 0.0192144

 Finally, we can see that the two forms are in fact different realizations of the same
transfer function.
In[23]:= TransferFunction s, original  ExpandRational  Chop


1. 2  15.   50.
Out[23]=    

  5. 3  33. 2  79.   50.
4

In[24]:= TransferFunction s, balanced   ExpandRational  Chop


1. 2  15.   50.
Out[24]=    

  5. 3  33. 2  79.   50.
4

Similarly to KalmanControllableForm and related functions, InternallyBalanced 


Form takes the option DecompositionMethod . The default Automatic value for this
option invokes the built-in function Eigensystem for the continuous-time systems and
SingularValues for the discrete-time systems, in the most important case of inexact sys-
tems. For exact systems, the Eigensystem-based solution will be attempted.
142 Control System Professional

 8.5 Dominant Subsystem


The controllability and observability Gramians in the example in the preceding section reveal
the modes that are relatively small and, therefore, contribute little to the input-output character-
istic. This suggests a way of reducing the order of the system by eliminating these weak
modes. What is meant by "relatively small" is, of course, a matter of convention and will be
addressed in the context of the option RejectionLevel later in this section.

Schematically, the system breaks up into dominant and weak subsystems connected as shown
in Figure 8.1. DominantSubsystem can be used to select the dominant part.

u Dominant subsystem y


Reduced model is obtained


by severing these connections

Weak subsystem

Figure 8.1. Model reduction based on decomposing the system into its dominant and weak parts.

DominantSubsystemsystem
find the dominant 
subsystem of the state-space system
Model reduction by selection of the dominant subsystem.
8. Realizations 143

 A reduced-order model of the system original can be found by selecting the


dominant subsystem.
In[25]:= reduced  DominantSubsystemoriginal

 0.592249 1.19293 0.643875 0.826229 




 1.19293 1.29982 5.6329


 0.619183

Out[25]= 

 0.643875 5.6329
 1.49353 0.519548

 0.826229 0.619183 0.519548 0.0384288 •

Similarly to the function MinimalRealization, DominantSubsystem takes the option


ReductionMethod. With the default Automatic value for this option, DominantSub
system may use the structural information about the input system if it is available (if, for
example, the system is already in the internally balanced form). Otherwise, the function starts
from constructing the internally balanced realization and then selects the dominant part, as set
by the option RejectionLevel. With ReductionMethod  InternallyBalancedForm ,
DominantSubsystem always uses the internally balanced form to select the dominant part.
DominantSubsystem inherits options from InternallyBalancedForm.

option name default value

RejectionLevel 0.1 if the relative value of a diagonal element


compared with the biggest element
of the Gramians is equal
to or less than this value,
the corresponding mode is to be dropped

The option specific to DominantSubsystem.

If the default value of RejectionLevel is not appropriate for the particular case, the user
may find the internally balanced realization "manually" and then choose a suitable value for
RejectionLevel.

 Because we do have the internally balanced realization of the system original, we


use it to find the second-order reduced model.
In[26]:= reduced2  DominantSubsystembalanced , RejectionLevel  .2

 0.314668 3.62134 0.602247 




Out[26]=  3.62134 22.5446 2.57868




 0.602247 2.57868 0.142305 •


144 Control System Professional

 This creates the Bode plots for the three systems and displays them at once. The
solid line is for the initial system, and the dashed and dashed-dotted ones are for the
third- and second-order reduced models, respectively. Note that in the first plot we
set up a plot range sufficient to display all three graphs, and in the second plot we
tweak PlotPoints for the phase unwrapping mechanism to operate correctly.
In[27]:= DisplayTogetherGraphicsArray
BodePlotoriginal, PlotRange  All, 0, 600,
BodePlotreduced , PlotStyle  Dashing 0.02, PlotPoints  75,
BodePlotreduced2, PlotStyle  Dashing 0.05, 0.015, 0.005, 0.015;

0
Magnitude dB

-20

-40

-60

-80
0.1 0.51 5 10 50100
Frequency RadSecond

0
Phase deg

-100
-200
-300
-400
-500

0.1 0.51 5 10 50100


Frequency RadSecond

As we can see, in the reduced models the low-frequency behavior is preserved while the
high-frequency (fast) states are eliminated.

 8.6 Pole-Zero Cancellation

PoleZeroCanceltf  cancel the common pole-zero 


pairs in the transfer function tf

Canceling common pole-zero pairs.

For the model reduction purposes, PoleZeroCancel in its current implementation is most
useful for SISO systems.
8. Realizations 145

 Here is a z-plane transfer function for a SISO system.


z  .5
In[28]:= TransferFunction z,  , Sampled  True
.5  1.5 z  z 2

  0.5
Out[28]=  
 
  1.5   0.5
2

 This is the transfer function after the pole-zero pair at z  0.5 is canceled.

In[29]:= PoleZeroCancel% 


1
Out[29]=   
  1.

Note that if the common factors coincide within the precision of the elements, they can be
canceled without calling PoleZeroCancel—for example, just by factoring the elements of
the transfer matrix. Therefore, PoleZeroCancel is most useful when the match is not exact.
In fact, the Tolerance option allows cancellation of the factors within any desired difference.

 The common pair in the preceding transfer function cancel in the factored form, too.

In[30]:= FactorRational%% 


1
Out[30]=   
  1.

 Here is another transfer function.


s  .5
In[31]:= TransferFunction s,  
s  .4

  0.5
Out[31]=   
  0.4

 Tolerance allows cancellation of pairs with a significant difference. The pole at


s  0.4 and the zero at s  0.5 cancel so long as Tolerance is set to 0.1 .
In[32]:= PoleZeroCancel% , Tolerance  .1


Out[32]=  1 •
146 Control System Professional

option name default value

Tolerance Automatic maximum difference between


a pole and a zero for which they
are considered a common pair

Option to PoleZeroCancel.

 8.7 Similarity Transformation


There can be an infinite number of realizations of a physical system that correspond to the
system's representations in different bases of state space. The transformation x t  Txt
from basis x to another basis, x , may be performed with any nonsingular matrix T . In the new
basis, the state equations from Eq. (8.1) become


x t  Ax t  But
(8.4)
yt  Cx t  Dut

where


A  TAT1

B  TB (8.5)

C  CT1

The result can be obtained using the function SimilarityTransform.

SimilarityTransformstatespace, m
transform the system statespace with the matrix m
Finding the similarity transformation.
8. Realizations 147

 Consider an earlier system.

In[33]:= system  StateSpace3, 2, 0, 0, 1, 0, 1, 2, 2,
0, 0, b1 , 0, 0, b2 , c1 , 0, 0, 0, 0, c3 , d11 , d12 , d21 , d22 

3 2 0



0 0
 0 1 0 b

 0

 1


Out[33]=  1 2 2 0 b2



 c1 0 0 d11 d12



 0 0 c3 d21 d22 •

 Here its eigenvectors are arranged as columns of the matrix.

In[34]:= t  EigenvectorsFirst%   Transpose

1 0 1 



Out[34]=  0 0 1



 1 1 1

 A similarity transformation based on the inverse of that matrix can be used to


represent the system in its canonical form.
In[35]:= SimilarityTransformsystem, Inverset


 3 0 0 b1 0 



 0 2 0 0 b

 2

Out[35]=  0 0 1 b1 0



 c1 0 c1 d11 d12




 c3 c3 c3 d21 d22 •

To avoid a double inversion of the matrix T in Eq. (8.5), either T or its inverse T1 can be
supplied as an input argument to SimilarityTransform . In the latter case, the option
InvertedTransformMatrix must be set to True. Another way to look at this option is that
it allows backward transformation from basis x to x.
148 Control System Professional

 This performs the transformation, assuming that matrix t is the inverse of the
transformation matrix.
In[36]:= SimilarityTransformsystem, t, InvertedTransformMatrix  True


 3 0 0 b1 0 



 0 2 0 0 b

 2

Out[36]=  0 0 1 b1 0



 c1 0 c1 d11 d12




 c3 c3 c3 d21 d22 •

Further performance gain can be achieved if the transformation matrix is known to be orthogo-
nal, in which case the transpose of the matrix can be used instead of its inverse.

option name default value

InvertedTransformMatrix False whether the input


matrix is already inverted
OrthogonalTransformMatrix Automatic whether the input matrix
is known to be orthogonal

Options to SimilarityTransform.

 8.8 Recovering the Transformation Matrix


The similarity transformation matrix, which has been used internally to arrive at the realiza-
tions of special forms introduced in this chapter, can be retrieved using the function Trans
formationMatrix.

TransformationMatrixoriginal, transformed
the similarity transformation
matrix between two realizations
Recovering the similarity transformation.
8. Realizations 149

 This is another simple system and its Kalman controllable realization.

In[37]:= system  StateSpace3, 0, 0, 0, 1, 0, 1, 2, 2,
0, 0, b1 , 0, 0, b2 , c1 , 0, 0, 0, 0, c3 , d11 , d12 , d21 , d22 

3 0 0



0 0
 0 1 0 b

 0

 1


Out[37]=  1 2 2 0 b2



 c1 0 0 d11 d12



 0 0 c3 d21 d22 •

In[38]:= KalmanControllableFormsystem


 1 0 0 b1 0 



 2 2 1 0 b2



Out[38]=  0 0 3 0 0



 0 0 c1 d11 d12




 0 c3 0 d21 d22 •

 This gives the transformation matrix between the two realizations.

In[39]:= TransformationMatrixsystem, % 

 0 1 0 



 0 0 1



Out[39]=
 1 0 0

 Indeed, the similarity transformation of the original system with this matrix, which
is known to be orthogonal, brings about the Kalman controllable realization.
In[40]:= SimilarityTransformsystem, % , OrthogonalTransformMatrix  True


 1 0 0 b1 0 



 2 2 1 0 b2





Out[40]=   0 0 3 0 0



 0 0 c1 d11 d12



 0 c3 0 d21 d22 •
9. Feedback Control Systems Design

Feeding a weighted part of the state or output variables back to the input is a method often
used to correct the behavior of control systems. This chapter describes the tools provided in
Control System Professional to design such feedback schemes by enforcing the desired pole
location on the complex plane. Another approach, using the optimal control technique, is
discussed in Chapter 10. The methods described here are applicable to continuous- or
discrete-time systems as long as the proper values of the poles—on the s - or z -plane—are
supplied.

 9.1 Pole Assignment with State Feedback


By closing the loop of an nth -order system

x  Ax  Bu (9.1)


with the state feedback control u  Kx, one forces the system's poles, that is, the eigenvalues
of matrix A  BK , to assume the new positions

Λ1 , Λ2 , …, Λn (9.2)
The problem of finding the matrix K that yields the desired locations of poles Λi is often
referred to as the pole assignment or pole placement problem. The function StateFeedback
Gains attempts to find its solution, assuming that the input system is completely controllable.
So long as the algorithm does not require knowledge of matrices C and D , they may be
omitted in the state-space description of the input system.

StateFeedbackGainsstatespace, poles
find the feedback gain matrix that places poles 
of the state-space system statespace into poles
State feedback design.

As an example, we consider a model of the single-axis satellite control system depicted in


Figure 9.1. The transfer function for the system is Hs  Θs  us  1  s2 , where Θ is the angle
of the satellite axis with respect to a reference, u  M  J is the normalized input variable, M is
the control torque applied by the thruster, and J is the moment of inertia about the center of
9. Feedback Control Systems Design 151

mass (Franklin et al. (1990)).

Reference

Figure 9.1. One-degree-of-freedom model of satellite attitude control.

 Load the application.

In[1]:= <<ControlSystems`

 This is the transfer function for the satellite control system.


1
In[2]:= TransferFunction s,  
s2
1 
Out[2]=  2 


 This finds a discrete-time realization of the system for sampling period T .

In[3]:= ToDiscreteTimeStateSpace% , Sampled  Period T


 T2
 1 T

 2
Out[3]= 

 0 1 T

1 0 0
T

 This designs the discrete-time controller that would place the poles of this system
into the desired locations z1 and z2 in the complex plane.
In[4]:= StateFeedbackGains% , z1, z2  Simplify

z11 z21
Out[4]= 
T2


z2 z1z1z23
2T
152 Control System Professional

 This is the controller gain matrix for the particular case z  0.8
0.2 j and sampling
period T  0.1 seconds.
In[5]:= % . z1  .8  .2 , z2  .8  .2 , T  0.1  Chop

Out[5]=  8. 3.6 

Feedback design is prone to significant numerical errors, especially for high-order or weakly
controllable systems. StateFeedbackGains has several options that help to avoid meaning-
less results. There are also some options pertaining to the method being applied.

option name default value

Method Automatic method to use


VerifyPoles Automatic whether to check
resulting closed-loop poles
against the ones required
AdmissibleError 0.01 relative error in pole
position considered admissible

Some of the options for StateFeedbackGains.

The option Method determines what method to use to compute the feedback gains. In the
base package, two methods are available: Ackermann and KNVD. The option value Auto
matic imposes the following division of labor: KNVD is called for inexact input and for a
special case of exact input, namely when the number of inputs is equal to the number of
states; Ackermann is used otherwise.

Using the option VerifyPoles, it is possible to check if the poles of the closed-loop system
are indeed (close to) the required ones. For the option value Automatic, the check is made
only if the input is inexact. The value must be set to True to perform the check on exact input
or input containing symbolic expressions. The option can be set to False to save some comput-
ing time.

The option AdmissibleError relates to the option VerifyPoles and specifies the relative
error in the location of poles that is deemed admissible. The value in no way affects the result
of the computation. If the required accuracy has not been reached, it is up to the user to
choose the appropriate strategy. Traditionally, the case would require changing the method of
computation, reconsidering the requirement for accuracy, or even reformulating the problem.
In Mathematica, one may also use a built-in mechanism for manipulating the precision, which
may resolve some problems of this sort.
9. Feedback Control Systems Design 153

 Consider a hypothetical eighth-order system.

In[6]:= n  8;

In[7]:= a  DiagonalMatrixRangen   N

 1. 0. 0. 0. 0. 0. 0. 0.

 0.
 2. 0. 0. 0. 0. 0. 0.

 0. 0. 3. 0. 0. 0. 0. 0.

 0.
 0. 0. 4. 0. 0. 0. 0.
Out[7]= 
 0.
 0. 0. 0. 5. 0. 0. 0.

 0.
 0. 0. 0. 0. 6. 0. 0.

 0.
 0. 0. 0. 0. 0. 7. 0.

 0. 0. 0. 0. 0. 0. 0. 8.

In[8]:= b  Table1., n 

 1.

 1.

 1.

 1.

Out[8]= 
 1.

 1.


 1.


 1.

 Suppose this is the list of the desired pole locations after the loop is closed.

In[9]:= poles  Rangen , 1

Out[9]= 8, 7, 6, 5, 4, 3, 2, 1

 Let us try to place the poles using Ackermann's formula (defined shortly) while
making sure that the target is not missed by more than 0.0001 percent. We are
warned that the goal has not been achieved. (Since we are not particularly interested
in the concrete values of the gains, we suppress the output by placing the semicolon
in the end of the input statement.)
In[10]:= StateFeedbackGainsa, b, poles,
Method  Ackermann , AdmissibleError  .000001;

StateFeedbackGains::bpl : Warning: Pole location


may deviate from the required one by more than 0.0001`%
154 Control System Professional

 On our machine, the machine-precision numbers are 16 digits long.

In[11]:= $MachinePrecision

Out[11]= 16

 This increases the precision of our parameters.

In[12]:= a, b, poles  SetPrecision a, b, poles, 25;

 By increasing the precision of the input, we force the feedback computation to be


done with higher precision. Now we are presented with no warning.
In[13]:= StateFeedbackGainsa, b, poles,
Method  Ackermann , AdmissibleError  .000001;

 We double-check the result. The achieved accuracy is even greater than required.

In[14]:= MaxEigenvaluesa  b.%   poles

Out[14]= 5.44 1021

9.1.1 Ackermann's Formula

According to Ackermann's formula, the feedback matrix K that places the poles of a
single-input system x  Ax  Bu into the positions Λ1 , Λ2 , …, Λn can be found as

K  en C1 ΦA (9.3)

where

en  0 0  0 1

is the unit vector of length n ,

C  B AB A2 B  An1 B

is the controllability matrix, and

ΦA  An  Α1 An1  Α2 An2    Αn1 A  Αn I


9. Feedback Control Systems Design 155

is the characteristic polynomial of matrix A . Here I is the identity matrix, and the coefficients
Αi are such that Λ1 , Λ2 , … , Λn are the roots of the polynomial:

s  Λ1 s  Λ2  s  Λn   sn  Α1 sn1  Α2 sn2    Αn1 s  Αn

The function StateFeedbackGains with the option Method Ackermann implements this
algorithm.

Method Ackermann compute the feedback matrix using Ackermann's formula

State feedback design using Ackermann's formula.

The Ackermann method, besides being useful for single-input systems, may also find applica-
tion if an attempt is to be made to control a multi-input system through a single input. The
option ControlInput Automatic is used in such cases to find the "best" control using the
condition number of the corresponding controllability matrix as a criterion. It is also possible
to specify the control input explicitly.

option name default value

ControlInput Automatic which input to choose as control

Option specific to the Ackermann method.


156 Control System Professional

Figure 9.2. F-8 aircraft in flight. Photograph by Dryden Flight Research Center, NASA.

As an example we consider an approximate model of the lateral dynamics of an F-8 aircraft


(Figure 9.2) linearized about a particular set of flight conditions and reproduced after Brogan
(1991). The state and input vectors in the model are

 p 
 
   ∆ 
 r   a 
 
x    and u   

 Β   ∆r
 
 Φ 
 

where p, r , Β , and Φ are the roll and yaw rates and the sideslip and roll angles, respectively,
and ∆a and ∆r are the aileron and rudder deflections. Figure 9.3 introduces the nomenclature.
9. Feedback Control Systems Design 157

Rudder ∆r

Front view

Top view

Ailerons
Β

Figure 9.3. Aircraft schematic.

 This is the state-space model of the aircraft.

In[15]:= aircraft 
StateSpace10, 0, 10, 0, 0, .7, 9, 0, 0, 1, .7, 0, 1, 0, 0, 0,
20, 2.8, 0, 3.13, 0, 0, 0, 0

 10 0 10 0 20 2.8 



 0 0.7 9 0 0 3.13
Out[15]= 
 0 1 0.7 0 0 0

 1 0 0 0 0 0

 Here are the closed-loop poles we wish the system to have.

In[16]:= poles  10, 8, 5, 2;

StateFeedbackGains may be asked to determine whether it is possible to control the


aircraft using only one of the inputs if, say, a malfunction prevents manipulation of the other.
If such input exists, the feedback gain matrix will contain a nonzero row corresponding to this
input.
158 Control System Professional

 StateFeedbackGains finds that the system is better controlled through the


second input (i.e., the rudder deflection) and returns the corresponding feedback
gains.
In[17]:= StateFeedbackGainsaircraft, poles, Method  Ackermann 


0 0 0 0
Out[17]=
 16.9205 19.4816 25.6083 169.205

 The attempt to control the aircraft from only the first input fails, and we are
presented with messages suggesting that the trouble possibly stems from the system
being uncontrollable.
In[18]:= StateFeedbackGainsaircraft, poles, Method  Ackermann , ControlInput  1

LinearSolve::nosol :
Linear equation encountered which has no solution.

StateFeedbackGains::nos :
Cannot find feedback gain matrix. The system may not be controllable.

Out[18]= StateFeedbackGains
StateSpace10, 0, 10, 0, 0, 0.7, 9, 0, 0, 1, 0.7, 0, 1, 0, 0, 0,
20, 2.8, 0, 3.13, 0, 0, 0, 0,
10, 8, 5, 2, Method  Ackermann, ControlInput  1

 Indeed, the system is not controllable from its first input; in other words, the aircraft
cannot be controlled by only the aileron deflections (at least not within the linearized
model).
In[19]:= ControllableSubsystemaircraft, 1

Out[19]= False

9.1.2 Robust Pole Assignment

Ackermann's formula does not provide for multi-input control and, even for a single-input
case, the resulting matrix can be very badly conditioned. The robust algorithm by Kautsky et
al. (1985), which is accessible via the method KNVD, often offers a better alternative. In the case
where the number of states is greater than the number of control inputs, the algorithm uses
the additional degrees of freedom to find the solution that is as insensitive to perturbations as
possible.
9. Feedback Control Systems Design 159

Method KNVD compute the feedback matrix using


the Kautsky-Nichols-Van Dooren algorithm

State feedback design using the robust method by Kautsky et al.

The algorithm depends heavily on numerical quantities of the system in question and so is
implemented for inexact input parameters only. However, for the particular case where the
number of inputs is equal to the number of states and matrix B is not singular, the solution
may be found simply from K  B1 A   (where  is the diagonal matrix determined by the
eigenvalues Λ1 , Λ2 , …, Λn ), and is attempted for exact and symbolic arguments, too.

In the KNVD regime, StateFeedbackGains accepts the option RandomOrthogonalComple 


ment, similarly to other functions that need to reconstruct the basis of the vector space given
an insufficient number of orthogonal components.

The "robustness" of the system designed using the KNVD method may improve after several
iterations, the number of which can be set via the option MaxIterations. Note, however,
that the implemented algorithm is not guaranteed to converge.

option name default value

MaxIterations 1 how many iterations to try

Option specific to the KNVD method.

In the rest of this section, the solutions obtained with the Ackermann and KNVD methods are
compared in terms of their robustness for the aircraft model.

 This finds the feedback via Ackermann's formula—reproducing the result we


already have.
In[20]:= kA  StateFeedbackGainsaircraft, poles, Method  Ackermann 


0 0 0 0
Out[20]=
 16.9205 19.4816 25.6083 169.205

 Now we obtain the feedback using the KNVD algorithm with a single iteration.

In[21]:= k1  StateFeedbackGainsaircraft, poles, Method  KNVD, MaxIterations  1

 0.4 0.250479 0.347476 4.


Out[21]=  14

 4.90531  10 1.78914 1.08946 4.27485  1013

160 Control System Professional

 This is the solution using the same method after 10 iterations.

In[22]:= k10 
StateFeedbackGainsaircraft, poles, Method  KNVD, MaxIterations  10

 0.31088 0.516493 1.13904 2.94829


Out[22]= 
 0.982774 3.23775 2.026 6.18559

To measure the robustness of the solutions, we distort the feedback matrices to some extent
(as if due to noise in the line) and see how that will affect the locations of the poles of the
closed-loop system. In practice, we would prefer the noise to have as little effect as possible.

 This is a utility function that distorts all numeric values in expr to some degree, up
to the maximum relative error err.
In[23]:= distortexpr_, err_ :
expr . x_ ? NumberQ  x 1  RandomReal, err, err

 We form the list comprising all three feedback matrices we have computed so far
and distort them as much as 1 percent.
In[24]:= dks  distortkA, k1, k10, .01;

 These are the three groups of eigenvalues of the corresponding distorted closed-loop
systems.
In[25]:= EigenvaluesStateFeedbackConnectaircraft, #
1  &  dks

Out[25]= 8.97859  1.21033 , 8.97859 1.21033 , 4.98785, 1.96418,


10.39, 7.68141, 5.06312, 1.97541,
9.90304, 8.05419, 5.09136, 2.00677

 Finally, these are the maximum relative errors introduced by the distortion.
#  poles
In[26]:= MaxAbs   &  %
poles

Out[26]= 0.194556, 0.0398239, 0.0182728

The last value in the list—and the smallest one—is the solution found after 10 iterations with
the KNVD method. This solution indeed looks robust—the relative error in pole location is
about as big as the imposed distortion of the feedback matrix. Comparing the second and the
third values, we see that the robustness has somewhat improved with iterations. On the other
end, the solution obtained with Ackermann's formula (the first element in the list) is not stable
against the noise.
9. Feedback Control Systems Design 161

 9.2 State Reconstruction


The prerequisite for pole assignment using state feedback is knowledge of the state variables.
So far in this chapter we have assumed that this prerequisite was somehow met. Now we
address the problem of how that can be done. In the trivial case of a square nonsingular
matrix C , the state vector can simply be computed from the input and output vectors as
x  C1 y  Du; otherwise an attempt can be made to reconstruct the state vector by forming
a device called an estimator (or observer), with which the approximation x to the state vector x
can be obtained as


x  A  LCx  B  LDu  Ly , (9.4)

where L is the estimator gain matrix. Figure 9.4 presents such a device in block diagram form
( Brogan 1991). As seen from the diagram, the estimator is driven by the difference
between the actual output measurement y and the "expected" output Cx , provided that the
direct transmission term Du is taken into account.

Observer

D B

System  .
  x^
u .
x Ax Bu
y  x^
y Cx Du L 
State estimate
 

Figure 9.4. Continuous-time estimator schematic.


162 Control System Professional

Observer

D B

System  
uk yk   ^
xk1 ^
xk
xk1 Axk Buk Delay
yk Cxk Duk L
  State estimat

Figure 9.5. Discrete-time estimator schematic.

If the initial system is completely observable, it is possible to choose gains L to be such that
the eigenvalues of Ac  A  LC assume any desired location, thereby controlling the rate at
which x follows x . This reduces the problem of finding the estimator gains to one of finding
the (transposed) controller gains for the dual system

ATc  AT  CT L T (9.5)

Therefore, the function StateFeedbackGains can be employed for the purpose. Alterna-
tively, one may use the function EstimatorGains, which performs the procedure in one
step. EstimatorGains does not introduce any new options of its own, but accepts and
passes on the options for StateFeedbackGains and DualSystem.

EstimatorGainssystem, poles
find the estimator gain matrix for system 
that places poles of the estimator at  poles
Estimator design.

The preceding diagram and equations refer to continuous-time systems. The estimator for a
discrete-time system is determined by an equation similar to Eq. (9.4):

x k  1  A  LCx k  B  LDuk  Ly k


  (9.6)
9. Feedback Control Systems Design 163

The corresponding block diagram is presented in Figure 9.5. EstimatorGains handles both
continuous- and discrete-time cases.

Another linearized state-space model of an inverted pendulum, reproduced after Gopal


(1993), will be used in the rest of this section to illustrate obtaining the estimator gain matrix.
The model assumes that the state and input vectors are, respectively,

 X 
 
  
 
 X 
x    and u  fx ,
 Θ 
  
 Θ 
 

where Θ is the angular displacement of the pendulum, X is the horizontal position of the cart,
and fx is the external force applied to the wheels. The model further assumes that the only
variable available for measurement is X , making it, therefore, the only output variable:

y X .

 Here is the state-space model.

In[27]:= StateSpace
3g m 6 g m M
0, 1, 0, 0, 0, 0,   , 0 , 0, 0, 0, 1, 0, 0,  , 0 ,
4 m 7 M 4 L m 7 L M
7 6
0,  , 0,   , 1, 0, 0, 0, 0
4 m 7 M 4 L m 7 L M

 0 1 0 0 0

 3gm 7
 0 
 0
4m7M
0
4m7M


Out[27]=  0 0 0 1 0


 6 g m  M 
 0
6

 0 0
 4Lm7LM 4Lm7 LM

1 0 0 0 0

Because we know that all symbolic variables in the input system are real-valued, we may set
the option ComplexVariables correspondingly to get a simpler result. This option will be
picked up by the function DualSystem. At this point, we will not specify the desired poles
for the estimator, but use a generic list of four symbolic values, {p1, p2, p3, p4} . Therefore,
the expression will be obtained in its general form.
164 Control System Professional

 This finds the estimator for the system and somewhat simplifies the result.

In[28]:= EstimatorGains% , p1, p2, p3, p4, ComplexVariables  None  Apart

Out[28]= p1  p2 p3  p4,


1
  6 g m  4 L p1 p2 m  4 L p1 p3 m  4 L p2 p3 m  6 g M 
L 4 m  7 M
7 L M p1 p2  7 L M p1 p3  7 L M p2 p3  p1  p2  p3 p4,
1
  6 g m p1  6 g M p1  4 L m p2 p3 p1  7 L M p2 p3 p1  6 g m p2 
3gLm
1
6 g M p2  6 g m p3  6 g M p3   6 g m  4 L p1 p2 m  4 L p1 p3 m 
3gLm
4 L p2 p3 m  6 g M  7 L M p1 p2  7 L M p1 p3  7 L M p2 p3 p4,
1
   2 m  M 6 g m  4 L p1 p2 m  4 L p1 p3 m  4 L p2 p3 m 
L2 m 4 m  7 M
6 g M  7 L M p1 p2  7 L M p1 p3  7 L M p2 p3 
1
 6 g m p1  6 g M p1  4 L m p2 p3 p1  7 L M p2 p3 p1 
3gLm
6 g m p2  6 g M p2  6 g m p3  6 g M p3 p4

 This is the result for a particular set of numerical values.

In[29]:= % .  m  .15, M  1, L  2, g  9.81, p1  2, p2  2  , p3  2  , p4  3 


Chop

Out[29]= 9, 35.4532, 153.358, 323.456


10. Optimal Control Systems Design

Given the constraints U on control functions ut that form the set of admissible controls
ut  U for all t  t0 , t1  and the constraints X on the state trajectories xt that form the set
of admissible trajectories xt  X for all t  t0 , t1  , the optimal control problem is to find an
admissible control function ut that forces the continuous-time system

x  fxt, ut, t (10.1)


to follow an admissible trajectory xt while minimizing the performance criterion

J  Sxt1 , t1    t Lxt, ut, t t (10.2)


t01

If the solution to the optimal control problem can be found in the form

ut  uxt, t (10.3)


then the control is said to exist in the closed-loop form, and Eq. (10.3) is referred to as the
optimal control law.

In Eq. (10.2), the function S is the cost associated with error in the terminal state at time t1 ,
and L penalizes for transient state errors and control effort. In the particular case of quadratic
cost functions,

S  xT t1 Mxt1  (10.4)

and

L  xT tQxt  uT tRut (10.5)

or (in the form that includes the cross-term P)

L  xT tQxt  uT tRut  2uT tPxt (10.6)

where the desired state is assumed to be x  0 .

Matrices M , Q , and R must be square; M and Q must have a length equal to the number of
states; and R must correspond in dimension to the number of inputs. Additionally, to ensure
that the solution is unique and finite, matrices M and Q must be positive semidefinite and
166 Control System Professional

matrix R must be positive definite. The cross-term problem in Eq. (10.6) is reducible to the one
in Eq. (10.5), and so matrix P must be of a form that brings about suitable Q and R .

The components of the matrices reflect the emphasis the designer places on corresponding
errors. For instance, if R is a diagonal matrix, a relatively larger value of Rii means that more
control effort will be allotted to regulate input ui . In a sense, the art of choosing the elements
of Q , R, and M is similar to the art of selecting the proper pole locations in the feedback
design via pole assignment.

The optimal control problem can be restated similarly for discrete-time control systems

xk  1  fxk, uk (10.7)


and the performance criterion is

N1
J  SxN   Lxk, uk (10.8)
k0

Control System Professional addresses both continuous- and discrete-time problems.

 10.1 Linear Quadratic Regulator


In the case of the linear system

x  Ax  Bu (10.9)


or

xk  1  Axk  Buk (10.10)


and quadratic cost functions, the optimal control problem is said to be the linear-quadratic (LQ)
optimal control problem. Further, for constant-coefficient matrices A and B and terminal time
infinitely far in the future (meaning, of course, that the operating time is sufficiently long
compared to the time constants of the system), the problem is referred to as the infinite-horizon
or infinite-time-to-go problem. In this case, the control law in Eq. (10.3) simplifies to

u  Kx (10.11)
with a constant-coefficient feedback gain matrix K. Note that the penalty function S for
terminal constraint in Eq. (10.2) and Eq. (10.8) is not an issue for the infinite-horizon problem.
The function LQRegulatorGains attempts to find the matrix K for this particular case. It
recognizes the type of system supplied to its input—continuous- versus discrete-time—and
10. Optimal Control Systems Design 167

acts accordingly. As is the case with the pole assignment problem, furnishing matrices C and
D in the state-space description is optional.

LQRegulatorGainsstatespace, q, r
find the optimal feedback gains for the 
system statespace and the quadratic cost 
function defined by weighting matrices q and r

LQRegulatorGainsstatespace, q, r, p
find the optimal feedback for the case where the 
quadratic cost function contains the cross-term  p
Linear quadratic regulator design.

As an example, we design an optimal regulator for the mixing tank shown in Figure 10.1. The
tank (Gopal (1993)) implements concentration control of a chemical mixture with inflows
through two regulated valves at rates Q1 and Q2 and concentrations C1 and C2 , respectively.
Outflow is at the rate Q with concentration C . The volume of the liquid in the tank is V . The
state, input, and output vectors are assumed to be as follows:

 V
 Q
 Q

1
x  , u  , and y 
 C
 C  Q2

The design will be carried out in the discrete-time domain.

Q1 , C1 Q2 , C2

Tank

Q, C

Figure 10.1. Mixing tank schematic.


168 Control System Professional

 Load the application.

In[1]:=  ControlSystems`

 This is a state-space representation of the mixing tank system for a particular set of
parameters.
In[2]:= tank  StateSpace0.01, 0, 0, 0.02,
1, 1, 0.004, 0.002, 0.01, 0, 0, 1

 0.01 0 1 1 
 
 0 0.02 0.004 0.002 
Out[2]= 
 

 0.01 0 0 0 
 
 0 1 0 0 •

 This is a discrete-time approximation of the system sampled with a period of 5


seconds.
In[3]:= tankd  ToDiscreteTime% , Sampled  Period 5


 0.951229 0. 4.87706 4.87706 
 
 0. 0.904837 0.0190325 0.00951626 
Out[3]= 
 

 0.01 0 0 0 
 
0 1 0 0 5

 This assigns some values to the weighting matrices Q and R .

In[4]:= q  DiagonalMatrix.01, 100

 0.01 0

Out[4]= 
0 100 

In[5]:= r  DiagonalMatrix2, .5

 2 0 
Out[5]=  
 0 0.5 

 This finds the optimal gain matrix.

In[6]:= LQRegulatorGainstankd , q , r

 0.0223257 3.30934 
Out[6]=  
 0.0778205 3.81983 
10. Optimal Control Systems Design 169

 To check the regulator in action, we plug it into the state feedback. This is the device
after the loop is closed.
In[7]:= StateFeedbackConnecttankd , % 


 0.462811 2.48971 4.87706 4.87706 
 
 0.000315645 0.805502 0.0190325 0.00951626 
Out[7]= 
 

 0.01 0. 0. 0. 
 
 0. 1. 0. 0. 5

 This simulates the output response of the closed-loop system to an impulse signal at
the second input; in other words, it shows how the outflow rate and the
concentration react to a short, sudden increase in the flow rate of the second
chemical. The outflow rate and the concentration are shown as the dash-dotted and
dotted lines, respectively.
In[8]:= SimulationPlot% , 0, DiscreteDeltat, t, 200, PlotStyle 
Dashing .1, .01, .01, .01, Dashing .01, PlotRange  All;

0.04

0.03

0.02

0.01

50 100 150 200


170 Control System Professional

 For comparison's sake, we plot the same graph for the original system. The outflow
rate and the concentration are now shown as the solid and dashed lines.
In[9]:= SimulationPlottankd , 0, DiscreteDeltat,
t, 200, PlotStyle  Thickness.001, Dashing .05;

0.04

0.03

0.02

0.01

50 100 150 200

 Finally, we combine the two plots in one graph, which shows clearly that the
regulated system has a significantly faster response.
In[10]:= Show % , %% ,
PlotLabel  "Regulated Vs. Original System", PlotRange  All;
Regulated Vs. Original System

0.04

0.03

0.02

0.01

50 100 150 200

A successful regulator design is possible only for a stabilizable system. Otherwise, LQRegula
torGains does not return any solution.

 Here are matrices A and B for a system that is not stabilizable (because it is both
unstable and uncontrollable).
3 1
In[11]:= aa   ;
0 2

1
In[12]:= bb   ;
0
10. Optimal Control Systems Design 171

 We assign equal weight to all inputs and states.

In[13]:= q  DiagonalMatrix1., 1.; r  1.;

 The attempt to build the regulator fails, as it should.

In[14]:= LQRegulatorGainsStateSpaceaa, bb, q , r

LinearSolve::nosol :
Linear equation encountered which has no solution.

Out[14]= LQRegulatorGains
StateSpace3, 1, 0, 2, 1, 0, 1., 0, 0, 1., 1.

 This modifies matrix A so that the system is stable (though still uncontrollable).
3 1
In[15]:= aa   ;
0 2

 Now the regulator can be built.

In[16]:= LQRegulatorGainsStateSpaceaa, bb, q , r

Out[16]=  0.162278 0.0314353 

The optimal regulator design is based on solving the appropriate algebraic Riccati equation.
The corresponding functions—RiccatiSolve and DiscreteRiccatiSolve —can be
accessed directly, if so desired, and are described in Section 10.3. LQRegulatorGains shares
with the Riccati equation solvers the limitations imposed on the input arguments and accepts
the options accepted by the Riccati solvers.

 10.2 Optimal Output Regulator


Closely related to the function LQRegulatorGains, which optimizes a system's behavior
with regard to state variables, is the function LQOutputRegulatorGains , which finds the
optimal solution to the output regulator problem. The cost function for this case contains
outputs y instead of states x (cf. Eq. 10.5).

L  yT tQyt  uT tRut (10.12)

LQOutputRegulatorGains calls LQRegulatorGains and accepts the same options, the


syntactic difference between the two being that the output regulator function, obviously, does
172 Control System Professional

require matrix C (and matrix D, if necessary) in the state-space description of the input sys-
tem.

LQOutputRegulatorGainsstatespace, q, r
find the optimal feedback
matrix for the output regulator problem
Linear quadratic output regulator design.

 Reconsider the mixing tank problem from Figure 10.1. We wish to design the output
regulator with matrices Q and R as given.
In[17]:= tank  StateSpace0.01, 0, 0, 0.02,
1, 1, 0.004, 0.002, 0.01, 0, 0, 1

0.01 0
  
1 1
 0 0.02 0.004 0.002  

Out[17]=  

 0.01 0 0 0 
 
 0 1 0 0 •

In[18]:= q  DiagonalMatrix10, .01

 10 0 
Out[18]=  
 0 0.01 

In[19]:= r  DiagonalMatrix2, .2

 2 0 
Out[19]=  
 0 0.2 

 This solves the problem.

In[20]:= LQOutputRegulatorGainstank, q , r

 0.00589458 0.000624227 
Out[20]=  
 0.0589383 0.00125691 

 10.3 Riccati Equations


Finding the optimal control for a continuous-time linear system with a quadratic cost function
involves solving the differential Riccati equation, which, for the case of the infinite-horizon
problem, simplifies to the algebraic Riccati equation (ARE)
10. Optimal Control Systems Design 173

AT W  WA  WBR1 BT W  Q  0 (10.13)

The discrete-time case requires solution of the discrete algebraic Riccati equation (DARE)

1
W  Q  AT WA  AT WBR  BT WB BT WA (10.14)

(see, for example, Brogan (1991), Section 14). These are equations in an unknown matrix W
that could be viewed as systems of coupled quadratic equations regarding the unknown
components Wi j and as such could be attempted using the built-in Mathematica functions
Solve and NSolve. Control System Professional provides also two more specialized functions
that can be more efficient than the general-purpose solvers.

RiccatiSolvea, b, q, r solve the algebraic Riccati equation

DiscreteRiccatiSolvea, b, q, r
solve the discrete algebraic Riccati equation
Functions for solving Riccati equations.

 Consider again the double-integrator system.


1
In[20]:= StateSpaceTransferFunction s,  
s2

 0 1 0 
 
Out[20]=  0 0 1 
 
 1 0 0 •

 This extracts matrices A and B.

In[21]:= aa  % 1
; bb  % 2
;

 Let all the weights be equal.

In[22]:= q  DiagonalMatrix1, 1; r  1;

 This is the solution to the corresponding ARE.

In[23]:= RiccatiSolveaa, bb, q , r


  3 1 
Out[23]=   
 1 3 
174 Control System Professional

 Consider now another second-order system.


1
In[24]:= StateSpaceTransferFunction s,  
s s  .5

 0 1. 0 
 
Out[24]=  0 0.5 1 
 
1 0 0 •

 This time we find its discrete-time equivalent for a sampling period of,
say, 1 second.
In[25]:= ss  ToDiscreteTime% , Sampled  Period 1


 1. 0.786939 0.426123 
 
Out[25]=  0. 0.606531 0.786939 
 
1 0 0 1

 This extracts matrices A and B.

In[26]:= aa  ss 1
; bb  ss 2
;

 This solves the DARE.

In[27]:= DiscreteRiccatiSolveaa, bb, q , r

 2.40153 1.05792 
Out[27]=  
 1.05792 2.09705 

 We can use the result to find the optimal feedback gains.

In[28]:= InverseTransposebb.% .bb  r.Transposebb.% .aa

Out[28]=  0.538833 0.794026 

 We could also arrive at this result by using LQRegulatorGains directly.

In[29]:= LQRegulatorGainsss, q , r

Out[29]=  0.538833 0.794026 

For yet another example, let us design a controller for the roll attitude of a missile
(Figure 10.2). The controller must, by using the hydraulic-powered ailerons, keep roll attitude
Φ close to zero while staying within the physical limits of aileron deflection ∆ and aileron

deflection rate ∆ (Bryson and Ho (1969)). In the state-space description, it is assumed that the
10. Optimal Control Systems Design 175


system has one input, which accepts the command signal to aileron actuators u  ∆ so that

u  ∆ and the state vector is

 ∆




x  Φ

Φ


The performance index we choose is

Φ2
1 ∆2 u2 
J    2  2  2  d t
2 0  Φ0 ∆0 u0 

resulting in matrices Q and R as shown below. Φ0 and ∆0 are the maximum desired values of
Φ and ∆, and u0 is the maximum available value of u .

Front view Top view


Ailerons

Figure 10.2. Roll attitude control of a missile.

 This is the A matrix for the model. Q and Τ are the aileron effectiveness and roll-time
constant, respectively.

0 0 0
 


  1 0 
Q   


In[30]:= aa  

 
;
 
Τ Τ 
 
 0 1 0
176 Control System Professional

 This is matrix B .

 
1
 
In[31]:= bb  
 ;
0 
   
0 

 These are the matrices Q and R for the performance index.


1 1
In[32]:= q  DiagonalMatrix  , 0,  
∆0 2 Φ0 2

 1
0 0 
 ∆20 
 
Out[32]=  
 
0 0 0 
 
 0 0 1 
 Φ 0 
2

1
In[33]:= r    
u0 2



1
Out[33]= u20 

 We choose a set of numeric values for our parameters.


Π Π
In[34]:= Τ  1, Q  10, u0  Π, ∆0   , Φ0   
12. 180.
Out[34]= Τ  1, Q  10, u0  Π, ∆0  0.261799, Φ0  0.0174533

 We then reassign the matrices using these values.

In[35]:= aa, bb, q , r  aa, bb, q , r . % ;

 Applying RiccatiSolve to this list solves the corresponding Riccati equation.

In[36]:= RiccatiSolve %

2.72757 2.94179 18.2378 


  

Out[36]=  2.94179 6.38971 49.0962 
 
 
 18.2378 49.0962 578.619 

 We can use the solution to find the optimal feedback matrix.

In[37]:= Inverser.Transposebb.%

Out[37]=  26.92 29.0343 180. 


10. Optimal Control Systems Design 177

 Again, the result is the same as the one obtained with LQRegulatorGains.

In[38]:= LQRegulatorGainsStateSpaceaa, bb, q , r

Out[38]=  26.92 29.0343 180. 

RiccatiSolve and DiscreteRiccatiSolve work by finding the eigensystem of the


corresponding Hamiltonian matrix. Alternatively, you may use the Schur decomposition
method, which has advantages for systems with multiple or near-multiple eigenvalues of the
Hamiltonian (Laub 1979). The method is accessible by selecting the option SolveMethod
SchurDecomposition (which is available for RiccatiSolve only). If this method is
chosen, RiccatiSolve does not accept infinite-precision input since neither does the built-in
function SchurDecomposition . The default Automatic setting of the option selects the
Eigendecomposition or SchurDecomposition method depending on whether the input
matrices are exact or not (for DiscreteRiccatiSolve , Eigendecomposition is chosen
in either case).

option name default value

SolveMethod Automatic method to find the basis of the eigenspace

Option specific to RiccatiSolve.

Solving Riccati equations involves sorting eigenvalues of the Hamiltonian (which is required
to separate stable and unstable eigenvalues); therefore, the eigenvalues should not contain
symbolic parameters. If symbolic parameters are used, a warning is issued and LQRegulator
Gains returns unevaluated. This, of course, does not mean that the system cannot be solved
symbolically; however, such a case requires human intervention in the selection of stable
poles.
178 Control System Professional

 10.4 Discrete Regulator by Emulation of Continuous Design


If the optimal regulator has been designed for a continuous system so that matrices Q and R
(and possibly P) are constructed to meet the design specifications, this knowledge can be
applied to find a discrete equivalent of the optimal regulator. The procedure starts with
computation of the discrete equivalent of the continuous cost function and then the discrete
regulator is designed based on the discrete equivalent cost (see Franklin et al. (1990),
Section 9.4.4). This algorithm is implemented in DiscreteLQRegulatorGains . Its syntax
closely resembles that for LQRegulatorGains , and it accepts the same set of options. In
addition, DiscreteLQRegulatorGains accepts the options related to the function ToDis
creteTime.

DiscreteLQRegulatorGainsstatespace, q, r
design the discrete emulation of the 
continuous optimal regulator for the system 
statespace and weighting matrices q and r

DiscreteLQRegulatorGainsstatespace, q, r, p, t
design the emulation for a cost function 
containing the cross-weighting matrix  p
Finding the discrete equivalent of a continuous optimal regulator.

 This is the model for the satellite system.


1
In[39]:= satellite  StateSpaceTransferFunction   
#2

 0 1 0 
 
Out[39]=  0 0 1 
 
 1 0 0 •

 Following an example in Franklin et al. (1990), we assume that these are the matrices
Q and R that lead to satisfactory behavior of the closed-loop system.
In[40]:= q  1, 0, 0, 0; r  0.01;
10. Optimal Control Systems Design 179

 This is the optimal regulator matrix for the continuous case.

In[41]:= LQRegulatorGainssatellite, q , r

Out[41]=  10. 4.47214 

 This is matrix A for the corresponding closed-loop system.

In[42]:= StateFeedbackConnectsatellite, %  1

  
0. 1.
Out[42]=
 10. 4.47214 

 These are the poles of the system. We want the discrete emulation to have poles
close to these.
In[43]:= poles  Eigenvalues% 

Out[43]= 2.23607 2.23607 , 2.23607  2.23607 

 First we decide on the sampling period. To find a suitable time scale, we compute
the characteristic polynomial of the closed-loop system.
In[44]:= CharacteristicPolynomial%% , s  Expand  Chop

Out[44]= 10.  4.47214 s  s2

 Comparing the preceding result with its representation via natural frequency Ωn
and damping coefficient Ζ , Ω2n  2ΖΩn s  s2 , we find the characteristic time
tn  2Π  Ωn .
2 Π
In[45]:= tn  



Coefficient% , s, 0

Out[45]= 1.98692

 We choose a sampling period several times smaller than the characteristic time.
tn
In[46]:= ts  
6
Out[46]= 0.331153
180 Control System Professional

 This is the discrete regulator that emulates the continuous one.

In[47]:= DiscreteLQRegulatorGainssatellite, q , r, Sampled  Period ts

Out[47]=  4.82977 3.10798 

 These are the poles of the corresponding discrete-time closed-loop system. The poles
are in the z -plane.
In[48]:= EigenvaluesStateFeedbackConnect
ToDiscreteTimesatellite, Sampled  Period ts, %   First

Out[48]= 0.35298  0.333181 , 0.35298  0.333181 

 This maps the poles back to the s -plane.


Log % 
In[49]:= 
ts
Out[49]= 2.18268 2.2846 , 2.18268  2.2846 

 As we can see, the poles of the emulation system match the ones found by the
continuous design within a few percentage points.
%  poles
In[50]:= Abs  
poles

Out[50]= 0.0228161, 0.0228161

The function DiscreteLQRegulatorGains should not be confused with LQRegulator


Gains, which, given a discrete-time StateSpace object as input, designs a discrete regulator.
The difference between the two functions is that the former generates a discrete object from a
continuous-type input, whereas the latter makes no type conversion; given continuous- or
discrete-type input, it returns output of the same type. To reinforce the difference, Discrete
LQRegulatorGains generates an error message if a meaningless attempt is made to feed it a
discrete-time StateSpace object.
10. Optimal Control Systems Design 181

 10.5 Optimal Estimation


Section 9.2 introduced the device called the estimator (or observer) and the function Estima
torGains, which computes the gain matrix for the device. Input and output measurements
were assumed to be known precisely so the problem could be referred to as the deterministic
state reconstruction. Consider now a linear system whose state vector is subject to some
random disturbances wt, called the process noise, and whose output measurements are
contaminated with noise vt, called the measurement noise

x t  Axt  But  Bwwt


(10.15)
yt  Cxt  Dut  Dwut  vt
The noise processes are assumed to have flat spectra (white noise), zero mean values

Ewt  0
Evt  0

and covariance matrices Q and R

EwtwT Τ  Q∆t  Τ


EvtvT Τ  R∆t  Τ

Here Ex denotes the mean of random variable x . The two noises may further be assumed to
be mutually uncorrelated,

EvtwT Τ  0

or if they are correlated, then their cross-covariance matrix is P:

EvtwT Τ  P∆t  Τ

If the observer with the same structure as in Figure 9.4 (Figure 9.5 for the discrete-time case) is
applied to find the state estimates from noisy measurements, and the dual algorithm to the
one used by the linear quadratic regulator is used to find the estimator gain matrix L , then the
observer provides the least-square unbiased estimation for the state vector and is called the
Kalman filter (or Kalman estimator). As with the infinite-horizon problem, one can consider the
steady-state constant-gain solution to the optimal estimation problem that is arrived at when
both process and measurement noises are stationary (at least in the wide sense) and the
182 Control System Professional

estimator operates for a sufficiently long time. The algorithm is implemented in the function
LQEstimatorGains . The corresponding block diagrams are given in Section 10.7, where the
KalmanEstimator function is introduced.

If, in addition, the noise terms have Gaussian distributions, then LQEstimatorGains finds
the solution to the so-called linear quadratic Gaussian (LQG) problem. In this case, the estima-
tion not only is optimal in the least-squares sense, but also satisfies the most-likelihood require-
ments.

Real processes never have (nor could have) absolutely flat spectra (i.e., be absolutely uncorre-
lated in time). At high spectral frequencies, the spectrum bends downwards, whereas at low
frequencies it usually has a significant 1  f Γ component. It is the responsibility of the user to
decide if the white-noise approximation is applicable to the particular case.

LQEstimatorGainsstatespace, q, r
find the optimal estimator matrix for the 
system statespace and process and measurement 
noises with covariance matrices q and r,
assuming that all inputs of the system are stochastic

LQEstimatorGainsstatespace, q, r, p
find the estimator gains for correlated process and 
measurement noises with cross-covariance matrix  p

LQEstimatorGainsstatespace, q, r, dinputs
or LQEstimatorGainsstatespace, q, r, p, dinputs
find the estimator gains if the 
system has deterministic inputs dinputs 
in addition to the stochastic ones
Optimal estimator design.

The function LQEstimatorGains relies on LQRegulatorGains (and, consequently, on the


Riccati equation solvers) and, therefore, accepts the same set of options and involves similar
restrictions on the input arguments.

Consider a servomechanism for the azimuth control of an antenna shown in Figure 10.3. The
system (cf. Gopal (1993)) has the state vector

 Θ


x  
 Θ
10. Optimal Control Systems Design 183

and input and output vectors

 V


u  and y  Θ
 w

where Θ is the angular position of the antenna, V is the input voltage applied to the servo
motor, and w is the disturbing torque acting on the motor's shaft. In the following examples
we will find the continuous and discrete Kalman estimators. The input wt and output vt
noise terms will be assumed to be white, mutually uncorrelated noises with zero-mean values.

Figure 10.3. Antenna schematic.

 Here is a state-space realization of the antenna mechanism.

In[51]:= antenna  StateSpace0, 1, 0, 5, 0, 0, 1, 0.1, 1, 0


 0 1 0 0 
 

Out[51]=  0 5 1 0.1 
 
 1 0 0 0 •

 This defines the noise variances.

In[52]:= q  100; r  1;

 This finds the stationary Kalman gains achieved after an observation of sufficient
length. The first input in our antenna system is the only deterministic input, which
is specified by the fourth argument to LQEstimatorGains.
In[53]:= LQEstimatorGainsantenna, q , r, 1

 0.196152 
Out[53]=  
 0.0192379 
184 Control System Professional

 This is a discrete-time approximation to antenna for some sampling period.

In[54]:= antennad  ToDiscreteTimeantenna, Sampled  Period .1


 1. 0.0786939 0.00426123 0.000426123 
 
Out[54]=  0. 0.606531 0.0786939 0.00786939 
 
1 0 0 0 0.1

 Now we let both noise terms have the same intensity.

In[55]:= qd  rd  10;

 This finds the stationary Kalman gain matrix for the discrete-time system.

In[56]:= LQEstimatorGainsantennad , qd , rd , 1

 
0.00199394 
Out[56]= 
 0.0000203033 

Like most other functions in Control System Professional, LQEstimatorGains accepts both
continuous- and discrete-time objects and chooses the appropriate algorithm accordingly.

 10.6 Discrete Estimator by Emulation of Continuous Design


The function DiscreteLQEstimatorGains is similar in purpose to DiscreteLQRegula
torGains (see Section 10.4); it is applicable when the optimal estimator has been designed
for a continuous system and you need to create a discrete equivalent. DiscreteLQEstima
torGains first finds the discrete equivalents of the covariance matrices for process and
measurement noises using the algorithm described in Franklin et al. (1990), Section 9.5.3. Then
it converts the continuous system to a discrete one, and finally performs the discrete estimator
design using LQEstimatorGains . DiscreteLQEstimatorGains accepts the same options
as LQEstimatorGains and shares the same restrictions. In addition, it accepts the options
related to ToDiscreteTime.
10. Optimal Control Systems Design 185

DiscreteLQEstimatorGainsstatespace, q, r
design the discrete emulation of the continuous
optimal estimator for the system defined by the state
space object statespace and noise 
covariance matrices q and r

DiscreteLQEstimatorGainsstatespace, q, r, dinputs
design the emulation if the 
system has deterministic inputs dinputs
Finding the discrete equivalent of the continuous optimal estimator.

 This finds the discrete estimator gains for the continuous system antenna.

In[57]:= antenna  StateSpace0, 1, 0, 5, 0, 0, 1, 0.1, 1, 0

0 1 0 0 
  
 0 5 1 0.1 
Out[57]=  
 
 1 0 0 0 •

In[58]:= DiscreteLQEstimatorGainsantenna, q , r, 1, Sampled  Period .1

 
0.0194241 
Out[58]= 
 0.00190346 

 10.7 Kalman Estimator


Once the gain matrix L for the Kalman estimator has been found, the estimator can be con-
structed as a state-space object using KalmanEstimator. The block diagram of the device is
shown in Figures 10.4 and 10.5 for continuous and discrete cases, respectively. Notice that the
estimator outputs the estimates for both output and state variables of the system, and there-
fore can be used either as an estimator per se (for example, to form a controller, as described in
the following section) or as a filter (see the example later in this section).
186 Control System Professional

Deterministic inputs System Kalman Estimator


u

B D D B

A  y^

    . Output estimate
. 
 x x  y   x^ x^
 C L 
 Sensor State
 outputs  estimate

Bw Dw C A

Stochastic inputs

Figure 10.4. Continuous Kalman estimator.

Deterministic inputs System Kalman Estimator

B A D D B D

   _   y^
  y   x
Delay C C Delay
 Sensor Output
 outputs   estimate

L A

Bw Dw C

w x^

Stochastic inputs State estimate

Figure 10.5. Discrete Kalman estimator.


10. Optimal Control Systems Design 187

KalmanEstimatorstatespace, gains
design the Kalman estimator 
for the system statespace assuming 
that the estimator gain matrix is  gains,
all outputs of the system are sensor outputs,
and all inputs are stochastic inputs

KalmanEstimatorstatespace, gains, sensors


use the sensor outputs 
specified by the  vector sensors

KalmanEstimatorstatespace, gains, sensors, dinputs


use dinputs as additional deterministic inputs
Kalman estimator design.

 Consider a two-input, two-output system.

In[59]:= StateSpacea, b1 , b2 , c1 , c2 , d11 , d12 , d21 , d22 


 a b1 b2 
 
Out[59]=  c1 d11 d12 
 
 c2 d21 d22 •

 Let the estimator gain matrix be symbolic.

In[60]:= ll = {{l}};

 This finds the state-space representation for the Kalman estimator assuming that the
first output of the system is the sensor output and only the first of the inputs is
deterministic. The result agrees with the block diagram in Figure 10.4.
In[61]:= KalmanEstimator%% , ll, 1, 1


 a  l c1 b1  l d11 l 
 
Out[61]=  c1 d11 0 
 
 1 0 0 •
188 Control System Professional

 Now we create another system that has the same state-space matrices as the
previous one, but is in the discrete-time domain.
In[62]:= StateSpacea, b1 , b2 ,
c1 , c2 , d11 , d12 , d21 , d22 , Sampled  True

 a b1 b2 
 
Out[62]=  c1 d11 d12 
 
 c2 d21 d22 

 KalmanEstimator recognizes the discrete-time data object and, consequently,


computes the discrete-time estimator. The result satisfies the block diagram in
Figure 10.5.
In[63]:= KalmanEstimator% , ll, 1, 1

 a  a l c1 b1  a l d11 a l 
 

Out[63]=  c1  l c21 d11  l c1 d11 l c1 
 
 1  l c1 l d11 l 

Because KalmanEstimator provides estimates for output signals, too, it can be used as a
Kalman filter (Figure 10.6). In the rest of this section, we design and try out the Kalman filter,
which extracts the useful signal from additive Gaussian noise that masks the angular measure-
ments for the antenna servomechanism (see Section 10.5).

y^
Kalman
u y filter
Stochastic linear system Filtered outputs
Inputs Sensor outputs

Figure 10.6. Kalman filter connected to a system.

 This is again our antenna system.

In[64]:= antenna


 0 1 0 0 
 
Out[64]=  0 5 1 0.1 
 
 1 0 0 0 •
10. Optimal Control Systems Design 189

 Recall that the variance of the process noise is q, and the variance of the
measurement noise is r. We now make the measurement noise far more intense and
will try to filter it out with the Kalman filter.
In[65]:= q  1; r  100;

 This is the estimator gain matrix.

In[66]:= ll  LQEstimatorGainsantenna, q , r, 1

  
0.0019996
Out[66]=
 1.9992  106 

Notice that because the process noise was made relatively small and the measurement noise
was relatively large compared with the noise in the example in Section 10.5, the relatively
smaller gains in the Kalman estimator were achieved. Consequently, the Kalman filter will
rely more on re-creating the output signal from the deterministic input using the known
system dynamics than on actually processing the noisy sensor output, which is the optimal
strategy for noisy measurements.

 This is a new object, antenna1, that incorporates another stochastic input through
which the measurement noise adds directly to the output. This is done by using the
parallel connection with no input connected. The expanded system has three inputs
and one output.
In[67]:= antenna1  ParallelConnectantenna, TransferFunction 1, , 1, 1

 0 1 0 0 0 
 

Out[67]=  0 5 1 0.1 0 
 
1 0 0 0 1 •

 This finds the Kalman estimator. Note that only the first output of the estimator
gives the filtered output of the system (the rest of the outputs give estimates for the
state vector; see Figure 10.4).
In[68]:= estimator  KalmanEstimator% , ll, 1, 1

0.0019996 1. 0. 0.0019996 
  
 
 1.9992  106 5. 1. 1.9992  106 
 
Out[68]=  1.
 
0. 0. 0. 
 
 1. 
 0. 0. 0. 
 
 0. 1. 0. 0. •
190 Control System Professional

 This picks the subsystem we are currently interested in. It contains all the inputs and
the first output of the estimator.
In[69]:= filter  Subsystemestimator, All, 1

 0.0019996 1. 0. 0.0019996 
 

Out[69]=  1.9992  106 5. 1. 1.9992  106 
 
 1. 0. 0. 0. •

 Then, we connect the expanded system antenna1 and the Kalman filter according
to the diagram in Figure 10.7. First we connect the inputs. In the figure, the inputs
and outputs are numbered as they appear after this stage.
In[70]:= ParallelConnectantenna1, filter, 1, 1, 


 0 1 0 0 0 0 0 0 
 
 0 5 0 0 1 0.1 0 0 
 
 
 0 0 0.0019996 1. 0. 0 0 0.0019996 

Out[70]=  
 0 0 1.9992  106 5. 1. 0 0 1.9992  106 
 
 
 1 0 0 0 0 0 1 0 
 
 0 0 1. 0. 0. 0 0 0. •

1
2
y^
u filter
1 1  4

w 2 antenna1
3 
v
zeros

Figure 10.7. Kalman filter connection example.


10. Optimal Control Systems Design 191

 Finally, we close the feedback loop by connecting the first output of the preceding
system with its fourth input (which actually is the first input of the filter). In the
composite, the first output corresponds to the output of the system and the second
one to the filtered output.
In[71]:= composite  FeedbackConnect% , 1, 4, Positive


  
0. 1. 0. 0. 0. 0. 0. 0.
 0. 5. 
 0. 0. 1. 0.1 0. 0. 
 
 0.0019996 0. 0.0019996 
 1. 0. 0. 0.0019996 0.0019996 
Out[71]=  6 

 1.9992  106
 0. 1.9992  106
5. 1. 0. 1.9992  106 1.9992  10 
 
 1. 0. 0. 0. 0. 0. 1. 0. 
 
 0. 0. 1. 0. 0. 0. 0. 0. •

 To create the normally distributed noise, we will load this standard package.

In[72]:= Needs"Statistics`ContinuousDistributions`"

 Let the length of our simulation sequences be n.

In[73]:= n  100;

 This creates the process noise vector that has the Gaussian distribution with zero
mean and standard deviation as required.

In[74]:= w  TableRandomNormalDistribution 0, q 1, 1
, n ;

 This is the measurement noise vector.


In[75]:= v  TableRandomNormalDistribution 0, r 1, 1
, n ;

 This is the sinusoidal input signal.


2
In[76]:= u  Sin   Π Rangen   N ;
20

 We intend to supply no external signal to the summing input 4 . This prepares a


dummy zero signal for this input.
In[77]:= zeros  Table0, n ;

 This is where the simulation is performed. The result is a list of output vectors.

In[78]:= y1, y2  OutputResponsecomposite, u, w , v, zeros;


192 Control System Professional

 We wish to see how the filter suppresses the measurement noise added to the
system output signal y1. The "original" signal (before the addition of noise v) is
denoted as y10.
In[79]:= y10  y1  v;

 This plots the signals. We can see that the Kalman filter has quite successfully
restored the original signal from the noise.
In[80]:= MultipleListPloty10, y1, y2,
PlotRange  10, 10, PlotJoined  True, SymbolShape  None,
PlotLabel  "Signals prior to and after the Kalman Filter",
PlotLegend  "Original", "Noise Added ", "Filtered ";

Signals prior to and after the Kalman Filter Original


10
7.5
5
2.5 Noise Added
-2.5 20 40 60 80 100
-5
-7.5
-10 Filtered

 10.8 Optimal Controller


The optimal controller design for the stochastic systems is based on the separation principle,
which states that if the optimal estimate for the state vector in the presence of noise is avail-
able, the optimal control law can be obtained as if there were no noise in the system (see, e.g.,
Gopal 1993, Section 12.5). The idea is implemented in the function Controller. Again, if
the process and measurement noise have a Gaussian distribution, Controller forms the
LQG controller.

To use this function you must first determine both the estimator gain matrix L (using, say, the
optimal procedure in LQEstimatorGains) and the regulator matrix K (with, say, LQRegula
torGains). Figures 10.8 and 10.9 show the structure of the controller for continuous- and
discrete-time systems, respectively. Note that only the part of the system related to the sensor
outputs is shown in these diagrams. For the discrete-time case, the controller is based on the
current estimator (as opposed to the predictor estimator (see Franklin et al. 1990, Section 6.3.4)),
and thus can be called the current controller.
10. Optimal Control Systems Design 193

Controllerstatespace, egains, cgains


design the controller for the system statespace,
if the estimator gain matrix is egains 
and the controller gain matrix is cgains,
assuming that all outputs of the system are
sensor outputs and all inputs are control inputs

Controllerstatespace, egains, cgains, sensors


use the sensor outputs 
specified by the  vector sensors

Controllerstatespace, egains, cgains, sensors, dinputs


use dinputs as additional deterministic inputs,
assuming that the rest of the inputs are control inputs

Controllerstatespace, egains, cgains, sensors, dinputs, controls


use controls as the control inputs
Controller design.

Once constructed, the controller can be connected to the system according to the block dia-
gram shown in Figure 10.10. It is a state-space object whose inputs are "additional determinis-
tic inputs" and the sensor outputs of the system to be controlled. The outputs of the controller
are typically connected to control inputs of the system to close the negative feedback loop.
Inside the controller, the feedback loop for control inputs is already closed.
194 Control System Professional

Additional deterministic inputs System


Controller
u2

B2 A D 12 D 12 B2

 .  y  
 x x   
 C1 L
 
     
.
y^ x^
B1 Bw D 1w D 11 D 11 B1
C1 A 

x^
u1  
K
Control inputs
w Stochastic inputs v

Figure 10.8. Continuous-time controller.

Additional deterministic inputs System Controller

u2

B2 A D 12 D 12 B2

  y  _ 
   x
Delay C1 C1 Delay
  
    

L A

B1 Bw D 1w D 11 D 11 x^ B1

K
u1  

Control inputs
w Stochastic inputs v

Figure 10.9. Discrete-time controller based on a current estimator.


10. Optimal Control Systems Design 195

Additional deterministic inputs

 u Stochastic linear system y

Control inputs  Sensor outputs

Control gains for


deterministic problem

K Kalman
estimator
x^
Controller

Figure 10.10. Controller design and connection.

 Consider a three-input, two-output system. Suppose that the first input is the control
input and the second and third are, respectively, deterministic and stochastic inputs.
Suppose further that we wish to use first output of the system to close the feedback
loop. Therefore, estimator and controller gain matrices should both be 1 1 .
In[81]:= StateSpacea, b1 , b2 , b3 ,
c1 , c2 , d11 , d12 , d13 , d21 , d22 , d23 

a b 1 b 2 b 3 
  
 c d 
Out[81]=  1 11 d12 d13  
 
 c2 d21 d22 d23 •

 This sets the estimator and controller gains.

In[82]:= ll  l; kk  k;

 This designs the controller. We can see that the interconnections correspond to the
diagram in Figure 10.8.
In[83]:= Controller%% , ll, kk, 1, 2, 1


 a  l c1  k b1  l d11  b2  l d12 l 
Out[83]=  
 k 0 0 •
196 Control System Professional

 This is the discrete-time system with the same state-space matrices as in the
preceding example.
In[84]:= StateSpacea, b1 , b2 , b3 , c1 , c2 ,
d11 , d12 , d13 , d21 , d22 , d23 , Sampled  True

 a b1 b2 b3 
 
Out[84]=  c1 d11 d12 d13 
 
 c2 d21 d22 d23 

 The discrete-time controller is designed (cf. Figure 10.9).

In[85]:= Controller% , ll, kk, 1, 2, 1  Simplify


a  k b1  l c1  1 b2 k l d11  1  l a  k b1  d12 k l b1  a l
 



 k l d11  1 k l d11  1 k l d11  1 
 
Out[85]=  
 k l c1  1 k l d12 kl 
 
 k l d11  1 k l d11  1 1  k l d11 

 As yet another example, consider again the discrete-time model for the familiar
satellite control system (see Section 9.1). The sampling period is T.
In[86]:= satellite  ToDiscreteTime
StateSpace0, 1, 0, 0, 0, 1, 1, 0, Sampled  Period T

 T2 
 1 T 

 2 
Out[86]=  

 0 1 T 
 
1 0 0 T

 This sets the estimator and controller gains symbolically.

In[87]:= kk  k1 , k2 ; ll  l1 , l2 ;

 This finds the controller.

In[88]:= Controllersatellite, ll, kk


  
1 1 T 2 k2 1 
k1 l1  k2 l2  T 2  l2 T  l1 
 2 k1 T  k1 l1  k2 l2  T 2  l2 T  l1  1 T 
2
 2 2 2 
Out[88]=  

 T k1  l2  T k1 l1  k2 l2  1  T k2 l2  T k1 l1  k2 l2  

 l1 k1  k1  k2 l2 k2 k1 l1  k2 l2 T
11. Nonlinear Control Systems

Although systematic treatment of nonlinear control problems is currently beyond the scope of
Control System Professional, it does provide the linearization tools that may allow construction
of a linear model describing the behavior of the nonlinear system in the vicinity of some
operating point. For reasonably smooth nonlinearities, this approach may provide a useful
insight into the properties of the system, if not a suitable approximation.

 11.1 Local Linearization of Nonlinear Systems


For a nonlinear state-space system of the form

x  fx, u
(11.1)
y  hx, u
the locally linearized model is given by


x  Ax  Bu
(11.2)
y  Cx  Du

where x , y , and u are small deviations,

x t  xt  xnt


y t  yt  y t
n
u t  ut  unt

from some known solution xn , yn , and un to the original nonlinear Eq. (11.1), which we refer
to as the nominal solution. The coefficients A , B, C , and D are the Jacobian matrices evaluated
on the nominal solution:

f  f 
A    , B    ,
x n u n
(11.3)
h  h 
C    , D   
x  n u  n

where the Jacobian g  t for a vector of functions


198 Control System Professional

 g t , t , …, t 
 1 1 2 n

 g2 t1 , t2 , …, tn 

gt  

 

 gm t1 , t2 , …, tn 

in variables t1 , t2 , …, tn is

  g1  g1  g1


    
 t1 t2 tn

  g2  g2  g2
g     
   t1 t2 tn

t 

    


  gm  gm  gm
    
 t1 t2 tn

The function Linearize attempts to find such an approximation.

Linearize f , x, xn , u, un 


find a linearized state-space 
approximation to the function  f in the 
state  variable x and input  variable u in 
the vicinity of the operating point xn , un

Linearize f , x1 , x1n , x2 , x2n , …, u1 , u1n , u2 , u2n , …
find a linearized state-space approximation 
to a  vector of functions  f in the state 
variables xi  and input variables ui 
in the vicinity of the operating point xi n , ui n

Linearize f , h, x1 , x1n , x2 , x2n , …, u1 , u1n , u2 , u2n , …
find a linearized state-space 
approximation to the  vectors f and h
Local linearization.

Linearize accepts one or both of the function vectors f and h and returns, respectively, the
short (containing just matrices A and B ) or full (containing all four matrices) state-space
description. Desired options for the resulting state-space object may be supplied to Linear
ize or inserted later.

As an example, we consider the linearization of the one-dimensional magnetic ball suspension


11. Nonlinear Control Systems 199

system shown in Figure 11.1 (after Kuo (1991)). The system attempts to control the vertical
position lt of the steel ball through input voltage et. The state variables are chosen as

x1 t  lt , x2 t  lt , and x3 t  it. The only input variable is ut  et .

i

R L
e

Electromagnet
2
_i
l
l

Steel ball

Mg

Figure 11.1. Magnetic ball levitation system.

Load the application.

In[1]:=  ControlSystems`

This is vector f corresponding to the nonlinear state equation x  fx, u .

x32 R x3 e
In[2]:= f  x2, g   ,     
M x1 L L
x32 e R x3
Out[2]= x2, g   ,    
M x1 L L

The output vector contains a single variable. Linearize does not require additional
list wrapping in such a case.
In[3]:= h  x1

Out[3]= x1
200 Control System Professional

This linearizes the state equation near some nominal point with the coordinates x10,
x20, x30, and e0. Since only one vector (f) is supplied, the resulting state-space
object contains only two matrices, A and B .
In[4]:= ball  Linearizef, x1, x10, x2, x20, x3, x30, e, e0

 0 1 0 0 
 
 x302 
 2 x30 

Out[4]=  
2 0   0 
 M x10 M x10 
 
 R 1 
0 0    
L L •

This finds the full (four-matrix) state-space description.

In[5]:= Linearizef, h , x1, x10, x2, x20, x3, x30, e, e0

 0 1 0 0 
 
 x302 
 2 x30 
 2
 0   0 
Out[5]=  M x10
M x10 


 R 1 
 0 0    
 L L 
 
1 0 0 0 •

As soon as the linearized state-space model is found, we may apply other Control
System Professional functions. For this experiment, let the nominal point be the
equilibrium position of the ball at some coordinate l0.

In[6]:= x10  l0, x20  0, x30  M g l0 

Out[6]= x10  l0, x20  0, x30  


g l0M 

This is the state-space description near the equilibrium.

In[7]:= ball  ball . %

0 
 
0 1 0

  
 g 2 g l0 M 
  0   0 
Out[7]=  
 l0 l0 M 
 1 
 R
 0 0    
L L •
11. Nonlinear Control Systems 201

We now find the state feedback gain matrix that places the poles of the system into
some position p1, p2, p3.
In[8]:= StateFeedbackGainsball, p1, p2, p3

L M g p1l0 p2 p3 p1g p2g p3 L M gl0 p1 p2l0 p1 p3l0 p2 p3


Out[8]=  


2 g l0 M
   


2 g l0 M
  L p1  L p2  L p3  R 

This is the system after the feedback loop is closed.

In[9]:= StateFeedbackConnectball, %  Simplify

 0 1 0 0 
 
 
 g 2g 
  0  
 
0 
Out[9]=  l0 g l0 M 

 
 M l0 p1 p2 p3  g p1  p2  p3 M g  l0 p2 p3  p1 p2  p3 1 

  

 



 
    
 
L 
 p1 p2 p3
2 g l0 M 2 g l0 M •

This is the closed-loop system for a particular set of numerical parameters after
dropping insignificant numerical errors.
10
In[10]:= % . l0  .1, M   , L  10., R  100, g  9.8, p1  1, p2  1  , p3  1  
103
Chop

0 
 
0 1 0


Out[10]=  98. 0 197.99 0 
 
1.49503 0.515178 3 0.1 •

Let us investigate the dynamics of the state variables. One way to do this is to insert
an identity matrix as matrix C into the previous (short) state-space object to feed all
states through to the outputs. The matrix can be directly inserted at the last position
in the state-space object.
In[11]:= % StandardForm

Out[11]//StandardForm=
StateSpace
0, 1, 0, 98., 0, 197.99, 1.49503, 0.515178, 3, 0, 0, 0.1
202 Control System Professional

In[12]:= Insert% , IdentityMatrix3, 1

0 
 
0 1 0

 98. 197.99 0 
 0
 
 1.49503 0.515178 3 0.1 
Out[12]=  
 1 0 0 0 
 
 0 1 0 0 
 
0 0 1 0 •

This gives the state response to a step function, that is, it shows how the state
variables change if the input voltage applied to the electromagnet suddenly changes
by some value (10 mV in the plot). The coordinate and velocity of the ball are
shown as a solid and dashed line, respectively, and the current in the magnet is
shown as the dashed-dotted line.
In[13]:= SimulationPlot% , .01, t, 5, Sampled  Period .1, PlotStyle 
Thickness.001, Dashing .04, .02, Dashing .05, .01, .01, .01,
PlotLabel  "Step Response";

Step Response
0.1

0.08

0.06

0.04

0.02

1 2 3 4 5

 11.2 Rational Polynomial Approximations


Another approach to obtaining the linear time-invariant (LTI) approximation to a nonlinear
system involves the approximation of a nonlinear transfer function by a polynomial ratio.
Corresponding functions are provided with standard Mathematica packages and represent
Padé, economized rational, general rational, and minimax approximations. The first two are in
the context Calculus`Pade` , and the others are in NumericalMath`Approxima-
tions`. Note that the built-in function InterpolatingPolynomial may be useful for
some approximations, too.
11. Nonlinear Control Systems 203

Here is the transfer function describing some ideal heat exchanger.


1
In[14]:= h  


10 s  1
50 s  1
1
Out[14]= 

1  10 s
1  50 s

The temperature sensor for the exchanger is located so that its reading is delayed a
few seconds, which introduces the delay term.
In[15]:= delay  Expa s

Out[15]= a s

This loads the necessary package.

In[16]:= Needs"Calculus`Pade`"

We use the Padé approximation to represent the delay as a polynomial ratio of the
order 2  2.
In[17]:= Padedelay, s, 0, 2, 2
2 2
1  
as
 
a s
Out[17]= 
2 
12 
1  
as
2
 
a2 s 2
12

This generates an object suitable for analysis with Control System Professional.

In[18]:= TransferFunction s, % h 


  
a  2 2
a

     1
Out[18]=  


 
12 2
 10   1 50   1   a2  2 a 
12
   2
  1 
12. Miscellaneous

This chapter covers several mathematical and utility functions. The functions SchurDecompo
sitionOrdered, LyapunovSolve, Rank, and DisplayTogetherGraphicsArray are
included with Control System Professional but are useful well outside its scope. Other utility
functions provide the means to determine the structure of systems (CountInputs, CountOut
puts, and CountStates) and to check on the structural consistency (ConsistentQ). Also
described is the function to create systems with random elements (RandomSystem).

 12.1 Ordered Schur Decomposition


The function SchurDecompositionOrdered is an extension to the built-in function Schur
Decomposition; it shares the same syntax and accepts the same options, with certain addi-
tions and exceptions.

Similar to the Schur decomposition of matrix m , the ordered Schur decomposition finds a
unitary matrix q and triangular matrix t, such that q t qH gives m , where H denotes Hermi-
tian transpose, with matrix t being such that the eigenvalues of m appear on the main diago-
nal of t . In addition, the ordered Schur decomposition makes the eigenvalues appear on the
diagonal in the prescribed order. The guidelines for selecting the ordering function in Schur
DecompositionOrdered are the same as those for the built-in function Sort.

SchurDecompositionOrderedm
find the Schur decomposition in 
which eigenvalues of matrix m appear 
on the diagonal in canonical order

SchurDecompositionOrderedm, pred
use the function pred to determine 
whether pairs of eigenvalues are in order
Ordered Schur decomposition.

 Load the application.

In[1]:=  ControlSystems`
12. Miscellaneous 205

 Here is a 3 3 matrix with random elements.

In[2]:= m  TableRandom, 3, 3

0.786599 0.848339 0.612827 


 
 0.398038 0.238012 0.517232 
Out[2]=  
 
 0.238887 0.194399 0.893263 

 This finds its Schur decomposition using the built-in Mathematica function.

In[3]:= q , t  SchurDecomposition  m;

 The eigenvalues on the main diagonal do not follow any particular order.

In[4]:= t

 1.5415 0.425219 0.422634 


 
Out[4]=  0. 0.12446 0.295623 
 
 0. 0. 0.500837 

 This finds the ordered Schur decomposition of the same matrix.

In[5]:= qo, to  SchurDecompositionOrdered  m;

 Now the diagonal elements appear in canonical order.

In[6]:= to  Chop

 0.12446 0.343931 0.309219 


 
Out[6]=  0
 0.500837 0.482617 
 
 0 0 1.5415 

 The decomposition is still valid.

In[7]:= qo.to.ConjugateTransposeqo  m  Chop

 0 0 0 
 
Out[7]=  0 0 0 
 
 0 0 0

 This is the ordered Schur decomposition in which the eigenvalues residing in the
right half of the complex plane go first.
In[8]:= qo, to  SchurDecompositionOrdered  m, Re#  0 &;
206 Control System Professional

 This is the corresponding matrix t.

In[9]:= to  Chop

1.5415 0.563829 0.203783 


 
Out[9]=
 0
 0.500837 0.295623 
 
0 0 0.12446 

 This sorts the eigenvalues in descending order of their real parts. For this particular
matrix m, the result is the same as the previous one.
In[10]:= qo, to  SchurDecompositionOrdered  m, Re#2  Re#1 &;

In[11]:= to  Chop

 1.5415 0.563829 0.203783 


 
Out[11]=  0 0.500837 0.295623 
 
0 0 0.12446 

The function SchurDecompositionOrdered accepts the option Pivoting, just as SchurDe


composition does. However, the option RealBlockForm in SchurDecompositionOr 
dered accepts only the default value False.

option name default value

RealBlockForm False whether complex eigenvalues


of the real input matrix should
be returned as real blocks

Option value specific to SchurDecompositionOrdered.

 12.2 Lyapunov Equations


The function LyapunovSolve attempts to find the solution X to the Lyapunov equation

XA  BX  C (12.1)


a special class of linear matrix equations that occurs in many branches of control theory, such
as stability analysis, optimal control, and response of a linear system to white noise (see, e.g.,
Brogan (1991)). Typically, A and B are square matrices with dimensions m  m and n  n . To be
consistent, matrices C and X should have dimensions n  m . An important particular case of
the Lyapunov equation,
12. Miscellaneous 207

XA  AT X  C (12.2)

involves only matrices A and C , in which case all matrices are square with the same dimen-
sions.

For discrete-time systems, the discrete Lyapunov equation

X  AXAT  C (12.3)

arises. The solution can be found with DiscreteLyapunovSolve.

LyapunovSolvea, c solve the matrix Lyapunov equation x.a 


Transposea.x  c for matrix x
LyapunovSolvea, b, c solve the Lyapunov equation x.a  b.x  c

DiscreteLyapunovSolvea, c
solve the discrete Lyapunov equation x 
a.x.Transposea  c
Functions for solving Lyapunov equations.

 Here is matrix a.

  1
1
In[12]:= a  

 2


;
 1 1

 Here is matrix c.
q1 0
In[13]:= c  ;
0 q2

 This solves the discrete Lyapunov equation and simplifies the result.

In[14]:= DiscreteLyapunovSolvea, c  Simplify

 2 q1  
3 q2
 q1    
5 q2
 2 4 
Out[14]=  19 q2  
 q1  4 2  
 
5 q2 3 q1
8 

 We may verify that the solution indeed satisfies the discrete Lyapunov equation.

In[15]:= a.% .Transposea  c  %  Simplify

Out[15]= True
208 Control System Professional

Consider now an example of design of a feedback controller that uses Lyapunov's method to
approximate the minimum-time response system for a given system (see Brogan (1991),
Section 10.8). The method is applicable to systems stable at least in Lyapunov's sense. To find
the Lyapunov function V x
 xT Px, we will first solve the Lyapunov equation,
ATP  PA  Q , where Q is the identity matrix with proper dimensions. Knowing V x
, one

  xTPx  xT x  2uTBT Px. To make V x
as negative as possible, and
can find V x
 x T Px
thereby obtain the fastest response, we will compute the input signal as

BT Px t

u  

BTPx t

 These are matrices A and B for a state-space system, which we assume to be


continuous-time.
3 2
In[16]:= a  ;
1 1

1 1
In[17]:= b  ;
0 1

 This solves the Lyapunov equation. The matrix Q is assumed to be the identity
matrix 2  2.
In[18]:= p  LyapunovSolvea, IdentityMatrix2

    


7 1
 40 
Out[18]=  
40
 1 9 
    
 40 20 

 This computes the control law.

In[19]:= bpx  Transposeb.p.x1, x2;

bpx
In[20]:= u     Simplify

bpx.bpx

7 x1  x2 8 x1  19 x2
Out[20]=  

 

 
2
, 

 

  
113 x1  318 x1 x2  362 x2
2
113 x1  318 x1 x2  362 x22
2

Despite the fact that our system is linear, the minimum time response control is not.
12. Miscellaneous 209

 This plot shows the first control signal as a function of the state variables.

In[21]:= Plot3Du1, x1, 2, 2, x2, 2, 2, PlotPoints  40, Boxed  False,
AxesLabel  "x1 ", "x2 ", "u1 ", ViewPoint  3.076, 0.000, 1.080,
PlotLabel  "Minimum time response control";

Minimum time response control


-2
-1
x1 0
1
2 1
0.5
0 u1
-0.5
-
-
-1
-2 -1 0 1 2
x2

 This is the second component of the control signal.

In[22]:= Plot3Du2, x1, 2, 2, x2, 2, 2, PlotPoints  40, Boxed  False,
AxesLabel  "x1 ", "x2 ", "u2 ", ViewPoint  2.141, 2.209, 1.080,
PlotLabel  "Minimum time response control";

Minimum time response control

1
0.5
0 u
2
-0.5
-2 -1
-2
-1 -1
0 0
x2 1 1 x1
2

LyapunovSolve and DiscreteLyapunovSolve use the direct method (via the built-in
function Solve) or the eigenvalue decomposition method. The method is set using the option
SolveMethod, which correspondingly accepts the values DirectSolve and Eigendecompo
sition. If this option's value is Automatic, these methods are tried in turn until one suc-
ceeds or all are tried.
210 Control System Professional

option name default value

SolveMethod Automatic method to solve the equation

Option specific to Lyapunov equation solvers.

 12.3 Rank of Matrix

Rankm find the rank of matrix m

Determining the rank of matrix.

For inexact numerical matrices m, Rank counts the nonzero singular values, as obtained
through the built-in function SingularValues. For exact and symbolic matrices, the differ-
ence between the number of columns of m and the length of the null space, as obtained
through NullSpace, is used to determine the rank. Correspondingly, Rank accepts the
options pertinent to SingularValues or NullSpace and passes them along to these func-
tions.

 12.4 Part Count and Consistency Check


CountInputs, CountOutputs, and CountStates can be used to determine the number of
inputs, outputs, or states of the system. They are useful in cases when systems change as the
result of structural operations (say, merging or connecting with others). Alternatively, for a
system entered manually, you may wish to check that no mistakes have been made and that
the matrices you entered can really represent a system. The following functions help with
these chores.

CountInputssystem find the number of inputs of system


CountOutputssystem find the number of outputs of system
CountStatessystem find the number of states of system
ConsistentQsystem determine if the elements of system 
have dimensions consistent with each other

Checking on the system parameters.


12. Miscellaneous 211

 12.5 Displaying Graphics Array Objects Together


The function DisplayTogetherGraphicsArray displays multiple GraphicsArray
objects as one such object and is similar to the function DisplayTogether from the standard
package Graphics`Graphics` . Input arguments can be either GraphicsArray objects or
any other Mathematica commands that result in such objects (e.g., BodePlot). The function
also accepts options pertinent to GraphicsArray. All input GraphicsArray objects must
have the same dimensions.

DisplayTogetherGraphicsArrayarray1 , array2 , …, opts


combine the graphics arrays 
arrayi in a GraphicsArray object

Displaying GraphicsArray objects together.

 12.6 Systems with Random Elements


Random yet stable (at least in the sense of Lyapunov) systems can be generated using the
function RandomSystem in conjunction with the desired system type—StateSpace, Trans
ferFunction, or ZeroPoleGain. RandomSystem[args] is used in place of the actual
system contents. Systems with random parameters could be useful for numerical experiments,
checking the design concepts, etc.

typeRandomSystemargs create a random system of type type

typevar, RandomSystemargs
use the  variable var in the body of 
the random transfer function system
RandomSystem random first-order single-input,
single-output SISO
system
RandomSystemn nth-order SISO system
RandomSystemn, i, o nth-order system with i inputs and o outputs
Generating a system with random elements.
212 Control System Professional

 This creates a random first-order transfer function in variable s.

In[23]:= TransferFunction s, RandomSystem

0.400733 
Out[23]=  
  2.40162

 This is a second-order single-input, two-output state-space system.

In[24]:= StateSpaceRandomSystem2, 1, 2

 1.93888 0.00387746 1.82357 


 
 0.344929 2.59669
 3.01261 
Out[24]=   
 3.76923
 0.228547 3.05476 

 3.05821 3.55686 4.87885 •

RandomSystem works by creating random matrices of zeros, poles, and gains (for transfer
function systems) or by creating a block diagonal matrix with suitable eigenvalues and then
performing linear transformation on that matrix to form matrix A (for state-space systems).
Almost all of the following options listed below (with the exception of Exact) accept either
one value (to be applied to both numerators and denominators or to the eigenvalues) or a list
of two values to create the numerators and denominators according to different rules.
12. Miscellaneous 213

option name default value

Exact False whether to generate an


infinite-precision system
ComplexRootProbability 0.33,0.5 probability of complex roots
RealRootProbability 0.33,Automatic probability of
real-valued roots
SpecialPoints Automatic special point locations
SpecialPointProbability 0.05,0.1 probability of special points
MultipleRootProbability 0.1,0.2 probability of multiple roots
ImaginaryToRealRatio Automatic mean imaginaryreal
ratio for complex roots
MappingFunction Automatic function s
to map
over random roots
ExactConversionFunction Automatic additional function s
to
map over roots to create
an infinite-precision system

Options to RandomSystem.

If RealRootProbability is set to Automatic, then all available root positions that remain
after the creation of complex roots and special points will be filled with real roots. This is
usually what you want in the denominator of a transfer function to ensure that the system
has the required order, but this is not necessarily the case for the numerators. Setting Real
RootProbability
Automatic will generate a strictly proper transfer function.

The option SpecialPoints allows the location(s) of some special roots to be specified (to
create an integrator, for example). The probability of such points in numerators and denomina-
tors is set by the option SpecialPointProbability.
References

Brogan, William L. Modern Control Theory, 3rd ed. Englewood Cliffs, NJ: Prentice Hall, 1991.

Dorf, Richard C. Modern Control Systems, Reading, MA: Addison-Wesley, 1992.

Franklin, Gene F., J. David Powell, and Abbas Emami-Naeini. Feedback Control of Dynamic
Systems, 2nd ed. Reading, MA: Addison-Wesley, 1991.

Franklin, Gene F, J. David Powell, and Michael L. Workman. Digital Control of Dynamic Systems,
2nd ed. Reading, MA: Addison-Wesley, 1990.

Gopal, M. Modern Control System Theory, 2nd ed. New York, NY: John Wiley & Sons, 1993.

Kailath, Thomas. Linear Systems, Englewood Cliffs, NJ: Prentice Hall, 1980.

Kautsky, J., N. K. Nichols, and P. Van Dooren. Robust pole assignment in linear state feed-
back. International Journal of Control, 41, no. 5, 1985, pp. 1129–1155.

Kuo, Benjamin C. Automatic Control Systems, 6th ed. Englewood Cliffs, NJ: Prentice Hall, 1991.

Laub, Alan J. A Schur method for solving algebraic Riccati equations. IEEE Transactions on
Automatic Control, AC-24, Dec. 1979, pp. 913–921.

Levine, William S. The Control Handbook, Boca Raton, FL: CRC Press, 1996.

Moore, Bruce C. Principal component analysis in linear systems: Controllability, observability,


and model reduction. IEEE Transactions on Automatic Control, AC-26, Feb. 1981, pp. 17–32.

Ogata, Katsuhiko. Modern Control Engineering, Englewood Cliffs, NJ: Prentice Hall, 1990.
Index

1  f noise, 182 All, in DeleteSubsystem, 115


in Subsystem, 115
Ackermann, 152, 155 Amplifiers, 112
robustness of solutions, 159 Analog simulation, 65
Ackermann's formula, 17 Analog systems, 33
Ackermann, 154 Analog-to-digital converters, 44
Active wrappers, 3, 32 Analytic, 92
Actuators, 25, 175 Angle of attack, of submarine, 72
A/D conversion, 44 Antenna example, 182
Admissible controls, 165 discrete estimator for, 185
Admissible error, AdmissibleError, 152 Kalman filter for, 188
Admissible trajectories, 165 ARE, 172
AdmissibleError, 152 Attitude control, of satellite, 151
Ailerons, 156 of spacecraft, 95
effectiveness of, 175 Azimuth control, of antenna, 182
of a missile, 175
roll-time constant of, 175 Backward rectangular rule, Backward
Aircraft example, 156 RectangularRule, 48
Algebraic Riccati equation, 172 BackwardRectangularRule, 48
discrete, 173 Bilinear transformation,
BilinearTransform, 48
BilinearTransform, 48, 55
216 Control System Professional

Block diagrams, 98 Complex numbers, notation for, 9


Bode plot, BodePlot, 85 Complex plane, s- vs. z-plane, 4
BodePlot, 50, 85 ComplexRootProbability, 213
collecting several plots in one, 144 ComplexVariables, 38, 131
displaying several objects together, 211 Composite systems, 98
gain and phase margins in, 89 Concentration control, 167
phase unwrapping in, 87 Condition number, of controllability matrix,
Bridged-T network, 66 155
Consistency check, ConsistentQ, 210
Calculus`Pade`, 202 ConsistentQ, 38, 210
Canonical forms, controllable, 140 Continuous-time systems, 33, 39, 54
controllable companion, 36 Continuous-time to discrete-time conversion,
Jordan, 138 4, 44
Kalman controllable, 136 Continuous-time vs. discrete-time systems,
Kalman observable, 136 39
modal, 138 ContinuousTimeQ, 40
observable companion, 36 Control design, optimal, 165
Cascade compensation, 119 using pole assignment, 150
Cascade connection, SeriesConnect, 98 Control effort, 165
Center of gravity, of pendulum, 12 Control Format palette, 7
Center of mass, of satellite, 151 Control input, selection in single-input
Characteristic equation, 80 algorithms, ControlInput, 155
Characteristic polynomial, 154, 179 Control inputs, for time-domain response,
Chemical mixture, control of, 167 ControlInputs, 60
Classical control, 80 Control matrix, 34
Closed loop, construction of, 105 Control objects, 3
Companion realizations, controllable, 36 constructing from ODEs, 16
observable, 36 continuous-time vs. discrete-time, 4, 33, 39
Compensator, 95 converting between, 4, 31–32, 35
Complex exponentials, reducing to default domain of, 39
trigonometric functions, 62 domain identification of, 4, 32, 39, 45
traditional notations for, 41
ControlInput, 155
ControlInputs, 60
Controllability, 122
Index 217

Controllability Gramian, 140, 142 CountOutputs, 210


ControllabilityGramian, 124, 128 CountStates, 210
Controllability matrix, 136, 154 Covariance matrix, 181
ControllabilityMatrix, 124, 126 CriticalFrequency, 48
Controllability test, Controllable, 122 Critically damped, 74
ControllabilityGramian, 129 Cross-covariance matrix, 181
ControllabilityMatrix, 126 Crossover frequency, 91
ControllabilityTest, 124 Current estimator, 192
Controllable, 122, 134
Controllable canonical form, 140 D/A conversion, 54
Controllable companion realization, Damping ratio, 74, 82, 88, 179
ControllableCompanion, 36 of dominant poles, 81
Controllable states, 136 of third-order system, 76
Controllable subspace, size of, DARE, 173
ControllableSpaceSize, 125 DecompositionMethod, in
ControllableCompanion, 36 InternallyBalancedForm, 141
ControllableSpaceSize, 125 in KalmanControllableForm, 137
ControllableSubsystem, 132–133 in KalmanObservableForm, 137
vs. KalmanControllableForm, 138 DefaultInputPort, 113
Controlled signal, 81 Deflection, of ailerons, 175
Controller, current, 192 Deflection rate, of ailerons, 175
design of, 119, 150 Delay, 53
in output feedback, 105 in heat exchanger, 203
in state feedback, 114 Padé approximation of, 203
optimal, 192 DeleteSubsystem, 98, 115–116
Controller, 192 Depth control, of submarine, 72
Controller design, 15 Derivative controller, 119
Correlation, between process and Determinant expansion formula,
measurement noises, 181 DeterminantExpansion, 33
Cost function, 165, 171 DeterminantExpansion, 33
equivalent, 178, 184 Deterministic, inputs, 182, 185, 187, 193
quadratic, 166 state reconstruction, 181
CountInputs, 210
218 Control System Professional

Differential equations, StateSpace model Economized rational approximation, 202


from, 15 Effectiveness, of ailerons, 175
Digital systems, 34 Eigendecomposition, as value of
Digital-to-analog converters, 54 SolveMethod, 209
Dirac delta function, approximating in Eigensystem, as value of
analog simulation, 79 DecompositionMethod, 141
DiracDelta, in impulse response Eigenvalues, and poles, 17, 150, 179
simulation, 70, 78 in SchurDecomposition, 204
DiracDelta, in impulse response multiple, 139, 177
simulation, 70, 78 of closed-loop system, 17, 150
Direct transmission matrix, 34 of Hamiltonian matrix, 177
DirectSolve, as value of SolveMethod, specifying order of, 204
209 Eigenvectors, 147
Discrete emulation of continuous design, 178, Electrical Engineering Examples, plotting
184 routines from, 80
Discrete simulation, 65 Emulation, of continuous design, 178, 184
Discrete-time systems, 34, 39, 44 EquationForm, 6, 43
Discrete-time to continuous-time conversion, Equilibrium, of magnetic ball, 200
4 of pendulum, 15
DiscreteDelta, in impulse response Equivalent cost, 178, 184
simulation, 169 Error signal, 81
DiscreteLQRegulatorGains, 178, 184 Estimator, 161
DiscreteLyapunovSolve, 129, 207 current, 192
DiscreteRiccatiSolve, 171, 173 discrete by emulation of continuous, 184
DiscreteTimeQ, 40 gain matrix for, EstimatorGains, 161
Displacement, of pendulum, 12 Kalman, 182, 185
DisplayTogether, vs. optimal, 181
DisplayTogetherGraphicsArray, predictor, 192
211 EstimatorGains, 162
DisplayTogetherGraphicsArray, 52, Evolution matrix, 34
144, 211 Exact, 213
Domain identification of control objects, 4, 39 ExactConversionFunction, 213
Dominant subsystem, Expanding transfer functions,
DominantSubsystem, 142 ExpandRational, 28
DominantSubsystem, 132–133, 142
Double integrator, 80, 151
PID controller for, 120
Dryden Flight Research Center, 156
Dual systems, DualSystem, 130
DualSystem, 130, 135
Dynamic systems, 27
Index 219

ExpandRational, 28
Gain band, 96
F-8 aircraft example, 156 Gain margin, GainPhaseMargins, 89
Factoring transfer functions, GainPhaseMargins, 89
FactorRational, 28 Gaussian distribution, 182, 192
FactorRational, 28, 145 NormalDistribution, 191
pole-zero cancellation in, 145 Gaussian noise, 188
Feed-forward path, 112 General rational approximation, 202
Feedback, negative, 105 GenericConnect, 98, 110
path, 112 Gramian, 124, 128
positive, 105 GraphicsArray, displaying several objects
Feedback connection, FeedbackConnect, together, 211
105
Feedback controller design, 15, 150, 201 Hamiltonian matrix, 177
using Lyapunov's method, 208 Heat exchanger example, 203
Feedback loop, forming with Hold equivalence methods, 48
FeedbackConnect, 105 Homogeneous response, 57
FeedbackConnect, 83, 98, 105, 191 Horizon, infinite, 166
Feedthrough matrix, 34
First-order hold, FirstOrderHold, 48 Imaginary unit, notation for, 9
First-order lag, 94 ImaginaryToRealRatio, 213
FirstOrderHold, 48, 56 Impulse response, 74
Flicker noise, 182 simulating with DiracDelta, 70
Flight control example, 156 simulating with DiscreteDelta, 169
Forced response, 57 simulation of, 70
Forward rectangular rule, Infinite-horizon problem, 166, 182
ForwardRectangularRule, 48 Infinite-time-to-go problem, 166
ForwardRectangularRule, 48 Inflow control, 167
Frames, 84 Inflow rate, 167
Free response, 57 Initial conditions, InitialConditions, 60
Frequency prewarping, InitialConditions, 19, 60
CriticalFrequency, 48, 55
Frequency response, 85, 93, 95–96
FullRankControllabilityMatrix, 125
FullRankObservabilityMatrix, 125
220 Control System Professional

Input matrix, 34 Kalman decomposition, Kalman, 135


Inputs, count of, 210 Kalman estimator, 182
deterministic, 182, 185, 193 KalmanEstimator, 185
stochastic, 182, 187 Kalman filter, 182, 185
InputVariables, 43 example of, 188
Installation, 1 Kalman gain matrix, 184
Integral controller, 119 KalmanControllableForm, 132, 136, 149
Integrator, 4, 80, 101 KalmanEstimator, 182, 185
Interconnections, 98 KalmanObservableForm, 136
arbitrary, 110 Kautsky-Nichols-Van Dooren algorithm,
elementary, 98 KNVD, 158
Internally balanced realizations, KNVD, 152, 158
InternallyBalancedForm, 140
InternallyBalancedForm, 140 Lag system, 49, 52, 94
InterpolatingFunction, in time-domain Laplace transform, LaplaceTransform, 44
simulations, 65 LaplaceTransform, 44
InterpolatingPolynomial, 202 Levitation system example, 199
Interpolation, as value of Linear quadratic Gaussian problem, 182
GainPhaseMargins, 92 Linear quadratic regulator, 17
Inventory control, 60 LQRegulatorGains, 166
Inventory level, control of, 60 Linearization, 16, 197
Inverted pendulum example, 11, 163 Linearize, 197
controller for, 15 Linearize, 16, 198
optimal controller for, 17 LinearSpacing, 87
InvertedTransformMatrix, 147 LogSpacing, 87
Irreducible realization, LQ regulator, 17
MinimalRealization, 133 LQEstimatorGains, 182, 184, 192
LQG controller, Controller, 192
Jacobian matrix, 197 LQG problem, LQEstimatorGains, 182
Jordan canonical form, LQOutputRegulatorGains, 171
JordanCanonicalForm, 138 LQRegulatorGains, 17–18, 167, 174, 177,
JordanCanonicalForm, 138 179, 182, 192

Kalman, 135
Kalman canonical forms, 136
Index 221

vs. DiscreteLQRegulatorGains, 180 controllability Gramian of, 129


vs. LQOutputRegulatorGains, 172 LQ regulator for, 168
LTI systems, 27, 202 output regulator for, 172
Lyapunov equations, 206 singular value plot for, 97
continuous, 206 Modal realization, JordanCanonicalForm,
discrete, 207 138
for controllability and observability Model reduction, DominantSubsystem, 142
Gramians, 129 MinimalRealization, 133
Lyapunov function, 208 PoleZeroCancel, 144
LyapunovSolve, 129, 206 Modern control, 27
Moment of inertia, of pendulum, 12
Magnetic ball suspension example, 199 Monic polynomial, 121
Magnitude response, 85 Most likelihood, 182
MappingFunction, 213 Multiple-input, multiple-output (MIMO)
Margins, 87 systems, 28
MarginStyle, 87, 89 minimal realization of, 133
MaxIterations, in MultipleRootProbability, 213
StateFeedbackGains, 159 Multivariable control, 28
Measurement noise, 181, 191–192
MergeSystems, 98, 117 NASA, Dryden Flight Research Center, 156
Method, in Rank, 210 Natural frequency, 74, 82, 179
in StateFeedbackGains, 151 of third-order system, 76
in ToContinuousTime, 54 Natural response, 57
in ToDiscreteTime, 48 NDSolve, in time-domain simulations, 65
MIMO systems, 28 Negative, in FeedbackConnect, 107
frequency response of, 96 in GenericConnect, 111
Minimal realization, Negative feedback, 105
MinimalRealization, 133 Nichols plot, NicholsPlot, 95
MinimalRealization, 38, 132–133 NicholsPlot, 95
Minimax approximation, 202 Noise, 1  f , 182
Minimum-time response, 208 additive, 188
Missile example, 175 covariance matrix of, 181, 184
Mixing tank example, 167
222 Control System Professional

Gaussian, 182 Observability, 122


high-frequency cutoff of, 182 Observability Gramian, 140, 142
measurement, 181 ObservabilityGramian, 124, 128
process, 181 Observability matrix, 136
spectrum of, 181 ObservabilityMatrix, 124, 126
stationary, 182 Observability test, Observable, 122
white, 181 ObservabilityGramian, 129
Nominal solution, 197 ObservabilityMatrix, 126
None, in DeleteSubsystem, 115 ObservabilityTest, 124
in Subsystem, 115 Observable, 122, 134
Nonlinear state-space models, 15 Observable canonical form, 36
linearization of, 16, 197 Observable companion realization,
simulation of, 21 ObservableCompanion, 36
Nonlinear systems, 197 Observable states, 136
local linearization of, 197 Observable subspace, size of,
rational polynomial approximations for, 202 ObservableSpaceSize, 125
Nonpolynomial transfer functions, 94 ObservableCompanion, 36
NonSingularControllabilityGramian, ObservableSpaceSize, 125
125 ObservableSubsystem, 133
NonSingularObservabilityGramian, vs. KalmanObservableForm, 138
125 Observation matrix, 34
Normal distribution, 182 Observer, 161
NormalDistribution, in simulations, 191 Kalman, 182
NullSpace, as value of optimal, 181
DecompositionMethod, 137 Optimal control, 165
in Rank, 210 Optimal controller, 192
Numerical errors, control of, 152 Optimal estimation, 181
Numerical integration methods, 48 Ordered Schur decomposition,
NumericalMath`Approximations`, 202 SchurDecompositionOrdered, 204
Nyquist frequency, 51 Orthogonal basis, 137, 159
Nyquist plot, NyquistPlot, 93 reconstruction of, 130
NyquistPlot, 93 Orthogonal complement, 130, 137, 159
OrthogonalTransformMatrix, 148–149
Index 223

Outflow control, 167 of a missile, 175


Outflow rate, 167 Period, 40
Output controllability matrix, Phase band, 96
OutputControllabilityMatrix, 126 Phase margin, GainPhaseMargins, 89
Output matrix, 34 Phase response, 85
Output regulator, optimal, Phase unwrapping, adjusting PlotPoints
LQOutputRegulatorGains, 171 for, 144
Output response, OutputResponse, 57 PhaseRange, 87
OutputControllabilityMatrix, 126 PhaseRange, 87, 92, 96
OutputControllable, 122 PID controller, 95, 119
OutputResponse, 19, 57–58 Pivoting, in
dummy variable in, 60 SchurDecompositionOrdered, 206
initial conditions in, 19, 60 Plant, 27
number of input signals in, 60, 65 PlotPoints, 81, 84, 87, 93, 95–96, 144
polling inputs in, 60 PlotSampling, 87, 95–96
simulations with, 65 Pole assignment, 17
symbolic solution, 57 controlling numerical errors in, 152
Outputs, count of, 210 robust, 158
OutputVariables, 43 StateFeedbackGains, 150
Overdamped response, 75 using Ackermann's formula, 154
Overshoot, 83 Pole placement, 17
StateFeedbackGains, 150
Padé approximation, 202 Pole-zero cancellation, PoleZeroCancel,
Parallel connection, ParallelConnect, 103 144
ParallelConnect, 98, 103, 110, 190 Poles, 18, 150
for adding inputs to system, 189 multiple, 213
Particular response, 57 of closed-loop system, 17
Penalty function, 165 of transfer function, Poles, 32
Pendulum, inverted, 11, 163 of transfer function, ZeroPoleGain, 30
Performance criterion, 165 Poles, 32
of a missile, 175 PoleStyle, 81
Performance index, 165 PoleZeroCancel, 133, 144
Polynomial approximations, 202
224 Control System Professional

Positive, in FeedbackConnect, 107, 191 RealRootProbability, 213


in GenericConnect, 111 Reduced-order model, 133, 140
Positive definite, 166 ReductionMethod, in
Positive feedback, 105 ControllableSpaceSize, 126
Positive semidefinite, 166 in ControllableSubsystem, 135
Predictor estimator, 192 in DominantSubsystem, 143
Prewarping, 55 in MinimalRealization, 135
CriticalFrequency, 48, 55 in ObservableSpaceSize, 126
Process noise, 181, 191–192 in ObservableSubsystem, 135
Production and inventory control model, 60 in TransferFunction, 33
Production rate, control of, 60 Reference signal, 81
Proper transfer function, state-space Regulator, linear quadratic,
realization of, 36 LQRegulatorGains, 166
Proportional controller, 119 output, 171
RejectionLevel, 142–143
QRDecomposition, as value of Resolvent matrix, 33
DecompositionMethod, 137 Response, in frequency domain, 85
Quadratic cost function, 166 in time domain, 57
minimum-time, 208
Ramp response, 77 ResponseVariable, 60
Random systems, RandomSystem, 211 Riccati equations, 18, 171–172, 182
RandomOrthogonalComplement, 130 RiccatiSolve, 171, 173
in KalmanControllableForm, 137 Robust pole assignment, KNVD, 158
in KalmanObservableForm, 137 Roll angle, 156
in StateFeedbackGains, 159 Roll attitude control, of a missile, 175
RandomSystem, 211 Roll rate, 156
Rank, of matrix, Rank, 210 Roll time constant, of ailerons, 175
Rational polynomial approximations, 202 Root loci, evolution of, 84
Rational polynomials, as RootLocusPlot, 80
TransferFunction objects, 27 RootLocusAnimation, 84
RealBlockForm, in RootLocusPlot, 80
SchurDecompositionOrdered, 206 RowReduce, as value of
Realizations, 132 DecompositionMethod, 137
converting between, 132
Index 225

Rudder, 156 SimilarityTransform, 146


SimilarityTransform, 132, 146, 149
Sampled, 4, 39 Simulation, analog, 65
Sampling, 44 discrete, 65
Sampling period, choice of, 179 SimulationPlot, 57, 69, 83, 169
SamplingPeriod, 40 plotting state response with, 72
Sampling rate, 40 Single-input, single-output (SISO) systems, 28
SamplingPeriod, 40 minimal realization of, 133
Satellite attitude control example, 151 Singular-value plot, SingularValuePlot,
controller for, 196 96
PID controller for, 119 SingularValuePlot, 96
Schur decomposition, ordered, SingularValues, as value of
SchurDecompositionOrdered, 204 DecompositionMethod, 137, 141
SchurDecomposition, as value of in Rank, 210
SolveMethod, 177 SISO systems, 28
vs. SchurDecompositionOrdered, 204 Solution, nominal, 197
SchurDecompositionOrdered, 204 SolveMethod, in
Second-order system, frequency response of, DiscreteRiccatiSolve, 177
85, 88 in RiccatiSolve, 177
impulse response of, 78 Spacecraft, attitude control of, 95
root loci of, 82 SpecialPointProbability, 213
sampling rate for, 179 SpecialPoints, 213
step response of, 74 Spectrum, of noise, 181
Separation principle, 192 Stabilizable system, 170
Serial connection, SeriesConnect, 98 Stable system, 171
Series compensation, 119 in Lyapunov's sense, 208
SeriesConnect, 82, 91, 98, 110 State equations, 33
Servo mechanism, 188 nonlinear, 15, 197
Servo motor, 183 State estimation, deterministic, 161
SetControlFormat, 7 optimal, 181
SetStandardFormat, 7 stochastic, 181
Sideslip angle, 156 State feedback, StateFeedbackConnect,
Similarity transformation, for Kalman forms, 114
136 StateFeedbackGains, 150
226 Control System Professional

State matrix, 34 state reconstruction, 181


State reconstruction, deterministic, 161, 181 system, 181, 192
optimal, 181 Strictly proper transfer function, and
stochastic, 181 RandomSystem, 213
State response, plotting with state-space realization of, 36
SimulationPlot, 72, 201 Submarine, depth control of, 72
StateResponse, 57 Subspace, controllable, 125
State trajectories, 165 observable, 125
State-space data structure, StateSpace, 33 Subsystem, 98, 115, 132
State-space models, nonlinear, 15, 197 Suspension system example, 199
State-space realizations, 132 SV plot, SingularValuePlot, 96
State-space systems, 33 System, analog, 33
StateFeedbackConnect, 19, 98, 114, 169, composite, 98
179–180, 201 continuous-time, 33
StateFeedbackGains, 17, 150, 201 digital, 34
StateResponse, 57–58 discrete-time, 34
dummy variable in, 60 dual, 130
initial conditions in, 60 dynamic, 27
number of input signals in, 60, 65 nonlinear, 197
polling inputs in, 60 random, 211
simulations with, 65 state-space realization of, 33
symbolic solution, 57 stochastic, 181
States, count of, 210 time-varying, 57
StateSpace, 3, 34
traditional notations for, 6, 41 T-bridge network, 66
with RandomSystem, 211 TargetForm, 35
StateVariables, 43 Temperature sensor, 203
Stationary noise, in wide sense, 182 Terminal state error, 165
Steady-state error, 77 Third-order system, step response of, 76
Step response, 74, 202 Time-domain response, 57
Stern plane, deflection of, 72 Time-domain simulation, 65
Stochastic, inputs, 182, 187
Index 227

Time-varying systems, response of, 57 Unobservable, states, 136


TimeVariable, 43
ToContinuousTime, 4, 54 VerifyPoles, 152
ToDiscreteTime, 4, 44, 151, 168, 174, 178,
180, 184 Weak modes, 142
Tolerance, in PoleZeroCancel, 145 Weak subsystem, 142
Torque, 183
Traditional notations, 5, 41 Yaw rate, 156
TraditionalForm, of control objects, 5, 41
Transfer function matrix, data structure for, z-transform, modified, 53
TransferFunction, 27 ZTransform, 44
Transfer matrix, data structure for, Zero-input response, 57
TransferFunction, 27 Zero-order hold, ZeroOrderHold, 48
TransferFunction, 3, 27 Zero-pole mapping, ZeroPoleMapping, 48
as a pure function object, 27 Zero-pole-gain data structure,
expanding, 28 ZeroPoleGain, 30
factoring, 28 Zero-state response, 57
nonpolynomial, 94 ZeroOrderHold, 48
traditional notations for, 5, 41 ZeroPoleGain, 3, 30
variable in, 32 variable in, 32
with RandomSystem, 211 with RandomSystem, 211
Transformation matrix, recovering of, ZeroPoleMapping, 48
TransformationMatrix, 148 Zeros, of transfer function, ZeroPoleGain,
TransformationMatrix, 148 30
Transient response, 57 of transfer function, Zeros, 32
Transient state error, 165 Zeros, 32
Transport lag, 94 ZeroStyle, 81
Triangle hold, FirstOrderHold, 48, 56 ZTransform, 44
Tustin transformation,
BilinearTransform, 48, 55 $ContinuousTimeComplexPlane
Variable, 41
Uncontrollable states, 136, 158, 171 $ContinuousTimeToken, 41
Undamped response, 75 $DiscreteTimeComplexPlaneVariable,
Underdamped response, 75 41
Unforced response, 57
228 Control System Professional

$DiscreteTimeToken , 41
$RandomOrthogonalComplement, 130
$Sampled, 39
$SamplingPeriod, 45

[Bullet] ( • ), in control objects, 41


[EmptyUpTriangle] (), in control
objects, 41
[ScriptCapitalS] (), in control objects,
41
[ScriptCapitalT] (), in control objects,
41
[ScriptK] (), in control objects, 43
[ScriptS] (), in control objects, 41
[ScriptT] (), in control objects, 43
[ScriptU] (), in control objects, 43
[ScriptX] (), in control objects, 43
[ScriptY] (), in control objects, 43
[ScriptZ] ( ), in control objects, 41

You might also like