Professional Documents
Culture Documents
June 2005
Second edition
Intended for use with Mathematica 4 or 5
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
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.
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
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).
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.
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
No special functions are needed to convert one control object to another. Simply apply
the desired head to the object you wish to convert.
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
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 1
In[6]:=
system TransferFunction s, ,
TraditionalForm
s s Α
Out[6]//TraditionalForm=
1
1
Α
Out[7]//TraditionalForm=
2
1
1 2 Α
Α 2 Α Α 2
6 Control System Professional
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.
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
In[11]:= % TraditionalForm
Out[11]//TraditionalForm=
1 Α Τ
1 Α Τ Α Τ 1
Α Α2
1 Α Τ
0 Α Τ
Α
Α
1 0
0 1 0 Τ
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).
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
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
0 1
Out[14]=
1 0 •
1. Getting Started 9
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.
In[15]:=
UnprotectComplex;
" y;
FormatComplexx_, y_ : x "
ProtectComplex;
Out[16]= 23
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
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
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.
(2.4)
fx Fx MX
2. Introduction: Extending Mathematica to Solve Control Problems 13
This is the first equation. We will keep it as eq1 for future reference.
m L2
In[4]:= J
12
L2 m
Out[4]=
12
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
Solve returns a list of rules that give generic solutions to the input equation.
We have, in fact, just a single rule and we extract it from the lists.
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 .
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
The replacement rule stored as sln helps to get rid of Θ t .
In[14]:= f % . sln
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.
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).
3 2 g m 2 g M
Out[17]= StateSpace 0, 1, , 0
,
L m 4 M
6
0,
6 g m M 6
Out[18]= StateSpace 0, 1, , 0
, 0,
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.
We see that the eigenvalues of the closed-loop system are indeed as required.
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.
0 1 0
Out[24]= 17.2941 0 0.176471
1 0 0
•
In[25]:= Q IdentityMatrix2
1 0
Out[25]=
0 1
In[26]:= R 1
Out[26]= 1
Here are the poles our system will possess when we close the loop.
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
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
In[34]:= sln
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
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
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
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.
In[42]:= ΘBig NDSolvede, Θ0 1.25, Θ 0 0, Θ, t, 0, 4, MaxSteps 1000
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.
This is the force the motor must exert to maintain the process.
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.
Here is how it works: everything beyond the interval from 1000 to 1000 gets cut
off.
In[48]:= clip 1001, 999, 999, 1001
This is the new differential equation for Θ under the saturated feedback.
In[51]:= ΘBig1 NDSolvede1, Θ0 1.25, Θ 0 0, Θ, t, 0, 4, MaxSteps 1000
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.
In[1]:= ControlSystems`
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.
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
1
Out[6]=
s
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.
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
In[9]:= FactorRational%
2 3 s
2 s
In[10]:= ExpandRational%
2 6 5 s s2
Out[10]= TransferFunctions,
,
1 s2 1 s4
1 2 s
Out[12]= TransferFunctions,
s s2
In[13]:= FactorRational%%
2 12 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.
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.
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 %
2 s
Out[16]= TransferFunctions, ,
s
s
1 s
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
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
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).
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.
TransferFunctionstatespace
find the TransferFunction object that
corresponds to the StateSpace object statespace
The straightforward, but computationally expensive, way of finding the transfer function
matrix of a state-space realization is based on the formula
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).
To distinguish between the two types of systems, the option Sampled is introduced in
Section 3.3.
ut . yt
xt xt
B C
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).
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
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.
In[26]:= StateSpace%
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 •
Out[29]//TraditionalForm=
0 a b b a
1 a b 1 1
0 1 0 0 •
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.
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
Out[31]= 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
Out[35]= False
Out[36]= False
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.
$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.
In[37]:= StateSpacea1 , a2 , a3 , a4 , b1 , b2 , c1 , c2 , Sampled True
Out[37]= StateSpacea1 , a2 , a3 , a4 , b1 , b2 , c1 , c2 , Sampled True
Out[38]//TraditionalForm=
a a b
1 2 1
a a b
3 4 2
c1 c2 0
3. Description of Dynamic Systems 43
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
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.
In[43]:= EquationForm%
Out[43]//EquationForm=
a1 a2 b1
a3 a4 b2
1 2
c c
Out[44]//EquationForm=
Θ a1 a2 Θ b1
∆
Θ a3 a4 Θ b2
Θ
c1 c2
Θ
1 a T
Out[46]= , Sampled PeriodT
TransferFunctions,
1 a T s
In[47]:= % . s z
1 a T
Out[47]= , Sampled PeriodT
TransferFunctionz,
1 a T z
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 Τ
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
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
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.
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.
a 1 s
T
Out[56]= TransferFunctions,
, Sampled PeriodT
2 a T s 2 a T
1 a T
Out[57]= , Sampled PeriodT
TransferFunctions,
a T s
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.
Magnitude dB
-2
-4
-6
-8
-10
-12
-14
0.01 0.05
0.1 0.51 5 10
Frequency RadSecond
Phase deg
-10
-20
-30
-40
0.01 0.05
0.1 0.5 1 5 10
Frequency RadSecond
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 RadSecond
Phase deg
-10
-20
-30
-40
0.01 0.05
0.1 0.5 1 5 10
Frequency RadSecond
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 RadSecond
Phase deg
-10
-20
-30
-40
0.01 0.05
0.1 0.5 1 5 10
Frequency RadSecond
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.
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.
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.
This is its discrete-time approximation when the delay equals the sampling 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[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 %
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
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
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.
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
is computed according to
k
xk Ak x0 Ak j Bj 1uj 1 (4.5)
j1
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.
In[1]:= ControlSystems`
4. Time-Domain Response 59
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.
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.
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
_ _
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 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.
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
1 1
Out[10]= UnitStep1 t 1t Cos3 1 t UnitStep1 t
10 10
1
1t Sin3 1 t UnitStep1 t
30
In[11]:= % Simplify
1
Out[11]= t 3 t 3 Cos3 3 t Sin3 3 t UnitStep1 t
30
4. Time-Domain Response 63
0.12
0.1
0.08
0.06
0.04
0.02
1 2 3 4 5 6 7
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
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.
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
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
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
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
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
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
This plots the input (the solid line) and the output (the dashed line) signals.
-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 Τ
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;
-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, % ;
-1
-2
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
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
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
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
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
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 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.
0.001
0.0005
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.
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;
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, t1
,
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
Ω2
Out[42]=
2 2 Ζ Ω Ω2
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
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.
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";
1.5
0.5
2 4 6 8 10
-0.5
-1
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.
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.
In[1]:= ControlSystems`
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.
r e 20 c
Gs
ss 1 s 4
Hs 1 ks
Out[5]= k1
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
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
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.
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.
Ω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
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.
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.
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, Ω
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
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.
k 50
Out[17]=
10
In[19]:= SeriesConnectg , h
k 50
Out[19]=
10 20
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.
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.
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
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.
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
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
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
In[27]:= NicholsPlot% ;
0
Gain dB
-20
-40
-60
-80
-180 -170 -160 -150 -140 -130 -120
Phase degrees
SingularValuePlotsystem
generate a singular-value plot for system
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.
yi u j
ui yj
System i System j
SeriesConnectsystem1 , system2
find the aggregate system by connecting all outputs
of system1 to corresponding inputs of system2
In[1]:= ControlSystems`
A11 A12 B1 0
Out[3]= A21 A22 0 B2
C11 C12 D11 D12 •
100 Control System Professional
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 •
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
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
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.
1
Out[10]=
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
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.
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
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.
1
Out[17]=
1 2 3
u 1 1 1 1 y
s s 1 s 2 s 3
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
ParallelConnectsystem1 , system2
connect all inputs of system1 with all inputs of
system2 and sum all corresponding outputs
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
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
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.
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
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
FeedbackConnectsystem1 , system2
put system2 in the negative feedback loop for system1
FeedbackConnectsystem1 , system2 ,
o1 , o2 , …, i1 , type1 , i2 , type2 , …
use typek when connecting input ik
The type descriptor for FeedbackConnect should be one of the reserved words Positive or
Negative.
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 •
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.
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
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
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
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
Out[32]= g h
g
Out[33]=
g h 1
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Α
a 0 b1 0
1
0 a 0 b2
Out[34]=
2
c1 0 d1 0
0 c2 0 d 2 •
A11 A12 B1 0
Out[35]= A21 A22 0 B2
C11 C12 D11 D12 •
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 •
u y
Β
a
Α
y
u 1 1 2 2 3 3 4 4
1 Β 1
1 2 3
4
5 5
b Α
5
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.
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 to GenericConnect.
114 Control System Professional
System
.
x x
B C
u y
Controller
StateFeedbackConnectsystem, controller
feed all states of system back to its inputs
via controller forming negative feedback
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
Subsystemsystem, inputs
select the part of system
associated with the specified inputs
This picks the subsystem that has only the first and third inputs.
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 •
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 •
DeleteSubsystemsystem, inputs
delete the part of system
associated with the specified inputs
Here is a transfer function of a system with two inputs and three outputs.
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.
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.
This merges them into one. The aggregate has all the inputs, outputs, and states of
its components.
In[46]:= MergeSystemsss1, ss2
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
1
1
0
1
1
Out[49]= 0 0
2
1
0 0
3
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
In[50]:= plant StateSpace0, 1, 0, 0, 0, 1, 1, 0
0 1 0
Out[50]= 0 0 1
1 0 0 •
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
kd 2 Τ k p 2 Τ ki k p ki
Out[53]=
Τ 3 kd 2 Τ k p 2 Τ ki k p ki
4
Out[54]= s3 s4 Τ s2 kd ki s Τ ki s kp 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
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
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.
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.
OutputControllablestatespace
test if the system
statespace is output controllable
Observablestatespace test if the system statespace is observable
Testing controllability and observability properties.
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 •
In[3]:= Controllabless
Out[3]= False
In[4]:= OutputControllabless
Out[4]= False
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.
In[6]:= Controllableundefinedsystem
Out[6]= Controllableundefinedsystem
124 Control System Professional
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
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
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.
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.
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
B AB A2 B An1 B
(7.1)
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.
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 •
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
In[12]:= Controllablesystem
Out[12]= False
In[13]:= ObservabilityMatrixsystem
1 0 0
3 1 0
Out[13]=
4 3 1
In[14]:= Rank%
Out[14]= 3
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
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.
In[17]:= ControllabilityGramian %
0.332677
500.205
Out[17]=
0.332677 0.00248846
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.
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
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 •
0 Rea1
Ima1 1 1
Out[21]= 1 a2 0 1
1 1 0 0 •
Option to DualSystem.
8. Realizations
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
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.
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 •
In[3]:= Controllabless
Out[3]= False
Neither is it observable.
In[4]:= Observabless
Out[4]= False
In[5]:= ControllableSubsystemss
a 0 b 1 0
2
0 a 0 b2
Out[5]=
3
0 0 d11 d12
0 c3 d21 d22 •
In[6]:= ObservableSubsystemss
a1 0 0 0
0 a3 0 b2
Out[6]=
c1 0 d11 d12
0 c3 d21 d22 •
8. Realizations 135
a3 0 b2
c3 d21 d22 •
0 b 2
3
a
0 d
Out[8]= 11 d12
c3 d21 d22 •
Out[9]= True
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
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
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 •
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
JordanCanonicalFormstatespace
find the Jordan canonical
form of the system statespace
Finding the Jordan canonical form.
1 0 0
0 2 0
Out[13]=
0 0 3
0 1 0
Out[14]= 1 0 1
1 1 0
8. Realizations 139
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.
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 •
In[18]:= JordanCanonicalForm%
3 0 0 b1 0
0 2 0 0 b
2
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
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. 15. 1. 0. 0 •
0.350054 1.21805
1.19628 1.65665 0.252316
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
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
1. 2 15. 50.
Out[24]=
5. 3 33. 2 79. 50.
4
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
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
Out[25]=
0.643875 5.6329
1.49353 0.519548
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.
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
As we can see, in the reduced models the low-frequency behavior is preserved while the
high-frequency (fast) states are eliminated.
For the model reduction purposes, PoleZeroCancel in its current implementation is most
useful for SISO systems.
8. Realizations 145
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.
Out[32]= 1 •
146 Control System Professional
Option to PoleZeroCancel.
x t Ax t But
(8.4)
yt Cx t Dut
where
A TAT1
B TB (8.5)
C CT1
SimilarityTransformstatespace, m
transform the system statespace with the matrix m
Finding the similarity transformation.
8. Realizations 147
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 •
1 0 1
Out[34]= 0 0 1
1 1 1
3 0 0 b1 0
0 2 0 0 b
2
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
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.
Options to SimilarityTransform.
TransformationMatrixoriginal, transformed
the similarity transformation
matrix between two realizations
Recovering the similarity transformation.
8. Realizations 149
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 •
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.
Λ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.
Reference
In[1]:= <<ControlSystems`
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.
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
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.
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;
In[11]:= $MachinePrecision
Out[11]= 16
We double-check the result. The achieved accuracy is even greater than required.
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
where
en 0 0 0 1
C B AB A2 B An1 B
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:
The function StateFeedbackGains with the option Method
Ackermann implements this
algorithm.
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.
Figure 9.2. F-8 aircraft in flight. Photograph by Dryden Flight Research Center, NASA.
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
Β
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
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
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
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.
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.
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.
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[22]:= k10
StateFeedbackGainsaircraft, poles, Method KNVD, MaxIterations 10
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
Finally, these are the maximum relative errors introduced by the distortion.
# poles
In[26]:= MaxAbs & %
poles
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
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
Observer
D B
System
uk yk ^
xk1 ^
xk
xk1 Axk Buk Delay
yk Cxk Duk L
State estimat
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):
The corresponding block diagram is presented in Figure 9.5. EstimatorGains handles both
continuous- and discrete-time cases.
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 .
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.
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
If the solution to the optimal control problem can be found in the form
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,
and
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
N1
J SxN Lxk, uk (10.8)
k0
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
Q1 , C1 Q2 , C2
Tank
Q, C
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 •
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
0.01 0
Out[4]=
0 100
2 0
Out[5]=
0 0.5
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
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
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
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
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
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.
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 •
10 0
Out[18]=
0 0.01
2 0
Out[19]=
0 0.2
In[20]:= LQOutputRegulatorGainstank, q , r
0.00589458 0.000624227
Out[20]=
0.0589383 0.00125691
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.
DiscreteRiccatiSolvea, b, q, r
solve the discrete algebraic Riccati equation
Functions for solving Riccati equations.
In[21]:= aa % 1
; bb % 2
;
3 1
Out[23]=
1 3
174 Control System Professional
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
In[26]:= aa ss 1
; bb ss 2
;
2.40153 1.05792
Out[27]=
1.05792 2.09705
In[29]:= LQRegulatorGainsss, q , r
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 Φ
Φ
Φ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 .
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
1
0 0
∆20
Out[32]=
0 0 0
0 0 1
Φ 0
2
1
In[33]:= r
u0 2
1
Out[33]= u20
In[36]:= RiccatiSolve %
In[37]:= Inverser.Transposebb.%
Again, the result is the same as the one obtained with LQRegulatorGains.
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
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.
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
In[41]:= LQRegulatorGainssatellite, q , r
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%
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
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
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
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
Ewt 0
Evt 0
Here Ex denotes the mean of random variable x . The two noises may further be assumed to
be mutually uncorrelated,
EvtwT Τ 0
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.
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
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.
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 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
1. 0.0786939 0.00426123 0.000426123
Out[54]= 0. 0.606531 0.0786939 0.00786939
1 0 0 0 0.1
In[55]:= qd rd 10;
This finds the stationary Kalman gain matrix for the discrete-time system.
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.
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 •
0.0194241
Out[58]=
0.00190346
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
B A D D B D
_ y^
y x
Delay C C Delay
Sensor Output
outputs estimate
L A
Bw Dw C
w x^
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
In[59]:= StateSpacea, b1 , b2 , c1 , c2 , d11 , d12 , d21 , d22
a b1 b2
Out[59]= c1 d11 d12
c2 d21 d22 •
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
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
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;
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
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`"
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 ;
In[75]:= v TableRandomNormalDistribution 0, r 1, 1
, n ;
This is where the simulation is performed. The result is a list of output vectors.
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 ";
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
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
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
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
K Kalman
estimator
x^
Controller
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 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
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
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.
x fx, u
(11.1)
y hx, u
the locally linearized model is given by
x Ax Bu
(11.2)
y Cx Du
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
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
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.
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
In[1]:= ControlSystems`
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 •
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
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
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
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
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
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.
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).
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.
In[1]:= ControlSystems`
12. Miscellaneous 205
This finds its Schur decomposition using the built-in Mathematica function.
The eigenvalues on the main diagonal do not follow any particular order.
In[4]:= t
In[6]:= to 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
In[9]:= to Chop
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
involves only matrices A and C , in which case all matrices are square with the same dimen-
sions.
X AXAT C (12.3)
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.
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.
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
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
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";
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";
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
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.
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
0.400733
Out[23]=
2.40162
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
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.
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.
Ogata, Katsuhiko. Modern Control Engineering, Englewood Cliffs, NJ: Prentice Hall, 1990.
Index
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
Kalman, 135
Kalman canonical forms, 136
Index 221
$DiscreteTimeToken , 41
$RandomOrthogonalComplement, 130
$Sampled, 39
$SamplingPeriod, 45