



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
MATLAB Control Theory Cheat Sheet
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!
s = tf('s') sys = (s-1)/(s+1); Create special variable s that you can use in a rational expression to create a continuous-time transfer function model. num = [5]; den = [1 1 3]; sys = tf(num,den) Create a continuous-time transfer function (TF) model by specifying numerator (num) and denominator (den) properties. z = tf('z',ts) sys = (z-1)/(z+1); sys = tf(num,den,ts) Create a special variable z that you can use in a rational expression to create a discrete- time transfer function with sample time ts. Create a discrete-time transfer function model, setting the numerator (num), denominator (den), and sample time (ts) properties. L = 1/(S+5); (^) Sensitivity TF. S_s = feedback(1, L); T_s = feedback(L, 1); % Or %= 1 - S % T(jw) + S(jw) = 1 Complementary Sensitivity or Co-Sensitivity TF. See functions: getSensitivity and getCompSensitivity for additional information, and https://www.mathworks.com/help/control/ ug/using-feedback-to-close-feedback- loops.html for ways of closing feedback loops with the feedback command. C = pid(Kp,Ki,Kd,tf) PID Controller with time constant. sys = filt(num,den) ts = 0.5; sys = filt(num,den,ts) Specify discrete transfer functions in DSP format. ts is unspecified. With ts specified.
stepplot(sys) (^) Plots step response of dynamic system. [y,tOut] = step(sys) (^) Returns the step response (y) and time [y,tOut] = step(sys,tFinal) (^) vector tOut. [y,tOut] = t0 is the initial time (when not specified step(sys,[t0,tFinal]) assumed to be zero). [y,tOut] = step(sys,t) (^) tFinal the final time. t is a time vector. h = stepplot(sys) h = stepplot(sys1,...,sysN) Plot step response with additional plot customization options. S_info = stepinfo(sys) S_info = stepinfo(y,t) Gives step response data like rise time, undershoot, setting time, etc. Can either use a sym or specify vectors y and t [length(y) = length(t)]. impulse(sys) Impulse response plot of dynamic system. Same syntax as step. impulseplot (^) Same syntax as stepplot. lsim(sys,u,t) lsim(sys,u,t,x0) Plot simulated time response of dynamic system to arbitrary inputs. Allows you to choose the input u, time vector t, and initial state vector x0. h = lsimplot(sys) h = lsimplot(sys,u,t) h = lsimplot(All_sys,u,t) Very similar syntax as stepplot. Can plot multiple systems. sys1, LineSpec1, sys2, LineSpec2.
P = pole(sys) (^) Returns the poles of a given system. Z = zero(sys) [Z,gain] = zero(sys) Returns the zeros of a given system. Returns the system zero-pole-gain. [p,z = pzmap(sys) pzplot(sys) Return the system poles and zeros of the dynamic system model sys. Plot pole-zero map of dynamic system sys with customization options. % z = zeros % p = poles % k = gain sys = zpk(z,p,k) sys = zpk(z,p,k,ts) sys = zpk(z,p,k,ltiSys) Creates a continuous-time zero-pole-gain model with zeros and poles specified as vectors and the scalar value of gain. The output sys is a zpk model object storing the model data. Set zeros or poles to [] for systems without zeros or poles. These two inputs need not have equal length, and the model need not be proper (that is, have an excess of poles). If you want a discrete zpk model. If you want to specify properties inherited from the dynamic system model include ltiSys. [z,p,k] = zpkdata(sys) [z,p,k,Ts] = zpkdata(sys) [z,p,k,Ts,covz,covp,covk] = zpkdata(sys) Access zero-pole-gain data Returns the zeros z, poles p, and gain(s) k of the zero-pole-gain, sample time Ts, covariances of the zeros, poles and gainmodel of the identified model sys. iopzmap(sys) (^) Plot pole-zero map for I/O pairs of models. iopzplot(sys) Plot pole-zero map for I/O pairs with additional plot customization options. bode(sys) [mag,phase,wout] = bode(sys) Plot frequency response of dynamic system model sys. Compute the frequency response of dynamic system model sys, and return the magnitude and phase of the response at each frequency in the vector wout. bodeplot(sys) Plot Bode frequency response with additional plot customization options. margin(sys) [Gm,Pm,Wcg,Wcp] = margin(sys) Lets you plot and find the Gain margin, phase margin, and crossover frequencies. allmargin(sys) % open loop system Gives relevant margin info like rise time, GainMargin, PhaseMargin, DelayMargin, system stability, etc. rlocus(sys) [r,k] = rlocus(sys) Root locus plot of dynamic system. Use grid on for the relevant grid. Calculate the root locus of SISO model sys and return the resulting vector of feedback gains k and corresponding complex root locations r. rlocusplot(sys) (^) Plot root locus and return plot handle. nyquist(sys) [re,im,wout] = nyquist(sys) Nyquist plot of frequency response. Use grid on for the relevant grid. nyquistplot(sys) Nyquist plot with additional plot customization options.
nichols(sys) [mag,phase,wout] = nichols(sys) Nichols chart of frequency response. Use grid on for the relevant grid. Compute the frequency response of dynamic system model sys and returns the magnitude and phase of the response at each frequency in the vector wout nicholsplot(sys) Plot^ Nichols^ frequency^ responses^ with^ additional plot customization options. ltiview(sys) Opens^ the^ Linear^ Time^ Invariant^ (LTI)^ Viewer^ GUI for a given system. controlSystemDesigner Interactively design and analyze SISO controllers with the Control System Designer app, using automated tuning methods. damp(sys) [wn,zeta,p] = damp(sys) Displays the damping ratio, natural frequency, and time constant of the poles of the linear model sys Returns the natural frequencies wn, and damping ratios zeta of the poles of sys, and the sys poles, p.
Continuous-time (CT) SS ๐ฅฬ = ๐ด๐ฅฬ + ๐ต๐ข ๐ฆ = ๐ถ๐ฅฬ + ๐ท๐ข Discrete-time (DT) SS ๐ฅฬ [๐ + 1] = ๐ด๐ฅฬ [๐] + ๐ต๐ข[๐] ๐ฆ[๐] = ๐ถ๐ฅฬ [๐] + ๐ท๐ข[๐] x is the state vector. u is the input vector. y is the output vector. A is the system matrix. B is the input matrix. C is output Matrix. D is the feedforward or direct transmission matrix. sys = ss(A,B,C,D) sys = ss(A,B,C,D,ltiSys) sys = ss(ssSys,'minimal') Creates a continuous-time state-space model object. Creates a state-space model with properties such as input and output names, internal delays and sample time values inherited from the model ltisys. Returns the minimal state-space realization with no uncontrollable or unobservable states. [a,b,c,d,Ts] = ssdata(sys) Access state-space model data. For viewing TF data see help tfdata. [num,den] = tfdata(tf(sys)) syms s; I = eye(size(A)); H_s = C(sI-A)^-1B+D* Converts the state space model represented by sys to transfer function and returns its numerator and denominator coefficients.Creates a symbol expression. Useful for checking SISO, SIMO, MISO, and MIMO hand calculations. [A,B,C,D] = ssdatass(sys)); Converts the transfer function represented by sys to state space model and extracts its A, B,C and D matrices sys = ss(A,B,C,D,ts) (^) Creates the discrete-time state-space model object with the sample time ts (in seconds). Set ts = - 1 to leave the sample time to unspecified. lsimplot(sys,u,t,x0); [t, y] = lsim(sys,u,t,x0) Plot simulated time response of dynamic system with t (time samples) and x0 (initial state values). io = linio(block,port)lins ys = linearize(model,io) Create an input perturbation analysis point for the signal that originates from the specified output port of a Simulinkยฎ block. Linearize the Simulink model using the specified analysis point(s).
Co = ctrb(sys) = ctrb(sys.A,sys.B); Co = ctrb(A,B) rank(Co) Returns the Controllability matrix Co. If full rank or ๐๐๐ก(๐ถ๐) โ 0 then the system is Controllable. Co = [B AB A^2B ... A^(n-1)B]. Ob = obsv(sys) (^) Returns the Observability matrix Ob. If full rank = obsv(sys.A,sys.C); or ๐๐๐ก(๐๐) โ 0 then the system is Observable. Ob = obsv(A,C) (^) Ob = [C; CA; CA^2; โฆ CA^(n-1)]. rank(Ob) H = ObCo % note the order. It matters.* Hankel Matrix. If full rank or ๐๐๐ก(๐ป) โ 0 then the system is a minimal realization. H = hankel(c) Returns^ a^ square^ Hankel^ Matrix^ where^ c^ defines the first column of the matrix, and the elements are zero below the main anti-diagonal. H = hankel(c,r) Returns a Hankel matrix with c as its first column and r as its last row. sysr = minreal(sys) [sysr,U] = minreal(sys,tol) Minimal realization or pole-zero cancellation. U such that (UAU', UB, CU') is a Kalman decomposition of (A,B,C).
When plotting (s-plane) the poles (xโs) and zeros (oโs) of a system you want the poles (s) to be in the light half plane (LHP). ๐ = ๐ + ๐๐ = ๐น๐(๐) + ๐ฐ๐(๐). ๐ = ๐ + ๐๐ is complex. ๐ = ๐ is simple. ๐ = ๐๐ is purely imaginary. Asymptoticly Stable / Stable ๐ ๐[๐ ๐] = ๐๐ < 0
Marginally Stable if ๐๐ = 0 for any simple pole and poles ๐๐ > 0. Unstable if one or both of these conditions is satisfied: 1) ๐๐ > 0 for any pole and 2) ๐๐ = 0
repeat). sys = tf([2 5 1],[1 3 5]); h = pzplot(sys); grid on % Use when you want the angle of poles. Theta = atan(Imag(s)/Real(s)) pzmap(sys) [p,z] = pzmap(sys)
s = svds(A,k) s = svds(A,k,Sigma) Returns the k largest singular values. Returns k singular values based on the value of sigma. For example, svds(A,k,'smallest') returns the k smallest singular values. gsvd(A,B); (^) Generalized SVD. sigma(sys) sigma(sys1,...,sysN) Singular value plot of dynamic system Plots the system(s). [sv,wout] = sigma(sys) Each frequency in the vector wout. The output sv is a matrix, and the value sv(:,k) gives the singular values in descending order at the frequency wout(k). The function automatically determines frequencies in wout based on system dynamics. [sv,wout] = sigma(sys,w) Returns the singular values sv at the frequencies specified by w. See sigmaplot for additional plot customization options. H = (^) Evaluate system response at a specified tf([1 - 1],[1 1 1],-1); frequency. z = 1+j; frsp = evalfr(H,z) A = [0.1 0; 0.2 0.9]; (^) Returns the frequency response of the B = [0.1; 0.1]; dynamic^ system^ model^ system^ (sys)^ at C = [10 5]; D = [0]; sys = ss(A,B,C,D); [H,wout]=freqresp(sys) frequencies wout. freqresp automatically determines the frequencies based on the dynamics of system (sys). w = 3; % Hz w^ is^ the^ real^ frequency^ grid. H = freqresp(sys,w) Use^ units^ to^ specify^ the^ frequency^ units. units = 'Hz'; H = freqresp(sys,w,units) issiso(sys) (^) Returns a logical value of 1 (true) if the dynamic system model sys is SISO and a logical value of 0 (false) otherwise. isempty(sys) (^) Returns a logical value of 1 (true) if the dynamic system model sys has no input or no output, and a logical value of 0 (false) otherwise. Where sys is a frd model, isempty(sys) returns 1 when the frequency vector is empty.
J = jordan(A) [V,J] = jordan(A) Jordan normal form (Jordan canonical form) Computes the Jordan normal form of the matrix A. Due to Jordan form being sensitive to numerical errors convert numeric input to exact symbolic form. Schur decomposition T = schur(A) [U,T] = schur(A) Returns T, the Schur matrix of A. Return T and a unitary matrix U such that A = UTU'. scaledsys = prescale(sys) Scales the entries of the state vector of a state-space model sys to maximize the accuracy of subsequent frequency-domain analysis. The scaled model scaledsys is equivalent to sys.
[S, P, A_bal] = balance(A) A_bal = balance(A,'noperm') Returns the scaling vector S and the permutation vector P separately. The transformation T and balanced matrix A_bal are obtained from A, S, and P by T(:,P) = diag(S) and A_bal(P,P) = diag(1./S)Adiag(S). Scales A without permuting its rows and columns. A = [0.1 0; 0.2 0.9]; [P,R,C] = equilibrate(A) [P,R,C] = equilibrate(A,outputForm) Permutes and rescales matrix A such that the new matrix B = RPA*C has a diagonal with entries of magnitude 1, and its off- diagonal entries are not greater than 1 in magnitude. outputForm = "matrix" or "vector". % Requires R2023b or higher. rng(0) % clear rng sys = drss(40); method = "balanced" R = reducespec(sys,method) Creates a model order reduction (MOR) specification object for a dense or sparse linear time- invariant (LTI) model sys. Method options: "balanced" "ncf" (Requires Robust Control Toolbox software) "modal" % Requires R2023b or higher. A = [0.1 0; 0.2 0.9]; B = [0.1; 0.1]; C = [10 5]; D = [0]; sys = ss(A,B,C,D); [msys,blks] = modalreal(sys) [msys,blks,TL,TR] = modalreal(sys) Returns a modal realization msys of an LTI model sys. This is a realization where A or (A,E) are block diagonal and each block corresponds to a real pole, a complex pair, or a cluster of repeated poles. blks is a vector containing block sizes down the diagonal. If you also want the block- diagonalizing transformations TL and TR. % Requires R2023b or higher. A = [0.1 0; 0.2 0.9]; B = [0.1; 0.1]; C = [10 5]; D = [0]; sys = ss(A,B,C,D); csys = compreal(sys) csys = compreal(sys,type) [csys,T] = compreal( ) Returns the controllable companion realization of the single-input LTI model sys. Realization of the model sys defined by type. "c" for controllable companion form. ๐ด๐ = ๐โ^1 ๐ด๐, ๐ต๐ = ๐โ^1 ๐ต, ๐ถ๐ = ๐ถ๐ "o" for observable companion form. ๐ด๐ = ๐๐ด๐โ^1 , ๐ต๐ = ๐๐ต, ๐ถ๐ = ๐ถ๐โ^1 Returns the transformation matrix as well T for explicit models with matrices A, B, C. sysT = ss2ss(sys,T) (^) Performs the state-coordinate transformation of sys using the specified transformation matrix T (must be invertible).
load wtankData.mat sys = frd(response,frequency) ts = 0.5; sys = frd(response,frequency,ts) num = [2,0]; den = [1,8,0]; ltiSys = tf(num,den,'TimeUnit','minutes ','InputDelay',3) sys = frd(response,frequency,ltiSys) Frequency-response data model Creates a continuous-time frequency-response data (frd) model, setting the ResponseData and Frequency properties. ts is sampling time and properties inherited from the dynamic system model is ltisys. Struct = get(sys) Value = get(sys,'PropertyName') Access model property value. Specify the desired properties. For example, 'Numerator'. sys=set(sys,'Property',Value) sys=set(sys,'Property1',Value , 'Property2',Value2,...) Set or modify model properties help and doc function (^) Documentation on a given function. feedback, series, parallel, append, connect, tunablePID, getLoopTransfer, AnalysisPoint For block diagram related functions operations look into the documentation.
K = place(A,B,p) [K,prec] = place(A,B,p) L = place(A',C',p)' Pole placement is a method of calculating the optimum gain matrix. p are your desired closed-loop poles. K is the state-feedack gain matrix. prec returns accuracy estimate of how closely the eignevalues of ๐ด โ ๐ต๐พ match your desired pole locations. L are your observer gains. [K,S,P] = lqr(sys,Q,R,N) [K,S,P] = lqr(A,B,Q,R,N) Linear-Quadratic Regulator (LQR) design. Both Q and R need to be symmetric positive define matrices. โExpensiveโ control strategy tr(R) > tr(Q). โCheapโ control strategy Q is larger than R. Typical choices: