Post

Matlab Control Systems Cheat Sheet

A cheat sheet for various control system functions used in the course ENEL809 but can be used for general reference.

Matlab Functions

Symbolic Toolbox

FunctionDescription
numden(sym_eqn)[N, D]Extracts the numerator and denominator of a symbolic equation
simplify(sym_eqn)[eqn]Simplifies the symbolic equation
expand(sym_eqn)[eqn]Expands the symbolic equation
solve([eqn ..], [var ..])Solves the equations(s) for the given variable(s) symbolically
vpasolve([eqn ..], [var ..])Solves the equations(s) for the given variable(s) numerically
laplace(sym_ft)[Fs]Finds the Laplace transform of the given symbolic equation
ilaplace(sym_Fs)[tf]Finds the inverse Laplace transform of the given symbolic equation
ztrans(sym_ft)[Fz]Finds the z-transform of the given symbolic equation
iztrans(sym_ft)[Fz]Finds the inverse z-transform of the given symbolic equation.
Use syms k positive integer to avoid a cryptic answer. 
limit(fx, x, a)[val]Returns the limit of the function fx as x approaches a. Useful to check if value is NaN meaning the function diverges to infinity.
c2d(tf, Ts, method)[tf]Converts continuous-time dynamic system to discrete time with the chosen method: ‘zoh’, ‘foh’, ‘impulse’, ‘tustin’, ‘matched’, ‘least-squares’, ‘damped’. Defaults to ‘zoh’ which is recommended, if method is omitted.

Matrix Operations

FunctionDescription
eye(N, M)[mat]Creates an identity matrix of N by M size
nan(N, M)[mat]Creates a NaN matrix of N by M size
zeros(N, M)[mat]Creates a zero matrix of N by M size
size(mat)[row, col]Returns the size of the matrix

Transfer Functions

Using s = tf(’s’) is a good way of making future equations using s become transfer function objects.

FunctionDescription
zpk(eqn)Factorizes the transfer function into a zero-pole-gain model
c2d(tf)Converts a continuous transfer function to a discrete one
tf(N, D)[tf] 
tf(N, D, Ts)[tf]Create a transfer function with the given numerator and denominator coefficients. May also need sym2ploy(N) and sym2ploy(D) before using tf(N, D). Adding the sampling time Ts creates a discrete-time transfer function
bode(tf)Create a bode plot of the given transfer function
feedback(Gs, Hs)[tf]Adds closed loop feedback Hs to the transfer function Gs
step(tf)Creates a plot of the transfer functions step response
stepinfo(tf)[obj]Returns a object with all the step response information
drmodel(N)[N, D]Generates a random stable test models of Nth order
drmodel(N)[A, B, C, D]Generates a random stable test models of Nth order
drmodel(N, P)[N, D]Generates a random stable test models of Nth order, P outputs
drmodel(N, P)[A, B, C, D]Generates a random stable test models of Nth order, P
drmodel(N, P, M)[A, B, C, D]Generates a random stable test models of Nth order, P outputs and M inputs
evalfr(tf, x)Evaluates frequency response at a single frequency
dcgain(tf)Computes the steady-state gain of the dynamic system (caution: does return a finite value for an unstable system). Should be used in conjunction with isstable(tf)
residues(N, D)[N, D, K]Partial fraction expansion
residuesz(N, D)[N, D, K]Z-transform partial fraction expansion
pzmap(tf)Plot the pole-zero map of a dynamic system
eig(tf) or pole(tf)The poles of the system, showing it’s stability
isstable(tf)[bool]Returns if the transfer function is stable or not

State-Space

FunctionDescription
abcdchk()Check state-space matrices for the correct dimensions
ss2tf(A, B, C, D)[tf]Converts a state-space model to a transfer function

Misc

FunctionDescription
pretty(eqn)Turns a command line equation in a more human readable equation
interp1(X, V, Xi)[Vi]1D interpolation, given the input vector X with the output vector V determine Vi from the known Xi
tic; <exp>; toc;Times the execution of the expression
This post is licensed under CC BY 4.0 by the author.