MATLAB Compatibility Module¶
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 (pythoncontrol) for people who are familiar with the MATLAB Control Systems Toolbox (tm). Most of the functions are just calls to pythoncontrol 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.
Creating linear models¶
*  tf() 
create transfer function (TF) models 
zpk  create zero/pole/gain (ZPK) models.  
*  ss() 
create statespace (SS) models 
dss  create descriptor statespace models  
delayss  create statespace models with delayed terms  
*  frd() 
create frequency response data (FRD) models 
lti/exp  create pure continuoustime delays (TF and ZPK only)  
filt  specify digital filters  
  lti/set  set/modify properties of LTI models 
  setdelaymodel  specify internal delay model (state space only) 
*  rss() 
create a random continuous state space model 
*  drss() 
create a random discrete state space model 
Data extraction¶
*  tfdata() 
extract numerators and denominators 
lti/zpkdata  extract zero/pole/gain data  
lti/ssdata  extract statespace matrices  
lti/dssdata  descriptor version of SSDATA  
frd/frdata  extract frequency response data  
lti/get  access values of LTI model properties  
ss/getDelayModel  access internal delay model (state space) 
Conversions¶
*  tf() 
conversion to transfer function 
zpk  conversion to zero/pole/gain  
*  ss() 
conversion to state space 
*  frd() 
conversion to frequency data 
*  c2d() 
continuous to discrete conversion 
d2c  discrete to continuous conversion  
d2d  resample discretetime model  
upsample  upsample discretetime LTI systems  
*  ss2tf() 
state space to transfer function 
s  ss2zpk  transfer function to zeropolegain 
*  tf2ss() 
transfer function to state space 
s  tf2zpk  transfer function to zeropolegain 
s  zpk2ss  zeropolegain to state space 
s  zpk2tf  zeropolegain to transfer function 
System interconnections¶
*  append() 
group LTI models by appending inputs/outputs 
*  parallel() 
connect LTI models in parallel
(see also overloaded + ) 
*  series() 
connect LTI models in series
(see also overloaded * ) 
*  feedback() 
connect lti models with a feedback loop 
lti/lft  generalized feedback interconnection  
*  :func:’~bdalg.connect’  arbitrary interconnection of lti models 
sumblk  summing junction (for use with connect)  
strseq  builds sequence of indexed strings (for I/O naming) 
System gain and dynamics¶
*  dcgain() 
steadystate (D.C.) gain 
lti/bandwidth  system bandwidth  
lti/norm  h2 and Hinfinity norms of LTI models  
*  pole() 
system poles 
*  zero() 
system (transmission) zeros 
lti/order  model order (number of states)  
*  pzmap() 
polezero map (TF only) 
lti/iopzmap  input/output polezero map  
*  damp() 
natural frequency, damping of system poles 
esort  sort continuous poles by real part  
dsort  sort discrete poles by magnitude  
lti/stabsep  stable/unstable decomposition  
lti/modsep  regionbased modal decomposition 
Timedomain analysis¶
*  step() 
step response 
stepinfo  step response characteristics  
*  impulse() 
impulse response 
*  initial() 
free response with initial conditions 
*  lsim() 
response to userdefined input signal 
lsiminfo  linear response characteristics  
gensig  generate input signal for LSIM  
covar  covariance of response to white noise 
Frequencydomain analysis¶
*  bode() 
Bode plot of the frequency response 
lti/bodemag  Bode magnitude diagram only  
sigma  singular value frequency plot  
*  nyquist() 
Nyquist plot 
*  nichols() 
Nichols plot 
*  margin() 
gain and phase margins 
lti/allmargin  all crossover frequencies and margins  
*  freqresp() 
frequency response over a frequency grid 
*  evalfr() 
frequency response at single frequency 
Model simplification¶
*  minreal() 
minimal realization; pole/zero cancellation 
ss/sminreal  structurally minimal realization  
*  hsvd() 
hankel singular values (state contributions) 
*  balred() 
reducedorder approximations of LTI models 
*  modred() 
model order reduction 
Compensator design¶
*  rlocus() 
evans root locus 
*  place() 
pole placement 
estim  form estimator given estimator gain  
reg  form regulator given statefeedback and estimator gains 
LQR/LQG design¶
ss/lqg  singlestep LQG design  
*  lqr() 
linear quadratic (LQ) statefbk regulator 
dlqr  discretetime LQ statefeedback regulator  
lqry  LQ regulator with output weighting  
lqrd  discrete LQ regulator for continuous plant  
ss/lqi  LinearQuadraticIntegral (LQI) controller  
ss/kalman  Kalman state estimator  
ss/kalmd  discrete Kalman estimator for cts plant  
ss/lqgreg  build LQG regulator from LQ gain and Kalman estimator  
ss/lqgtrack  build LQG servocontroller  
augstate  augment output by appending states 
Statespace (SS) models¶
*  rss() 
random stable ctstime statespace models 
*  drss() 
random stable disctime statespace models 
ss2ss  state coordinate transformation  
canon  canonical forms of statespace models  
*  ctrb() 
controllability matrix 
*  obsv() 
observability matrix 
*  gram() 
controllability and observability gramians 
ss/prescale  optimal scaling of statespace models.  
balreal  gramianbased input/output balancing  
ss/xperm  reorder states. 
Frequency response data (FRD) models¶
frd/chgunits  change frequency vector units  
frd/fcat  merge frequency responses  
frd/fselect  select frequency range or subgrid  
frd/fnorm  peak gain as a function of frequency  
frd/abs  entrywise magnitude of frequency response  
frd/real  real part of the frequency response  
frd/imag  imaginary part of the frequency response  
frd/interp  interpolate frequency response data  
mag2db  convert magnitude to decibels (dB)  
db2mag  convert decibels (dB) to magnitude 
Time delays¶
lti/hasdelay  true for models with time delays  
lti/totaldelay  total delay between each input/output pair  
lti/delay2z  replace delays by poles at z=0 or FRD phase shift  
*  pade() 
pade approximation of time delays 
Model dimensions and characteristics¶
class  model type (‘tf’, ‘zpk’, ‘ss’, or ‘frd’)  
isa  test if model is of given type  
tf/size  model sizes  
lti/ndims  number of dimensions  
lti/isempty  true for empty models  
lti/isct  true for continuoustime models  
lti/isdt  true for discretetime models  
lti/isproper  true for proper models  
lti/issiso  true for singleinput/singleoutput models  
lti/isstable  true for models with stable dynamics  
lti/reshape  reshape array of linear models 
Overloaded arithmetic operations¶
*  + and   add, subtract systems (parallel connection) 
*  *  multiply systems (series connection) 
/  right divide – sys1*inv(sys2)  
  \  left divide – inv(sys1)*sys2 
^  powers of a given system  
‘  pertransposition  
.’  transposition of input/output map  
.*  elementbyelement multiplication  
[..]  concatenate models along inputs or outputs  
lti/stack  stack models/arrays along some dimension  
lti/inv  inverse of an LTI system  
lti/conj  complex conjugation of model coefficients 
Matrix equation solvers and linear algebra¶
*  lyap() 
solve continuoustime Lyapunov equations 
*  dlyap() 
solve discretetime Lyapunov equations 
lyapchol, dlyapchol  squareroot Lyapunov solvers  
*  care() 
solve continuoustime algebraic Riccati equations 
*  dare() 
solve disctime algebraic Riccati equations 
gcare, gdare  generalized Riccati solvers  
bdschur  block diagonalization of a square matrix 
Additional functions¶
*  gangof4() 
generate the Gang of 4 sensitivity plots 
*  linspace() 
generate a set of numbers that are linearly spaced 
*  logspace() 
generate a set of numbers that are logarithmically spaced 
*  unwrap() 
unwrap phase angle to give continuous curve 

control.matlab.
bode
(*args, **keywords)¶ Bode plot of the frequency response
Plots a bode gain and phase diagram
Parameters: sys : Lti, or list of Lti
System for which the Bode response is plotted and give. Optionally a list of systems can be entered, or several systems can be specified (i.e. several parameters). The sys arguments may also be interspersed with format strings. A frequency argument (array_like) may also be added, some examples: * >>> bode(sys, w) # one system, freq vector * >>> bode(sys1, sys2, ..., sysN) # several systems * >>> bode(sys1, sys2, ..., sysN, w) * >>> bode(sys1, ‘plotstyle1’, ..., sysN, ‘plotstyleN’) # + plot formats
omega: freq_range :
Range of frequencies in rad/s
dB : boolean
If True, plot result in dB
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
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)
>>> bode(sys1, sys2, ..., sysN)
>>> bode(sys1, sys2, ..., sysN, w)
>>> bode(sys1, 'plotstyle1', ..., sysN, 'plotstyleN')

control.matlab.
c2d
(sysc, Ts, method='zoh')¶ Return a discretetime system
Parameters: sysc: Lti (StateSpace or TransferFunction), continuous :
System to be converted
Ts: number :
Sample time for the conversion
method: string, optional :
Method to be applied, ‘zoh’ Zeroorder hold on the inputs (default) ‘foh’ Firstorder hold, currently not implemented ‘impulse’ Impulseinvariant discretization, currently not implemented ‘tustin’ Bilinear (Tustin) approximation, only SISO ‘matched’ Matched polezero method, only SISO

control.matlab.
damp
(sys, doprint=True)¶ Compute natural frequency, damping and poles of a system
The function takes 1 or 2 parameters
Parameters: sys: Lti (StateSpace or TransferFunction) :
A linear system object
doprint: :
if true, print table with values
Returns: wn: array :
Natural frequencies of the poles
damping: array :
Damping values
poles: array :
Pole locations
See also

control.matlab.
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: arraylike :
A linear system in state space form.
Z, P, k: arraylike, arraylike, number :
A linear system in zero, pole, gain form.
num, den: arraylike :
A linear system in transfer function form.
sys: Lti (StateSpace or TransferFunction) :
A linear system object.
Returns: gain: matrix :
The gain of each output versus each input:
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:

control.matlab.
drss
(states=1, outputs=1, inputs=1)¶ Create a stable discrete random state space object.
Parameters: states: integer :
Number of state variables
inputs: integer :
Number of system inputs
outputs: integer :
Number of system outputs
Returns: sys: StateSpace :
The randomly created linear system
Raises: ValueError :
if any input is not a positive integer
See also
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 :
Notes
This function is a wrapper for StateSpace.evalfr and TransferFunction.evalfr.
Examples
>>> sys = ss("1. 2; 3. 4", "5.; 7", "6. 8", "9.") >>> evalfr(sys, 1j) array([[ 44.821.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 response vector, at matching frequency freqs [in rad/s]
frd(sys, freqs)
 Convert an Lti system into an frd model with data at frequencies freqs.
Parameters: response: array_like, or list :
complex vector with the system response
freq: array_lik or lis :
vector with frequencies
sys: Lti (StateSpace or TransferFunction) :
A linear system
Returns: sys: FRD :
New frequency response system

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 :
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.matlab.
impulse
(sys, T=None, input=0, output=None, **keywords)¶ Impulse response of a linear system
If the system has multiple inputs or outputs (MIMO), one input has to be selected for the simulation. Optionally, one output may be selected. If no selection is made for the output, all outputs are given. The parameters input and output do this. All other inputs are set to 0, all other outputs are ignored.
Parameters: sys: StateSpace, TransferFunction :
LTI system to simulate
T: arraylike object, optional :
Time vector (argument is autocomputed if not given)
input: int :
Index of the input that will be used in this simulation.
output: int :
Index of the output that will be used in this simulation.
**keywords: :
Additional keyword arguments control the solution algorithm for the differential equations. These arguments are passed on to the function
lsim()
, which in turn passes them on toscipy.integrate.odeint()
. See the documentation forscipy.integrate.odeint()
for information about these arguments.Returns: yout: array :
Response of the system
T: array :
Time values of the output
Examples
>>> yout, T = impulse(sys, T)

control.matlab.
initial
(sys, T=None, X0=0.0, input=None, output=None, **keywords)¶ Initial condition response of a linear system
If the system has multiple outputs (?IMO), optionally, one output may be selected. If no selection is made for the output, all outputs are given.
Parameters: sys: StateSpace, or TransferFunction :
LTI system to simulate
T: arraylike object, optional :
Time vector (argument is autocomputed if not given)
X0: arraylike object or number, optional :
Initial condition (default = 0)
Numbers are converted to constant arrays with the correct shape.
input: int :
This input is ignored, but present for compatibility with step and impulse.
output: int :
If given, index of the output that is returned by this simulation.
**keywords: :
Additional keyword arguments control the solution algorithm for the differential equations. These arguments are passed on to the function
lsim()
, which in turn passes them on toscipy.integrate.odeint()
. See the documentation forscipy.integrate.odeint()
for information about these arguments.Returns: yout: array :
Response of the system
T: array :
Time values of the output
Examples
>>> yout, T = initial(sys, T, X0)

control.matlab.
lsim
(sys, U=0.0, T=None, X0=0.0, **keywords)¶ Simulate the output of a linear system.
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: arraylike or number, optional :
Input array giving input at each time T (default = 0).
If U is
None
or0
, a special algorithm is used. This special algorithm is faster than the general algorithm, which is used otherwise.T: arraylike :
Time steps at which the input is defined, numbers must be (strictly monotonic) increasing.
X0: arraylike 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 function
scipy.integrate.odeint()
. See the documentation forscipy.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.
Examples
>>> yout, T, xout = lsim(sys, U, T, X0)

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 response 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 openloop. 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 : arraylike (dB), optional
Array of closedloop magnitudes defining the isogain lines on a custom Nichols chart.
cl_phases : arraylike (degrees), optional
Array of closedloop phases defining the isophase 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
Notes
This function is a wrapper for StateSpace.pole and TransferFunction.pole.

control.matlab.
rlocus
(sys, klist=None, **keywords)¶ Root locus plot
The rootlocus plot has a callback function that prints pole location, gain and damping to the Python consol on mouseclicks on the rootlocus graph.
Parameters: sys: StateSpace or TransferFunction :
Linear system
klist: iterable, optional :
optional list of gains
xlim : control of xaxis range, normally with tuple, for
other options, see matplotlib.axes
ylim : control of yaxis range
Plot : boolean (default = True)
If True, plot magnitude and phase
PrintGain: boolean (default = True) :
If True, report mouse clicks when close to the rootlocus branches, calculate gain, damping and print
Returns: rlist: :
list of roots for each gain
klist: :
list of gains used to compute roots

control.matlab.
rss
(states=1, outputs=1, inputs=1)¶ Create a stable continuous random state space object.
Parameters: states: integer :
Number of state variables
inputs: integer :
Number of system inputs
outputs: integer :
Number of system outputs
Returns: sys: StateSpace :
The randomly created linear system
Raises: ValueError :
if any input is not a positive integer
See also
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 discretetime 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.
Parameters: sys: Lti (StateSpace or TransferFunction) :
A linear system
A: array_like or string :
System matrix
B: array_like or string :
Control matrix
C: array_like or string :
Output matrix
D: array_like or string :
Feed forward matrix
dt: If present, specifies the sampling period and a discrete time :
system is created
Returns: out: StateSpace :
The new linear system
Raises: ValueError :
if matrix sizes are not selfconsistent
Examples
>>> # Create a StateSpace object from four "matrices". >>> sys1 = ss("1. 2; 3. 4", "5.; 7", "6. 8", "9.")
>>> # Convert a TransferFunction to a StateSpace object. >>> sys_tf = tf([2.], [1., 3]) >>> sys2 = ss(sys_tf)

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()
Parameters: sys: StateSpace :
A linear system
A: array_like or string :
System matrix
B: array_like or string :
Control matrix
C: array_like or string :
Output matrix
D: array_like or string :
Feedthrough matrix
Returns: out: TransferFunction :
New linear system in transfer function form
Raises: ValueError :
if matrix sizes are not selfconsistent, or if an invalid number of arguments is passed in
TypeError :
if sys is not a StateSpace object
Examples
>>> A = [[1., 2], [3, 4]] >>> B = [[5.], [7]] >>> C = [[6., 8]] >>> D = [[9.]] >>> sys1 = ss2tf(A, B, C, D)
>>> sys_ss = ss(A, B, C, D) >>> sys2 = ss2tf(sys_ss)

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
Returns: (A, B, C, D): list of matrices :
State space data for the system

control.matlab.
step
(sys, T=None, X0=0.0, input=0, output=None, **keywords)¶ Step response of a linear system
If the system has multiple inputs or outputs (MIMO), one input has to be selected for the simulation. Optionally, one output may be selected. If no selection is made for the output, all outputs are given. The parameters input and output do this. All other inputs are set to 0, all other outputs are ignored.
Parameters: sys: StateSpace, or TransferFunction :
LTI system to simulate
T: arraylike object, optional :
Time vector (argument is autocomputed if not given)
X0: arraylike or number, optional :
Initial condition (default = 0)
Numbers are converted to constant arrays with the correct shape.
input: int :
Index of the input that will be used in this simulation.
output: int :
If given, index of the output that is returned by this simulation.
**keywords: :
Additional keyword arguments control the solution algorithm for the differential equations. These arguments are passed on to the function
control.forced_response()
, which in turn passes them on toscipy.integrate.odeint()
. See the documentation forscipy.integrate.odeint()
for information about these arguments.Returns: yout: array :
Response of the system
T: array :
Time values of the output
Examples
>>> yout, T = step(sys, T, X0)

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 coefficients.
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.
Parameters: sys: Lti (StateSpace or TransferFunction) :
A linear system
num: array_like, or list of list of array_like :
Polynomial coefficients of the numerator
den: array_like, or list of list of array_like :
Polynomial coefficients of the denominator
Returns: out: TransferFunction :
The new linear system
Raises: ValueError :
if num and den have invalid or unequal dimensions
TypeError :
if num or den are of incorrect type
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 .Examples
>>> # Create a MIMO transfer function object >>> # The transfer function from the 2nd input to the 1st output is >>> # (3s + 4) / (6s^2 + 5s + 4). >>> num = [[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]]] >>> den = [[[9., 8., 7.], [6., 5., 4.]], [[3., 2., 1.], [1., 2., 3.]]] >>> sys1 = tf(num, den)
>>> # Convert a StateSpace to a TransferFunction object. >>> sys_ss = ss("1. 2; 3. 4", "5.; 7", "6. 8", "9.") >>> sys2 = tf(sys1)

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 coefficients.
For details see:
tf()
Parameters: sys: Lti (StateSpace or TransferFunction) :
A linear system
num: array_like, or list of list of array_like :
Polynomial coefficients of the numerator
den: array_like, or list of list of array_like :
Polynomial coefficients of the denominator
Returns: out: StateSpace :
New linear system in state space form
Raises: ValueError :
if num and den have invalid or unequal dimensions, or if an invalid number of arguments is passed in
TypeError :
if num or den are of incorrect type, or if sys is not a TransferFunction object
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)
>>> sys_tf = tf(num, den) >>> sys2 = tf2ss(sys_tf)

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 :
Transfer function coefficients (SISO only)

control.matlab.
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
Notes
This function is a wrapper for StateSpace.zero and TransferFunction.zero.
Todo
The following functions should be documented in their own modules! This is only a temporary solution.

control.pzmap.
pzmap
(sys, Plot=True, title='Pole Zero Map')¶ Plot a pole/zero map for a linear system.
Parameters: sys: Lti (StateSpace or TransferFunction) :
Linear system for which poles and zeros are computed.
Plot: bool :
If
True
a graph is generated with Matplotlib, otherwise the poles and zeros are only computed and returned.Returns: pole: array :
The systems poles
zeros: array :
The system’s zeros.

control.freqplot.
nyquist
(syslist, omega=None, Plot=True, color='b', labelFreq=0, *args, **kwargs)¶ Nyquist plot for a system
Plots a Nyquist plot for the system over a (optional) frequency range.
Parameters: syslist : list of Lti
List of linear input/output systems (single system is OK)
omega : freq_range
Range of frequencies (list or bounds) in rad/sec
Plot : boolean
If True, plot magnitude
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)

control.nichols.
nichols
(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 Nicholschart grid. Default is True.
Returns: None :

control.statefbk.
place
(A, B, p)¶ Place closed loop eigenvalues
Parameters: A : 2d array
Dynamics matrix
B : 2d array
Input matrix
p : 1d list
Desired eigenvalue locations
Returns: K : 2d array
Gains such that A  B K has given eigenvalues
Examples
>>> A = [[1, 1], [0, 1]] >>> B = [[0], [1]] >>> K = place(A, B, [2, 5])

control.statefbk.
lqr
(*args, **keywords)¶ Linear quadratic regulator design
The lqr() function computes the optimal state feedback controller that minimizes the quadratic cost
The function can be called with either 3, 4, or 5 arguments:
lqr(sys, Q, R)
lqr(sys, Q, R, N)
lqr(A, B, Q, R)
lqr(A, B, Q, R, N)
Parameters: A, B: 2d array :
Dynamics and input matrices
sys: Lti (StateSpace or TransferFunction) :
Linear I/O system
Q, R: 2d array :
State and input weight matrices
N: 2d array, optional :
Cross weight matrix
Returns: K: 2d array :
State feedback gains
S: 2d array :
Solution to Riccati equation
E: 1d array :
Eigenvalues of the closed loop system
Examples
>>> K, S, E = lqr(sys, Q, R, [N]) >>> K, S, E = lqr(A, B, Q, R, [N])

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 :
Statespace 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. 572574.

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
>>> import numpy as np >>> X = [5.74, 5.97, 6.19, 0.13, 0.35, 0.57] >>> unwrap(X, period=2 * np.pi) [5.74, 5.97, 6.19, 6.413185307179586, 6.633185307179586, 6.8531853071795865]

control.mateqn.
lyap
(A, Q, C=None, E=None)¶ X = lyap(A,Q) solves the continuoustime Lyapunov equation
where A and Q are square matrices of the same dimension. Further, Q must be symmetric.
X = lyap(A,Q,C) solves the Sylvester equation
where A and Q are square matrices.
X = lyap(A,Q,None,E) solves the generalized continuoustime Lyapunov equation
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 discretetime Lyapunov equation
where A and Q are square matrices of the same dimension. Further Q must be symmetric.
dlyap(A,Q,C) solves the Sylvester equation
where A and Q are square matrices.
dlyap(A,Q,None,E) solves the generalized discretetime Lyapunov equation
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 continuoustime algebraic Riccati equation
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 continuoustime algebraic Riccati equation
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 discretetime algebraic Riccati equation
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 discretetime algebraic Riccati equation
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 and the closed loop eigenvalues L, i.e., the eigenvalues of A  B G , E.