Python Control
Python Control
Release dev
1 Introduction 3
1.1 Overview of the Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Some Differences from MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Python-Control Functions 5
2.1 Creating System Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Block Diagram Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.3 Control System Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.4 Frequency Domain Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.5 Time Domain Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.6 Control System Synthesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.7 Model Simplification Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.8 Utility Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3 Python-Control Classes 33
3.1 LTI System Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.2 State Space Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.3 Transfer Function Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.4 FRD Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
i
4.17 Additional functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
5 Examples 67
ii
Python Control Documentation, Release dev
Welcome to the Python Control Systems Library (python-control) User’s Manual. This manual describes the python-
control package, including all of the functions defined in the package and examples showing how to use the package.
Contents:
Contents 1
Python Control Documentation, Release dev
2 Contents
CHAPTER 1
Introduction
Welcome to the Python Control Systems Toolbox (python-control) User’s Manual. This manual contains informa-
tion on using the python-control package, including documentation for all functions in the package and examples
illustrating their use.
The python-control package is a set of python classes and functions that implement common operations for the analysis
and design of feedback control systems. The initial goal is to implement all of the functionality required to work
through the examples in the textbook Feedback Systems by Astrom and Murray. A MATLAB compatibility package
(control.matlab) is available that provides many of the common functions corresponding to commands available in the
MATLAB Control Systems Toolbox.
In addition to the documentation here, there is a project wiki that contains some additional information about how to
use the package (including some detailed worked examples):
http://python-control.sourceforge.net
The python-control package makes use of NumPy and SciPy. A list of general differences between NumPy and
MATLAB can be found here:
http://www.scipy.org/NumPy_for_Matlab_Users
In terms of the python-control package more specifically, here are some thing to keep in mind:
• You must include commas in vectors. So [1 2 3] must be [1, 2, 3].
• Functions that return multiple arguments use tuples
• You cannot use braces for collections; use tuples instead
• Transfer functions are currently only implemented for SISO systems; use state space representations for MIMO
systems.
3
Python Control Documentation, Release dev
2. Untar the source code in a temporary directory and run ‘python setup.py install’ to build and install the code
3. To see if things are working correctly, run ipython -pylab and run the script ‘examples/secord-matlab.py’. This
should generate a step response, Bode plot and Nyquist plot for a simple second order system. (For more detailed
tests, run nosetests in the main directory.)
4. To see the commands that are available, run the following commands in ipython:
>>> import control
>>> ?control
5. If you want to have a MATLAB-like environment for running the control toolbox, use:
>>> from control.matlab import *
>>> ?control.matlab
4 Chapter 1. Introduction
CHAPTER 2
Python-Control Functions
class control.StateSpace(*args)
The StateSpace class represents state space instances and functions.
The StateSpace class is used throughout the python-control library to represent systems in state space form. This
class is derived from the Lti base class.
The main data members are the A, B, C, and D matrices. The class also keeps track of the number of states (i.e.,
the size of A).
Discrete time state space system are implemented by using the ‘dt’ class variable and setting it to the sampling
period. If ‘dt’ is not None, then it must match whenever two state space systems are combined. Setting dt = 0
specifies a continuous system, while leaving dt = None means the system timebase is not specified. If ‘dt’ is set
to True, the system will be treated as a discrete time system with unspecified sampling time.
control.ss(*args)
Create a state space system.
The function accepts either 1, 4 or 5 parameters:
ss(sys) Convert a linear system into space system form. Always creates a new system, even if sys is already
a StateSpace object.
ss(A, B, C, D) Create a state space system from the matrices of its state and output equations:
𝑥˙ = 𝐴 · 𝑥 + 𝐵 · 𝑢
𝑦 =𝐶 ·𝑥+𝐷·𝑢
ss(A, B, C, D, dt) Create a discrete-time state space system from the matrices of its state and output
equations:
5
Python Control Documentation, Release dev
The matrices can be given as array like data types or strings. Everything that the constructor of
numpy.matrix accepts is permissible here too.
See also:
tf, ss2tf, tf2ss
Examples
class control.TransferFunction(*args)
The TransferFunction class represents TF instances and functions.
The TransferFunction class is derived from the Lti parent class. It is used throught the python-control library to
represent systems in transfer function form.
The main data members are ‘num’ and ‘den’, which are 2-D lists of arrays containing MIMO numerator and
denominator coefficients. For example,
>>> num[2][5] = numpy.array([1., 4., 8.])
means that the numerator of the transfer function from the 6th input to the 3rd output is set to s^2 + 4s + 8.
Discrete time transfer functions are implemented by using the ‘dt’ class variable and setting it to something other
than ‘None’. If ‘dt’ has a non-zero value, then it must match whenever two transfer functions are combined. If
‘dt’ is set to True, the system will be treated as a discrete time system with unspecified sampling time.
control.tf(*args)
Create a transfer function system. Can create MIMO systems.
The function accepts either 1 or 2 parameters:
tf(sys) Convert a linear system into transfer function form. Always creates a new system, even if sys is
already a TransferFunction object.
tf(num, den) Create a transfer function system from its numerator and denominator polynomial coeffi-
cients.
If num and den are 1D array_like objects, the function creates a SISO system.
To create a MIMO system, num and den need to be 2D nested lists of array_like objects. (A 3 dimensional
data structure in total.) (For details see note below.)
tf(num, den, dt) Create a discrete time transfer function system; dt can either be a positive number
indicating the sampling time or ‘True’ if no specific timebase is given.
See also:
ss, ss2tf, tf2ss
Notes
Todo
The next paragraph contradicts the comment in the example! Also “input” should come before “output” in the
sentence:
“from the (j+1)st output to the (i+1)st input”
num[i][j] contains the polynomial coefficients of the numerator for the transfer function from the (j+1)st
output to the (i+1)st input. den[i][j] works the same way.
The coefficients [2, 3, 4] denote the polynomial 2 · 𝑠2 + 3 · 𝑠 + 4.
Examples
Notes
If the number of states, inputs, or outputs is not specified, then the missing numbers are assumed to be 1. The
poles of the returned system will always have a magnitude less than 1.
control.isctime(sys, strict=False)
Check to see if a system is a continuous-time system
Parameters sys : LTI system
System to be checked
strict: bool (default = False) :
If strict is True, make sure that timebase is not None
control.isdtime(sys, strict=False)
Check to see if a system is a discrete time system
Parameters sys : LTI system
System to be checked
strict: bool (default = False) :
If strict is True, make sure that timebase is not None
control.issys(object)
control.pade(T, n=1)
Create a linear system that approximates a delay.
Return the numerator and denominator coefficients of the Pade approximation.
Parameters T : number
time delay
n : integer
order of approximation
Returns num, den : array
Polynomial coefficients of the delay model, in descending powers of s.
Notes
Based on an algorithm in Golub and van Loan, “Matrix Computation” 3rd. Ed. pp. 572-574.
control.sample_system(sysc, Ts, method=’zoh’, alpha=None)
Convert a continuous time system to discrete time
Creates a discrete time system from a continuous time system by sampling. Multiple methods of conversion are
supported.
Parameters sysc : linsys
Continuous time system to be converted
Ts : real
Sampling period
method : string
Method to use for conversion: ‘matched’ (default), ‘tustin’, ‘zoh’
Returns sysd : linsys
Discrete time system, with sampling rate Ts
Notes
Examples
control.ss2tf(*args)
Transform a state space system to a transfer function.
The function accepts either 1 or 4 parameters:
ss2tf(sys) Convert a linear system into space system form. Always creates a new system, even if sys is
already a StateSpace object.
ss2tf(A, B, C, D) Create a state space system from the matrices of its state and output equations.
For details see: ss()
See also:
tf, ss, tf2ss
Examples
control.ssdata(sys)
Return state space data objects for a system
Parameters sys: Lti (StateSpace, or TransferFunction) :
LTI system whose data will be returned
See also:
ss, tf, ss2tf
Examples
>>> num = [[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]]]
>>> den = [[[9., 8., 7.], [6., 5., 4.]], [[3., 2., 1.], [-1., -2., -3.]]]
>>> sys1 = tf2ss(num, den)
control.tfdata(sys)
Return transfer function data objects for a system
Parameters sys: Lti (StateSpace, or TransferFunction) :
LTI system whose data will be returned
Returns (num, den): numerator and denominator arrays :
Notes
This function is a wrapper for the feedback function in the StateSpace and TransferFunction classes. It calls
TransferFunction.feedback if sys1 is a TransferFunction object, and StateSpace.feedback if sys1 is a StateSpace
object. If sys1 is a scalar, then it is converted to sys2‘s type, and the corresponding feedback function is used. If
sys1 and sys2 are both scalars, then TransferFunction.feedback is used.
control.negate(sys)
Return the negative of a system.
Parameters sys: StateSpace, TransferFunction or FRD :
Notes
This function is a wrapper for the __neg__ function in the StateSpace and TransferFunction classes. The output
type is the same as the input type.
If both systems have a defined timebase (dt = 0 for continuous time, dt > 0 for discrete time), then the timebase
for both systems must match. If only one of the system has a timebase, the return timebase will be set to match
it.
Examples
control.parallel(sys1, sys2)
Return the parallel connection sys1 + sys2.
Parameters sys1: scalar, StateSpace, TransferFunction, or FRD :
sys2: scalar, StateSpace, TransferFunction, or FRD :
Returns out: scalar, StateSpace, or TransferFunction :
Raises ValueError :
if sys1 and sys2 do not have the same numbers of inputs and outputs
See also:
series, feedback
Notes
This function is a wrapper for the __add__ function in the StateSpace and TransferFunction classes. The output
type is usually the type of sys1. If sys1 is a scalar, then the output type is the type of sys2.
If both systems have a defined timebase (dt = 0 for continuous time, dt > 0 for discrete time), then the timebase
for both systems must match. If only one of the system has a timebase, the return timebase will be set to match
it.
Examples
control.series(sys1, sys2)
Return the series connection sys2 * sys1 for –> sys1 –> sys2 –>.
Parameters sys1: scalar, StateSpace, TransferFunction, or FRD :
sys2: scalar, StateSpace, TransferFunction, or FRD :
Returns out: scalar, StateSpace, or TransferFunction :
Raises ValueError :
if sys2.inputs does not equal sys1.outputs if sys1.dt is not compatible with sys2.dt
See also:
parallel, feedback
Notes
This function is a wrapper for the __mul__ function in the StateSpace and TransferFunction classes. The output
type is usually the type of sys2. If sys2 is a scalar, then the output type is the type of sys1.
If both systems have a defined timebase (dt = 0 for continuous time, dt > 0 for discrete time), then the timebase
for both systems must match. If only one of the system has a timebase, the return timebase will be set to match
it.
Examples
control.acker(A, B, poles)
Pole placement using Ackermann method
Call: K = acker(A, B, poles)
Parameters A, B : 2-d arrays
State and input matrix of the system
poles: 1-d list :
Desired eigenvalue locations
Returns K: matrix :
Gains such that A - B K has given eigenvalues
control.ctrb(A, B)
Controllabilty matrix
Parameters A, B: array_like or string :
Dynamics and input matrix of the system
Returns C: matrix :
Controllability matrix
Examples
>>> C = ctrb(A, B)
where A and Q are square matrices of the same dimension. Further, Q and R are a symmetric matrices. If R is
None, it is set to the identity matrix. The function returns the solution X, the gain matrix G = B^T X and the
closed loop eigenvalues L, i.e., the eigenvalues of A - B G.
(X,L,G) = care(A,B,Q,R,S,E) solves the generalized continuous-time algebraic Riccati equation
𝐴𝑇 𝑋𝐸 + 𝐸 𝑇 𝑋𝐴 − (𝐸 𝑇 𝑋𝐵 + 𝑆)𝑅−1 (𝐵 𝑇 𝑋𝐸 + 𝑆 𝑇 ) + 𝑄 = 0
where A, Q and E are square matrices of the same dimension. Further, Q and R are symmetric matrices. If R is
None, it is set to the identity matrix. The function returns the solution X, the gain matrix G = R^-1 (B^T X E +
S^T) and the closed loop eigenvalues L, i.e., the eigenvalues of A - B G , E.
control.dare(A, B, Q, R, S=None, E=None)
(X,L,G) = dare(A,B,Q,R) solves the discrete-time algebraic Riccati equation
𝐴𝑇 𝑋𝐴 − 𝑋 − 𝐴𝑇 𝑋𝐵(𝐵 𝑇 𝑋𝐵 + 𝑅)−1 𝐵 𝑇 𝑋𝐴 + 𝑄 = 0
where A and Q are square matrices of the same dimension. Further, Q is a symmetric matrix. The function
returns the solution X, the gain matrix G = (B^T X B + R)^-1 B^T X A and the closed loop eigenvalues L, i.e.,
the eigenvalues of A - B G.
(X,L,G) = dare(A,B,Q,R,S,E) solves the generalized discrete-time algebraic Riccati equation
𝐴𝑇 𝑋𝐴 − 𝐸 𝑇 𝑋𝐸 − (𝐴𝑇 𝑋𝐵 + 𝑆)(𝐵 𝑇 𝑋𝐵 + 𝑅)−1 (𝐵 𝑇 𝑋𝐴 + 𝑆 𝑇 ) + 𝑄 = 0
where A, Q and E are square matrices of the same dimension. Further, Q and R are symmetric matrices. The
function returns the solution X, the gain matrix 𝐺 = (𝐵 𝑇 𝑋𝐵 + 𝑅)−1 (𝐵 𝑇 𝑋𝐴 + 𝑆 𝑇 ) and the closed loop
eigenvalues L, i.e., the eigenvalues of A - B G , E.
control.dlyap(A, Q, C=None, E=None)
dlyap(A,Q) solves the discrete-time Lyapunov equation
𝐴𝑋𝐴𝑇 − 𝑋 + 𝑄 = 0
where A and Q are square matrices of the same dimension. Further Q must be symmetric.
dlyap(A,Q,C) solves the Sylvester equation
𝐴𝑋𝑄𝑇 − 𝑋 + 𝐶 = 0
where A and Q are square matrices.
dlyap(A,Q,None,E) solves the generalized discrete-time Lyapunov equation
𝐴𝑋𝐴𝑇 − 𝐸𝑋𝐸 𝑇 + 𝑄 = 0
where Q is a symmetric matrix and A, Q and E are square matrices of the same dimension.
control.dcgain(*args)
Compute the gain of the system in steady state.
The function takes either 1, 2, 3, or 4 parameters:
Parameters A, B, C, D: array-like :
A linear system in state space form.
Z, P, k: array-like, array-like, number :
A linear system in zero, pole, gain form.
num, den: array-like :
A linear system in transfer function form.
sys: Lti (StateSpace or TransferFunction) :
A linear system object.
Notes
This function is only useful for systems with invertible system matrix A.
All systems are first converted to state space form. The function then computes:
𝑔𝑎𝑖𝑛 = −𝐶 · 𝐴−1 · 𝐵 + 𝐷
control.evalfr(sys, x)
Evaluate the transfer function of an LTI system for a single complex number x.
To evaluate at a frequency, enter x = omega*j, where omega is the frequency in radians
Parameters sys: StateSpace or TransferFunction :
Linear system
x: scalar :
Complex number
Returns fresp: ndarray :
See also:
freqresp, bode
Notes
Examples
>>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
>>> evalfr(sys, 1j)
array([[ 44.8-21.4j]])
>>> # This is the transfer function matrix evaluated at s = i.
Todo
Add example with MIMO system
control.gram(sys, type)
Gramian (controllability or observability)
Parameters sys: StateSpace :
State-space system to compute Gramian for
type: String :
Type of desired computation. type is either ‘c’ (controllability) or ‘o’ (observability).
Returns gram: array :
Gramian of system
Raises ValueError :
• if system is not instance of StateSpace class
• if type is not ‘c’ or ‘o’
• if system is unstable (sys.A has eigenvalues not in left half plane)
ImportError :
if slycot routin sb03md cannot be found
Examples
>>> Wc = gram(sys,'c')
>>> Wo = gram(sys,'o')
Notes
This function is a wrapper for StateSpace.freqresp and TransferFunction.freqresp. The output omega is a sorted
version of the input omega.
Examples
>>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
>>> mag, phase, omega = freqresp(sys, [0.1, 1., 10.])
>>> mag
array([[[ 58.8576682 , 49.64876635, 13.40825927]]])
>>> phase
array([[[-0.05408304, -0.44563154, -0.66837155]]])
Todo
Add example with MIMO system
#>>> sys = rss(3, 2, 2) #>>> mag, phase, omega = freqresp(sys, [0.1, 1., 10.]) #>>> mag[0, 1, :] #array([
55.43747231, 42.47766549, 1.97225895]) #>>> phase[1, 0, :] #array([-0.12611087, -1.14294316, 2.5764547
]) #>>> # This is the magnitude of the frequency response from the 2nd #>>> # input to the 1st output, and the
phase (in radians) of the #>>> # frequency response from the 1st input to the 2nd output, for #>>> # s = 0.1i, i,
10i.
control.margin(*args)
Calculate gain and phase margins and associated crossover frequencies
Function margin takes either 1 or 3 parameters.
Parameters sys : StateSpace or TransferFunction
Linear SISO system
mag, phase, w : array_like
Input magnitude, phase (in deg.), and frequencies (rad/sec) from bode frequency re-
sponse data
Returns gm, pm, Wcg, Wcp : float
Gain margin gm, phase margin pm (in deg), gain crossover frequency (corresponding to
phase margin) and phase crossover frequency (corresponding to gain margin), in rad/sec
of SISO open-loop. If more than one crossover frequency is detected, returns the lowest
corresponding margin.
Examples
>>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
>>> gm, pm, wg, wp = margin(sys)
margin: no magnitude crossings found
Todo
better ecample system!
#>>> gm, pm, wg, wp = margin(mag, phase, w)
control.markov(Y, U, M)
Calculate the first M Markov parameters [D CB CAB ...] from input U, output Y.
Parameters Y: array_like :
Output data
U: array_like :
Input data
M: integer :
Number of Markov parameters to output
Returns H: matrix :
First M Markov parameters
Notes
Examples
>>> H = markov(Y, U, M)
control.obsv(A, C)
Observability matrix
Parameters A, C: array_like or string :
Dynamics and output matrix of the system
Returns O: matrix :
Observability matrix
Examples
>>> O = obsv(A, C)
control.phase_crossover_frequencies(sys)
Compute frequencies and gains at intersections with real axis in Nyquist plot.
Call as: omega, gain = phase_crossover_frequencies()
Examples
control.pole(sys)
Compute system poles.
Parameters sys: StateSpace or TransferFunction :
Linear system
Notes
returnall=False: boolean :
If true, return all margins found. Note that for frequency data or FRD systems, only one
margin is found and returned.
epsw=1e-10: float :
frequencies below this value are considered static gain, and not returned as margin.
Returns gm, pm, sm, wg, wp, ws: float or array_like :
Gain margin gm, phase margin pm, stability margin sm, and associated crossover fre-
quencies wg, wp, and ws of SISO open-loop. If more than one crossover frequency is
detected, returns the lowest corresponding margin. When requesting all margins, the
return values are array_like, and all margins are returns for linear systems not equal to
FRD
control.zero(sys)
Compute system zeros.
Parameters sys: StateSpace or TransferFunction :
Linear system
Returns zeros: ndarray :
Array that contains the system’s zeros.
Raises NotImplementedError :
when called on a TransferFunction object or a MIMO StateSpace object
See also:
pole
Notes
Hz : boolean
If True, plot frequency in Hz (omega must be provided in rad/sec)
deg : boolean
If True, return phase in degrees (else radians)
Plot : boolean
If True, plot magnitude and phase
*args, **kwargs: :
Additional options to matplotlib (color, linestyle, etc)
Returns mag : array (list if len(syslist) > 1)
magnitude
phase : array (list if len(syslist) > 1)
phase
omega : array (list if len(syslist) > 1)
frequency
Notes
1. Alternatively, you may use the lower-level method (mag, phase, freq) = sys.freqresp(freq) to generate the
frequency response for a system, but it returns a MIMO response.
2. If a discrete time model is given, the frequency response is plotted along the upper branch of the unit circle,
using the mapping z = exp(j omega dt) where omega ranges from 0 to pi/dt and dt is the discrete time base. If
not timebase is specified (dt = True), dt is set to 1.
Examples
>>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
>>> mag, phase, omega = bode(sys)
Examples
>>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
>>> real, imag, freq = nyquist_plot(sys)
control.gangof4_plot(P, C, omega=None)
Plot the “Gang of 4” transfer functions for a system
Generates a 2x2 plot showing the “Gang of 4” sensitivity functions [T, PS; CS, S]
Parameters P, C : Lti
Linear input/output systems (process and control)
omega : array
Range of frequencies (list or bounds) in rad/sec
Returns None :
control.nichols_plot(syslist, omega=None, grid=True)
Nichols plot for a system
Plots a Nichols plot for the system over a (optional) frequency range.
Parameters syslist : list of Lti, or Lti
List of linear input/output systems (single system is OK)
omega : array_like
Range of frequencies (list or bounds) in rad/sec
grid : boolean, optional
True if the plot should include a Nichols-chart grid. Default is True.
Returns None :
control.freqplot.default_frequency_range(syslist)
Compute a reasonable default frequency range for frequency domain plots.
Finds a reasonable default frequency range by examining the features (poles and zeros) of the systems in syslist.
Parameters syslist : list of Lti
List of linear input/output systems (single system is OK)
Returns omega : array
Examples
This is a convention for function arguments and return values that represent time series: sequences of values
that change over time. It is used throughout the library, for example in the functions forced_response(),
step_response(), impulse_response(), and initial_response().
Note: This convention is different from the convention used in the library scipy.signal. In Scipy’s convention
the meaning of rows and columns is interchanged. Thus, all 2D values must be transposed when they are used with
functions from scipy.signal.
Types:
• Arguments can be arrays, matrices, or nested lists.
• Return values are arrays (not matrices).
The time vector is either 1D, or 2D with shape (1, n):
T = [[t1, t2, t3, ..., tn ]]
Input, state, and output all follow the same convention. Columns are different points in time, rows are different
components. When there is only one row, a 1D object is accepted or returned, which adds convenience for SISO
systems:
U = [[u1(t1), u1(t2), u1(t3), ..., u1(tn)]
[u2(t1), u2(t2), u2(t3), ..., u2(tn)]
...
...
[ui(t1), ui(t2), ui(t3), ..., ui(tn)]]
Same for X, Y
So, U[:,2] is the system’s input at the third point in time; and U[1] or U[1,:] is the sequence of values for the system’s
second input.
The initial conditions are either 1D, or 2D with shape (j, 1):
X0 = [[x1]
[x2]
...
...
[xj]]
The convention also works well with the state space form of linear systems. If D is the feedthrough matrix of a linear
system, and U is its input (matrix or array), then the feedthrough part of the system’s response, can be computed like
this:
ft = D * U
Returns T: array :
Time values of the output.
yout: array :
Response of the system.
xout: array :
Time evolution of the state vector.
See also:
step_response, initial_response, impulse_response
Examples
Examples
See also:
forced_response, initial_response, impulse_response
Examples
See also:
box_grid, Y
control.phaseplot.box_grid(xlimp, ylimp)
box_grid generate list of points on edge of box
list = box_grid([xmin xmax xnum], [ymin ymax ynum]) generates a list of points that correspond to a uniform
grid at the end of the box defined by the corners [xmin ymin] and [xmax ymax].
control.lqr(*args, **keywords)
Linear quadratic regulator design
The lqr() function computes the optimal state feedback controller that minimizes the quadratic cost
∫︁ ∞
𝐽= 𝑥′ 𝑄𝑥 + 𝑢′ 𝑅𝑢 + 2𝑥′ 𝑁 𝑢
0
E: 1-d array :
Eigenvalues of the closed loop system
Examples
control.place(A, B, p)
Place closed loop eigenvalues
Parameters A : 2-d array
Dynamics matrix
B : 2-d array
Input matrix
p : 1-d list
Desired eigenvalue locations
Returns K : 2-d array
Gains such that A - B K has given eigenvalues
Examples
ImportError :
if slycot routine ab09ad is not found
Examples
control.hsvd(sys)
Calculate the Hankel singular values.
Parameters sys : StateSpace
A state space system
Returns H : Matrix
A list of Hankel singular values
See also:
gram
Notes
The Hankel singular values are the singular values of the Hankel operator. In practice, we compute the square
root of the eigenvalues of the matrix formed by taking the product of the observability and controllability grami-
ans. There are other (more efficient) methods based on solving the Lyapunov equation in a particular way (more
details soon).
Examples
>>> H = hsvd(sys)
Examples
control.unwrap(angle, period=6.28)
Unwrap a phase angle to give a continuous curve
Parameters X : array_like
Input array
period : number
Input period (usually either 2‘‘*‘‘pi or 360)
Returns Y : array_like
Output array, with jumps of period/2 eliminated
Examples
Python-Control Classes
lti.py
The Lti module contains the Lti parent class to the child classes StateSpace and TransferFunction. It is designed for
use in the python-control library.
Routines in this module:
Lti.__init__ isdtime() isctime() timebase() timebaseEqual()
class control.lti.Lti(inputs=1, outputs=1, dt=None)
Lti is a parent class to linear time invariant control (LTI) objects.
Lti is the parent to the StateSpace and TransferFunction child classes. It contains the number of inputs and
outputs, and the timebase (dt) for the system.
The timebase for the system, dt, is used to specify whether the system is operating in continuous or discrete
time. It can have the following values:
•dt = None No timebase specified
•dt = 0 Continuous time system
•dt > 0 Discrete time system with sampling time dt
•dt = True Discrete time system with unspecified sampling time
When to Lti systems are combined, there timebases much match. A system with timebase None can be combined
with a system having a specified timebase, and the result will have the timebase of the latter system.
The StateSpace and TransferFunction child classes contain several common “virtual” functions. These are:
__init__ copy __str__ __neg__ __add__ __radd__ __sub__ __rsub__ __mul__ __rmul__ __div__ __rdiv__
evalfr freqresp pole zero feedback returnScipySignalLti
isctime(strict=False)
Check to see if a system is a continuous-time system
Parameters sys : LTI system
System to be checked
strict: bool (default = False) :
If strict is True, make sure that timebase is not None
33
Python Control Documentation, Release dev
isdtime(strict=False)
Check to see if a system is a discrete-time system
Parameters strict: bool (default = False) :
If strict is True, make sure that timebase is not None
control.lti.isctime(sys, strict=False)
Check to see if a system is a continuous-time system
Parameters sys : LTI system
System to be checked
strict: bool (default = False) :
If strict is True, make sure that timebase is not None
control.lti.isdtime(sys, strict=False)
Check to see if a system is a discrete time system
Parameters sys : LTI system
System to be checked
strict: bool (default = False) :
If strict is True, make sure that timebase is not None
control.lti.timebase(sys, strict=True)
Return the timebase for an Lti system
dt = timebase(sys)
returns the timebase for a system ‘sys’. If the strict option is set to False, dt = True will be returned as 1.
control.lti.timebaseEqual(sys1, sys2)
Check to see if two systems have the same timebase
timebaseEqual(sys1, sys2)
returns True if the timebases for the two systems are compatible. By default, systems with timebase ‘None’ are
compatible with either discrete or continuous timebase systems. If two systems have a discrete timebase (dt >
0) then their timebases must be equal.
class control.statesp.StateSpace(*args)
The StateSpace class represents state space instances and functions.
The StateSpace class is used throughout the python-control library to represent systems in state space form. This
class is derived from the Lti base class.
The main data members are the A, B, C, and D matrices. The class also keeps track of the number of states (i.e.,
the size of A).
Discrete time state space system are implemented by using the ‘dt’ class variable and setting it to the sampling
period. If ‘dt’ is not None, then it must match whenever two state space systems are combined. Setting dt = 0
specifies a continuous system, while leaving dt = None means the system timebase is not specified. If ‘dt’ is set
to True, the system will be treated as a discrete time system with unspecified sampling time.
append(other)
Append a second model to the present model. The second model is converted to state-space if necessary,
inputs and outputs are appended and their order is preserved
evalfr(omega)
Evaluate a SS system’s transfer function at a single frequency.
self.evalfr(omega) returns the value of the transfer function matrix with input value s = i * omega.
feedback(other=1, sign=-1)
Feedback interconnection between two LTI systems.
freqresp(omega)
Evaluate the system’s transfer func. at a list of ang. frequencies.
mag, phase, omega = self.freqresp(omega)
reports the value of the magnitude, phase, and angular frequency of the system’s transfer function matrix
evaluated at s = i * omega, where omega is a list of angular frequencies, and is a sorted version of the input
omega.
horner(s)
Evaluate the systems’s transfer function for a complex variable
Returns a matrix of values evaluated at complex variable s.
minreal(tol=0.0)
Calculate a minimal realization, removes unobservable and uncontrollable states
pole()
Compute the poles of a state space system.
returnScipySignalLti()
Return a list of a list of scipy.signal.lti objects.
For instance,
>>> out = ssobject.returnScipySignalLti()
>>> out[3][5]
is a signal.scipy.lti object corresponding to the transfer function from the 6th input to the 4th output.
sample(Ts, method=’zoh’, alpha=None)
Convert a continuous time system to discrete time
Creates a discrete-time system from a continuous-time system by sampling. Multiple methods of conver-
sion are supported.
Parameters Ts : float
Sampling period
Notes
Examples
zero()
Compute the zeros of a state space system.
xferfcn.py
Transfer function representation and functions.
This file contains the TransferFunction class and also functions that operate on transfer functions. This is the primary
representation for the python-control library.
Routines in this module:
TransferFunction.__init__ TransferFunction._truncatecoeff TransferFunction.copy TransferFunction.__str__ Trans-
ferFunction.__repr__ TransferFunction.__neg__ TransferFunction.__add__ TransferFunction.__radd__ Transfer-
Function.__sub__ TransferFunction.__rsub__ TransferFunction.__mul__ TransferFunction.__rmul__ TransferFunc-
tion.__div__ TransferFunction.__rdiv__ TransferFunction.__truediv__ TransferFunction.__rtruediv__ Transfer-
Function.evalfr TransferFunction.freqresp TransferFunction.pole TransferFunction.zero TransferFunction.feedback
TransferFunction.minreal TransferFunction.returnScipySignalLti TransferFunction._common_den _tfpolyToString
_addSISO _convertToTransferFunction
class control.xferfcn.TransferFunction(*args)
The TransferFunction class represents TF instances and functions.
The TransferFunction class is derived from the Lti parent class. It is used throught the python-control library to
represent systems in transfer function form.
The main data members are ‘num’ and ‘den’, which are 2-D lists of arrays containing MIMO numerator and
denominator coefficients. For example,
>>> num[2][5] = numpy.array([1., 4., 8.])
means that the numerator of the transfer function from the 6th input to the 3rd output is set to s^2 + 4s + 8.
Discrete time transfer functions are implemented by using the ‘dt’ class variable and setting it to something other
than ‘None’. If ‘dt’ has a non-zero value, then it must match whenever two transfer functions are combined. If
‘dt’ is set to True, the system will be treated as a discrete time system with unspecified sampling time.
evalfr(omega)
Evaluate a transfer function at a single angular frequency.
self.evalfr(omega) returns the value of the transfer function matrix with input value s = i * omega.
feedback(other=1, sign=-1)
Feedback interconnection between two LTI objects.
freqresp(omega)
Evaluate a transfer function at a list of angular frequencies.
mag, phase, omega = self.freqresp(omega)
reports the value of the magnitude, phase, and angular frequency of the transfer function matrix evaluated
at s = i * omega, where omega is a list of angular frequencies, and is a sorted version of the input omega.
horner(s)
Evaluate the systems’s transfer function for a complex variable
Returns a matrix of values evaluated at complex variable s.
minreal(tol=None)
Remove cancelling pole/zero pairs from a transfer function
pole()
Compute the poles of a transfer function.
returnScipySignalLti()
Return a list of a list of scipy.signal.lti objects.
For instance,
>>> out = tfobject.returnScipySignalLti()
>>> out[3][5]
is a signal.scipy.lti object corresponding to the transfer function from the 6th input to the 4th output.
sample(Ts, method=’zoh’, alpha=None)
Convert a continuous-time system to discrete time
Creates a discrete-time system from a continuous-time system by sampling. Multiple methods of conver-
sion are supported.
Parameters Ts : float
Sampling period
method : {“gbt”, “bilinear”, “euler”, “backward_diff”, “zoh”, “matched”}
Which method to use:
• gbt: generalized bilinear transformation
• bilinear: Tustin’s approximation (“gbt” with alpha=0.5)
Notes
Examples
zero()
Compute the zeros of a transfer function.
means that the frequency response from the 6th input to the 3rd output at the frequencies defined in omega is set
to the array above, i.e. the rows represent the outputs and the columns represent the inputs.
evalfr(omega)
Evaluate a transfer function at a single angular frequency.
self.evalfr(omega) returns the value of the frequency response at frequency omega.
Note that a “normal” FRD only returns values for which there is an entry in the omega vector. An interpo-
lating FRD can return intermediate values.
feedback(other=1, sign=-1)
Feedback interconnection between two FRD objects.
freqresp(omega)
Evaluate a transfer function at a list of angular frequencies.
mag, phase, omega = self.freqresp(omega)
reports the value of the magnitude, phase, and angular frequency of the transfer function matrix evaluated
at s = i * omega, where omega is a list of angular frequencies, and is a sorted version of the input omega.
matlab.py
MATLAB emulation functions.
This file contains a number of functions that emulate some of the functionality of MATLAB. The intent of these
functions is to provide a simple interface to the python control systems library (python-control) for people who are
familiar with the MATLAB Control Systems Toolbox (tm). Most of the functions are just calls to python-control
functions defined elsewhere. Use ‘from control.matlab import *’ in python to include all of the functions defined here.
Functions that are defined in other libraries that have the same names as their MATLAB equivalents are automatically
imported here.
The following tables give an overview of the module control.matlab. They also show the implementation
progress and the planned features of the module.
The symbols in the first column show the current state of a feature:
• * : The feature is currently implemented.
• - : The feature is not planned for implementation.
• s : A similar feature from an other library (Scipy) is imported into the module, until the feature is implemented
here.
41
Python Control Documentation, Release dev
4.3 Conversions
Examples
>>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
>>> mag, phase, omega = bode(sys)
Todo
Document these use cases
•>>> bode(sys, w)
Notes
This function is only useful for systems with invertible system matrix A.
All systems are first converted to state space form. The function then computes:
𝑔𝑎𝑖𝑛 = −𝐶 · 𝐴−1 · 𝐵 + 𝐷
Notes
If the number of states, inputs, or outputs is not specified, then the missing numbers are assumed to be 1. The
poles of the returned system will always have a magnitude less than 1.
control.matlab.evalfr(sys, x)
Evaluate the transfer function of an LTI system for a single complex number x.
To evaluate at a frequency, enter x = omega*j, where omega is the frequency in radians
Parameters sys: StateSpace or TransferFunction :
Linear system
x: scalar :
Complex number
Returns fresp: ndarray :
See also:
freqresp, bode
Notes
Examples
>>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
>>> evalfr(sys, 1j)
array([[ 44.8-21.4j]])
>>> # This is the transfer function matrix evaluated at s = i.
Todo
Add example with MIMO system
control.matlab.frd(*args)
Construct a Frequency Response Data model, or convert a system
frd models store the (measured) frequency response of a system.
This function can be called in different ways:
frd(response, freqs) Create an frd model with the given response data, in the form of complex re-
sponse vector, at matching frequency freqs [in rad/s]
frd(sys, freqs) Convert an Lti system into an frd model with data at frequencies freqs.
See also:
ss, tf
control.matlab.freqresp(sys, omega)
Frequency response of an LTI system at multiple angular frequencies.
Parameters sys: StateSpace or TransferFunction :
Linear system
omega: array_like :
List of frequencies
Returns mag: ndarray :
phase: ndarray :
omega: list, tuple, or ndarray :
See also:
evalfr, bode
Notes
This function is a wrapper for StateSpace.freqresp and TransferFunction.freqresp. The output omega is a sorted
version of the input omega.
Examples
>>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
>>> mag, phase, omega = freqresp(sys, [0.1, 1., 10.])
>>> mag
array([[[ 58.8576682 , 49.64876635, 13.40825927]]])
>>> phase
array([[[-0.05408304, -0.44563154, -0.66837155]]])
Todo
Add example with MIMO system
#>>> sys = rss(3, 2, 2) #>>> mag, phase, omega = freqresp(sys, [0.1, 1., 10.]) #>>> mag[0, 1, :] #array([
55.43747231, 42.47766549, 1.97225895]) #>>> phase[1, 0, :] #array([-0.12611087, -1.14294316, 2.5764547
]) #>>> # This is the magnitude of the frequency response from the 2nd #>>> # input to the 1st output, and the
phase (in radians) of the #>>> # frequency response from the 1st input to the 2nd output, for #>>> # s = 0.1i, i,
10i.
See also:
lsim, step, initial
Examples
Examples
As a convenience for parameters U, X0: Numbers (scalars) are converted to constant arrays with the correct
shape. The correct shape is inferred from arguments sys and T.
Parameters sys: Lti (StateSpace, or TransferFunction) :
LTI system to simulate
U: array-like or number, optional :
Input array giving input at each time T (default = 0).
If U is None or 0, a special algorithm is used. This special algorithm is faster than the
general algorithm, which is used otherwise.
T: array-like :
Time steps at which the input is defined, numbers must be (strictly monotonic) increas-
ing.
X0: array-like or number, optional :
Initial condition (default = 0).
**keywords: :
Additional keyword arguments control the solution algorithm for the
differential equations. These arguments are passed on to the func-
tion scipy.integrate.odeint(). See the documentation for
scipy.integrate.odeint() for information about these arguments.
Returns yout: array :
Response of the system.
T: array :
Time values of the output.
xout: array :
Time evolution of the state vector.
See also:
step, initial, impulse
Examples
control.matlab.margin(*args)
Calculate gain and phase margins and associated crossover frequencies
Function margin takes either 1 or 3 parameters.
Parameters sys : StateSpace or TransferFunction
Linear SISO system
mag, phase, w : array_like
Input magnitude, phase (in deg.), and frequencies (rad/sec) from bode frequency re-
sponse data
Returns gm, pm, Wcg, Wcp : float
Gain margin gm, phase margin pm (in deg), gain crossover frequency (corresponding to
phase margin) and phase crossover frequency (corresponding to gain margin), in rad/sec
of SISO open-loop. If more than one crossover frequency is detected, returns the lowest
corresponding margin.
Examples
>>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
>>> gm, pm, wg, wp = margin(sys)
margin: no magnitude crossings found
Todo
better ecample system!
#>>> gm, pm, wg, wp = margin(mag, phase, w)
control.matlab.ngrid()
Nichols chart grid
Plots a Nichols chart grid on the current axis, or creates a new chart if no plot already exists.
Parameters cl_mags : array-like (dB), optional
Array of closed-loop magnitudes defining the iso-gain lines on a custom Nichols chart.
cl_phases : array-like (degrees), optional
Array of closed-loop phases defining the iso-phase lines on a custom Nichols chart.
Must be in the range -360 < cl_phases < 0
Returns None :
control.matlab.pole(sys)
Compute system poles.
Parameters sys: StateSpace or TransferFunction :
Linear system
Returns poles: ndarray :
Array that contains the system’s poles.
Raises NotImplementedError :
when called on a TransferFunction object
See also:
zero
Notes
Notes
If the number of states, inputs, or outputs is not specified, then the missing numbers are assumed to be 1. The
poles of the returned system will always have a negative real part.
control.matlab.ss(*args)
Create a state space system.
The function accepts either 1, 4 or 5 parameters:
ss(sys) Convert a linear system into space system form. Always creates a new system, even if sys is already
a StateSpace object.
ss(A, B, C, D) Create a state space system from the matrices of its state and output equations:
𝑥˙ = 𝐴 · 𝑥 + 𝐵 · 𝑢
𝑦 =𝐶 ·𝑥+𝐷·𝑢
ss(A, B, C, D, dt) Create a discrete-time state space system from the matrices of its state and output
equations:
The matrices can be given as array like data types or strings. Everything that the constructor of
numpy.matrix accepts is permissible here too.
See also:
tf, ss2tf, tf2ss
Examples
control.matlab.ss2tf(*args)
Transform a state space system to a transfer function.
The function accepts either 1 or 4 parameters:
ss2tf(sys) Convert a linear system into space system form. Always creates a new system, even if sys is
already a StateSpace object.
ss2tf(A, B, C, D) Create a state space system from the matrices of its state and output equations.
For details see: ss()
See also:
tf, ss, tf2ss
Examples
control.matlab.ssdata(sys)
Return state space data objects for a system
Parameters sys: Lti (StateSpace, or TransferFunction) :
LTI system whose data will be returned
Examples
control.matlab.tf(*args)
Create a transfer function system. Can create MIMO systems.
The function accepts either 1 or 2 parameters:
tf(sys) Convert a linear system into transfer function form. Always creates a new system, even if sys is
already a TransferFunction object.
tf(num, den) Create a transfer function system from its numerator and denominator polynomial coeffi-
cients.
If num and den are 1D array_like objects, the function creates a SISO system.
To create a MIMO system, num and den need to be 2D nested lists of array_like objects. (A 3 dimensional
data structure in total.) (For details see note below.)
tf(num, den, dt) Create a discrete time transfer function system; dt can either be a positive number
indicating the sampling time or ‘True’ if no specific timebase is given.
See also:
ss, ss2tf, tf2ss
Notes
Todo
The next paragraph contradicts the comment in the example! Also “input” should come before “output” in the
sentence:
“from the (j+1)st output to the (i+1)st input”
num[i][j] contains the polynomial coefficients of the numerator for the transfer function from the (j+1)st
output to the (i+1)st input. den[i][j] works the same way.
The coefficients [2, 3, 4] denote the polynomial 2 · 𝑠2 + 3 · 𝑠 + 4.
Examples
control.matlab.tf2ss(*args)
Transform a transfer function to a state space system.
The function accepts either 1 or 2 parameters:
tf2ss(sys) Convert a linear system into transfer function form. Always creates a new system, even if sys is
already a TransferFunction object.
tf2ss(num, den) Create a transfer function system from its numerator and denominator polynomial coef-
ficients.
For details see: tf()
See also:
ss, tf, ss2tf
Examples
>>> num = [[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]]]
>>> den = [[[9., 8., 7.], [6., 5., 4.]], [[3., 2., 1.], [-1., -2., -3.]]]
>>> sys1 = tf2ss(num, den)
control.matlab.tfdata(sys)
Return transfer function data objects for a system
Parameters sys: Lti (StateSpace, or TransferFunction) :
LTI system whose data will be returned
Returns (num, den): numerator and denominator arrays :
Notes
Todo
The following functions should be documented in their own modules! This is only a temporary solution.
labelFreq : int
Label every nth frequency on the plot
*args, **kwargs: :
Additional options to matplotlib (color, linestyle, etc)
Returns real : array
real part of the frequency response array
imag : array
imaginary part of the frequency response array
freq : array
frequencies
Examples
>>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
>>> real, imag, freq = nyquist_plot(sys)
Examples
control.statefbk.lqr(*args, **keywords)
Linear quadratic regulator design
The lqr() function computes the optimal state feedback controller that minimizes the quadratic cost
∫︁ ∞
𝐽= 𝑥′ 𝑄𝑥 + 𝑢′ 𝑅𝑢 + 2𝑥′ 𝑁 𝑢
0
Examples
control.statefbk.ctrb(A, B)
Controllabilty matrix
Parameters A, B: array_like or string :
Dynamics and input matrix of the system
Returns C: matrix :
Controllability matrix
Examples
>>> C = ctrb(A, B)
control.statefbk.obsv(A, C)
Observability matrix
Parameters A, C: array_like or string :
Dynamics and output matrix of the system
Returns O: matrix :
Observability matrix
Examples
>>> O = obsv(A, C)
control.statefbk.gram(sys, type)
Gramian (controllability or observability)
Parameters sys: StateSpace :
State-space system to compute Gramian for
type: String :
Type of desired computation. type is either ‘c’ (controllability) or ‘o’ (observability).
Returns gram: array :
Gramian of system
Raises ValueError :
• if system is not instance of StateSpace class
• if type is not ‘c’ or ‘o’
• if system is unstable (sys.A has eigenvalues not in left half plane)
ImportError :
if slycot routin sb03md cannot be found
Examples
>>> Wc = gram(sys,'c')
>>> Wo = gram(sys,'o')
control.delay.pade(T, n=1)
Create a linear system that approximates a delay.
Return the numerator and denominator coefficients of the Pade approximation.
Parameters T : number
time delay
n : integer
order of approximation
Returns num, den : array
Polynomial coefficients of the delay model, in descending powers of s.
Notes
Based on an algorithm in Golub and van Loan, “Matrix Computation” 3rd. Ed. pp. 572-574.
control.freqplot.gangof4(P, C, omega=None)
Plot the “Gang of 4” transfer functions for a system
Generates a 2x2 plot showing the “Gang of 4” sensitivity functions [T, PS; CS, S]
Parameters P, C : Lti
Linear input/output systems (process and control)
omega : array
Range of frequencies (list or bounds) in rad/sec
Returns None :
control.ctrlutil.unwrap(angle, period=6.28)
Unwrap a phase angle to give a continuous curve
Parameters X : array_like
Input array
period : number
Input period (usually either 2‘‘*‘‘pi or 360)
Returns Y : array_like
Output array, with jumps of period/2 eliminated
Examples
𝐴𝑋𝐸 𝑇 + 𝐸𝑋𝐴𝑇 + 𝑄 = 0
where Q is a symmetric matrix and A, Q and E are square matrices of the same dimension.
control.mateqn.dlyap(A, Q, C=None, E=None)
dlyap(A,Q) solves the discrete-time Lyapunov equation
𝐴𝑋𝐴𝑇 − 𝑋 + 𝑄 = 0
where A and Q are square matrices of the same dimension. Further Q must be symmetric.
dlyap(A,Q,C) solves the Sylvester equation
𝐴𝑋𝑄𝑇 − 𝑋 + 𝐶 = 0
where A and Q are square matrices.
dlyap(A,Q,None,E) solves the generalized discrete-time Lyapunov equation
𝐴𝑋𝐴𝑇 − 𝐸𝑋𝐸 𝑇 + 𝑄 = 0
where Q is a symmetric matrix and A, Q and E are square matrices of the same dimension.
control.mateqn.care(A, B, Q, R=None, S=None, E=None)
(X,L,G) = care(A,B,Q,R=None) solves the continuous-time algebraic Riccati equation
𝐴𝑇 𝑋 + 𝑋𝐴 − 𝑋𝐵𝑅−1 𝐵 𝑇 𝑋 + 𝑄 = 0
where A and Q are square matrices of the same dimension. Further, Q and R are a symmetric matrices. If R is
None, it is set to the identity matrix. The function returns the solution X, the gain matrix G = B^T X and the
closed loop eigenvalues L, i.e., the eigenvalues of A - B G.
(X,L,G) = care(A,B,Q,R,S,E) solves the generalized continuous-time algebraic Riccati equation
𝐴𝑇 𝑋𝐸 + 𝐸 𝑇 𝑋𝐴 − (𝐸 𝑇 𝑋𝐵 + 𝑆)𝑅−1 (𝐵 𝑇 𝑋𝐸 + 𝑆 𝑇 ) + 𝑄 = 0
where A, Q and E are square matrices of the same dimension. Further, Q and R are symmetric matrices. If R is
None, it is set to the identity matrix. The function returns the solution X, the gain matrix G = R^-1 (B^T X E +
S^T) and the closed loop eigenvalues L, i.e., the eigenvalues of A - B G , E.
control.mateqn.dare(A, B, Q, R, S=None, E=None)
(X,L,G) = dare(A,B,Q,R) solves the discrete-time algebraic Riccati equation
𝐴𝑇 𝑋𝐴 − 𝑋 − 𝐴𝑇 𝑋𝐵(𝐵 𝑇 𝑋𝐵 + 𝑅)−1 𝐵 𝑇 𝑋𝐴 + 𝑄 = 0
where A and Q are square matrices of the same dimension. Further, Q is a symmetric matrix. The function
returns the solution X, the gain matrix G = (B^T X B + R)^-1 B^T X A and the closed loop eigenvalues L, i.e.,
the eigenvalues of A - B G.
(X,L,G) = dare(A,B,Q,R,S,E) solves the generalized discrete-time algebraic Riccati equation
𝐴𝑇 𝑋𝐴 − 𝐸 𝑇 𝑋𝐸 − (𝐴𝑇 𝑋𝐵 + 𝑆)(𝐵 𝑇 𝑋𝐵 + 𝑅)−1 (𝐵 𝑇 𝑋𝐴 + 𝑆 𝑇 ) + 𝑄 = 0
where A, Q and E are square matrices of the same dimension. Further, Q and R are symmetric matrices. The
function returns the solution X, the gain matrix 𝐺 = (𝐵 𝑇 𝑋𝐵 + 𝑅)−1 (𝐵 𝑇 𝑋𝐴 + 𝑆 𝑇 ) and the closed loop
eigenvalues L, i.e., the eigenvalues of A - B G , E.
Examples
67
Python Control Documentation, Release dev
68 Chapter 5. Examples
CHAPTER 6
• genindex
• search
69
Python Control Documentation, Release dev
c
control, 5
control.frdata, 38
control.lti, 33
control.matlab, 41
control.statesp, 34
control.timeresp, 24
control.xferfcn, 36
71
Python Control Documentation, Release dev
c
control, 5
control.frdata, 38
control.lti, 33
control.matlab, 41
control.statesp, 34
control.timeresp, 24
control.xferfcn, 36
73
Python Control Documentation, Release dev
B F
balred() (in module control), 30 feedback() (control.frdata.FRD method), 38
bode() (in module control.matlab), 46 feedback() (control.statesp.StateSpace method), 35
bode_plot() (in module control), 21 feedback() (control.xferfcn.TransferFunction method), 37
box_grid() (in module control.phaseplot), 29 feedback() (in module control), 12
forced_response() (in module control), 25
C FRD (class in control.frdata), 38
frd() (in module control.matlab), 49
c2d() (in module control.matlab), 46
freqresp() (control.frdata.FRD method), 38
care() (in module control), 14
freqresp() (control.statesp.StateSpace method), 35
care() (in module control.mateqn), 65
freqresp() (control.xferfcn.TransferFunction method), 37
control (module), 5
freqresp() (in module control), 17
control.frdata (module), 38
freqresp() (in module control.matlab), 49
control.lti (module), 33
control.matlab (module), 41
control.statesp (module), 34
G
control.timeresp (module), 24 gangof4() (in module control.freqplot), 64
control.xferfcn (module), 36 gangof4_plot() (in module control), 23
ctrb() (in module control), 14 gram() (in module control), 16
ctrb() (in module control.statefbk), 62 gram() (in module control.statefbk), 63
D H
damp() (in module control.matlab), 47 horner() (control.statesp.StateSpace method), 35
dare() (in module control), 15 horner() (control.xferfcn.TransferFunction method), 37
dare() (in module control.mateqn), 65 hsvd() (in module control), 31
dcgain() (in module control), 15
dcgain() (in module control.matlab), 47 I
default_frequency_range() (in module control.freqplot), impulse() (in module control.matlab), 50
23 initial() (in module control.matlab), 51
dlyap() (in module control), 15 initial_response() (in module control), 26
dlyap() (in module control.mateqn), 65 isctime() (control.lti.Lti method), 33
drss() (in module control), 8 isctime() (in module control), 8
drss() (in module control.matlab), 48 isctime() (in module control.lti), 34
isdtime() (control.lti.Lti method), 33
E isdtime() (in module control), 8
evalfr() (control.frdata.FRD method), 38 isdtime() (in module control.lti), 34
evalfr() (control.statesp.StateSpace method), 35 issys() (in module control), 9
75
Python Control Documentation, Release dev
R
returnScipySignalLti() (control.statesp.StateSpace
method), 35
returnScipySignalLti() (control.xferfcn.TransferFunction
method), 37
rlocus() (in module control.matlab), 53
root_locus() (in module control), 20
rss() (in module control.matlab), 54
S
sample() (control.statesp.StateSpace method), 35
76 Index