Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

Basic ControlSystem Symbolic

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Basic ControlSystem Symbolic

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

MATLAB BASIC CHEAT SHEET

Basics Constructing Matrices and Vectors


clc Clear command window zeros(12, 5) Make a 12 × 5 matrix of zeros
clear Clear all variables ones(12, 5) Make a 12 × 5 matrix of ones
close all Close all plots eye(5) Make a 5 × 5 identity matrix
help function Print help page for function linspace(0, 50, 1000) Make a vector with 1000 elements
% This is a comment Comments evenly spaced between 0 and 50
ctrl-c Abort the current operation 0:10 Row vector of 0, 1, . . . , 9, 10
format short Display 4 decimal places 0:0.001:50 Row vector of elements from 0 to 50
with 0.001 step
format long Display 15 decimal places

Operations on Matrices and Vectors


Defining and Changing Variables 3 * x Multiply every element of x by 3
a = 3 Define variable a to be 3 x + 2 Add 2 to every element of x
x = [1, 2, 3] Set x to be the row vector [1, 2, 3] x + y Element-wise addition of two vectors x and y
x = [1; 2; 3] Set x to be the column vector [1, 2, 3]T A * y Product of a matrix and vector
A = [1, 2, 3, 4; Set A to be a 3 × 4 matrix A * B Product of two matrices
5, 6, 7, 8; A ^ 3 Square matrix A to the third power
9, 10, 11, 12] A .^ 3 Every element of A to the third power
x(2) = 7 Change x from [1, 2, 3] to [1, 7, 3] exp(A) Compute the exponential of every element of A
A(2,1) = 0 Change A2,1 from 5 to 0 expm(A) Compute the exponential matrix of A (i.e. eA )
syms x Define variable x to be symbolic abs(A) Compute the absolute values of every element of A
double(x) Convert x from symbolic to double A' Transpose of A
subs(x) Replace all variables in the symbolic ex- inv(A) Compute the inverse of A
pression of x with their values taken
from the MATLAB workspace det(A) Compute the determinant of A
eig(A) Compute the eigenvalues of A
rank(A) Compute the rank of A
Constants
pi π = 3.141592653589793 Entries of Matrices and Vectors
NaN Not a number (i.e. 0/0) x(2:12) The 2nd to the 12th elements of x
Inf Infinity x(2:end) The 2nd to the last elements of x
x(1:3:end) Every third element of x from the first to last
Basic Arithmetic and Trigonometric Functions A(5,:) Get the 5th row of A
A(:,5) Get the 5th column of A
3*4, 7+4, 2-6, 8/3 multiply, add, subtract and divide
A(5, 1:3) Get the first to third elements in the 5th row
3^7 Compute 37

sqrt(5) Compute 5
Plotting
log(3) Compute ln(3)
plot(x,y) Plot y versus x (must be the same length)
log10(100) Compute log10 (100)
loglog(x,y) Plot y versus x on a log-log scale (both axes
abs(-5) Compute | − 5|
have a logarithmic scale)
sin(5*pi/3) Compute sin(5π/3), angle expressed in rad
semilogx(x, y) Plot y versus x with x on a log scale
cos(pi/2) Compute cos(π/2), angle expressed in rad
semilogy(x, y) Plot y versus x with y on a log scale
tan(pi/4) Compute tan(π/2), angle expressed in rad
axis equal Force the x and y axes to be scaled equally
asin(0.5) Compute arcsin(0.5), result expressed in rad
grid on Add a grid to the plot
atan(3) Compute arctan(π/2), result in rad
hold on Multiple plots on single figure
atan2(2,3) Compute arctan(2/3), result ∈ [−π, π]
figure Start a new plot
sind(300) Compute sin(300), angle expressed in deg
cosd(90) Compute cos(90), angle expressed in deg Equations and Polynomials
coeffs(x^2*x-1) Return the coefficients of a
polynomial symbolic expres-
Complex Numbers (either numeric or symbolic) sion
a = 4+i*3 define a with 4 as the real part and 3 as the imaginary solve(x^2+x==0) Compute the solution of a sym-
part bolic equation

abs(a) compute |a| (i.e. 42 + 32 ) solve([x1+x2==0;x2+6==0]) Compute the solution of a sys-
angle(a) compute arg(a) (i.e. atan2(3,4)) tem of symbolic equations

Department of Engineering, University of Ferrara https://de.unife.it Updated: June 4, 2022


MATLAB SYMBOLIC AND CONTROL SYSTEM TOOLBOXES

Laplace Transform (Symbolic) Root locus and Bode Plots


dirac(t) Dirac impulse rlocus(G) Plot the root locus of the trans-
fer function G
heaviside(t) Heaviside step function
rlocus(G,k) Plot the root locus of G with
laplace(f(t)) Compute the Laplace transform of a symbolic
given k values (k is a vector)
expression
bode(G) Plot the Bode diagrams of G
ilaplace(G(s)) Compute the inverse Laplace transform of a
(amplitude and phase)
symbolic expression
bode(G,w) Plot the Bode diagrams of G at
given frequencies w (w is a vec-
LTI Systems and Transfer Functions tor)
ctrb(A,B) Compute the controllability ma- margin(G) Plot the Bode diagrams of G
trix specifying the stability margin
obsv(A,C) Compute the observability ma- [Gm,Pm,Wpi,Wc]=margin(G) Return the gain (Gm) and phase
trix (Pm) margins and the cross fre-
ss(A,B,C,D) Get the state-space representa- quencies Wpi and Wc
tion of a LTI system
tf(num,den) Get the transfer function given
the coefficients of numerator Example: Root Locus
and denominator
s = tf('s'); % Laplace variable
tf(sys) Get the transfer function given G = (s+5)/((s+1)*(s+2)*(s+8)); % Transfer function
the ss representation of a sys- rlocus(G) % Plot the root locus of G
tem
[Num,Den]=ss2tf(A,B,C,D) Compute the coefficients of the
transfer function of the A,B,C,D
system
s=tf('s') Define the laplace s variable as
a transfer function
pole(G) Compute the poles of the trans-
fer function G
zero(G) Compute the zeroes of the trans-
fer function G
dcgain(G) Compute the DC gain of the
transfer function G (i.e. gain at
zero frequency)
damp(G) Print poles, natural frequencies
and damping factors of G

Connected Systems and Responses


parallel(G1,G2) Return the G1-G2 parallel connection
series(G1,G2) Return the G1-G2 series connection
feedback(G1,G2) Return the G1-G2 negative feedback connec- Example: Bode
tion
impulse(G) Plot the impulse response of G s = tf('s'); % Laplace variable
impulse(G,t) Plot the impulse response of G in time t (t G = (s+5)/((s+1)*(s+2)*(s+8)); % Transfer function
is a sampled vector) bode(G) % Amplitude and phase Bode diagrams

y=impulse(G) Return the impulse response of G as a col-


umn vector
step(G) Plot the step response of G Bode Diagram
0
step(G,t) Plot the step response of G in time t (t is a
sampled vector)
Magnitude (dB)

-20
y=step(G) Return the step response of G as a column
-40
vector
step(G,popt) Plot the step response of G with specified -60
time options (popt = timeoptions)
-80
stepinfo(G) Print the characteristics of the step response 0
of G
Phase (deg)

-45

PID Controllers (standard form) -90

pidstd(Kp) Return a P controller -135

pidstd(Kp,Ti) Return a PI controller -180


10-2 10-1 100 101 102
pidstd(Kp,Inf,Td) Return a PD controller Frequency (rad/s)
pidstd(Kp,Ti,Td) Return a PID controller

Department of Engineering, University of Ferrara https://de.unife.it Updated: June 4, 2022

You might also like