Quick Matlab Reference: Note Command Syntax Is Case-Sensitive!
Quick Matlab Reference: Note Command Syntax Is Case-Sensitive!
Quick Matlab Reference: Note Command Syntax Is Case-Sensitive!
who
whos
clear
clear x
save
load
save filename
save filename x y z
load filename
Matrix commands
[ 1 2; 3 4]
zeros(n)
1 2
.
3 4
creates an nxn matrix whose elements are zero.
zeros(m,n)
ones(m,n)
ones(n)
ones(A)
zeros(A)
eye(n)
Transpose of A
Plotting commands
plot(x,y)
plot(y)
semilogx(x,y)
plots log(x) vs y.
loglog(x,y)
semilogy(x,y)
grid
title(text)
ylabel(text)
xlabel(text)
text(x,y,text)
text(x,y,text,sc)
gtext(text)
hold on
hold off
polar(theta,r)
bar(x)
bar(x,y)
hist(x)
mesh(z)
contour(z)
meshc(z)
meshgrid
print
print filename -dps
Misc. commands
length(x)
size(x)
randn
rand
fliplr(x)
flipud(x)
reshape(A,m,n)
f = t3+sin(t)
diff(f,t)
int(f,t,a,b)
det(A)
Determinant.
diff(f)
int(f)
Differentiate f .
Integrate f .
inv(A)
Matrix inverse of A.
rank(A)
Rank.
eig(A)
poly(A)
Characteristic polynomial.
help symbolic
expm(A)
Matrix exponential.
10
15
20
25
30
35
40
0.6
0.4
0.2
0.2
0.4
0.6
0.8
0.6
0.4
0.2
0.2
0.4
0.6
0.8
PSfrag replacements
Connecting systems
LTI systems can be interconnected in a number of ways. For example, you may
add and multiply systems (or constants) to achieve parallel and series connections, respectively. Assume that H1 above is controlled by a PI controller with
K = 1, Ti = 4 and h = 2, according to the standard block diagram to the left:
uc
Hr
H1
SYS1
SYS2
There is a function feedback for constructing feedback systems. The block diagram to the right is obtained by the call feedback(SYS1,SYS2). Note the sign
conventions. To find the transfer function from the set point u c to the output y,
you identify that SYS1 is H1 Hr and SYS2 is 1. You can also use block matrices of
systems to describe multiinput multioutput systems.
>>
>>
>>
>>
>>
>>
>>
Hyuc = feedback(H1*Hr,1);
%
% You can also derive the matrix of transfer functions,
% from inputs uc and l to outputs y and u:
%
+-------+
%
uc ----->|
|----> y
%
| CLSYS |
>>
>>
>>
>>
>>
>>
>>
>>
%
l ----->|
|----> u
%
+-------+
% From y=H1(l+u), u=Hr(uc-y) it follows that
SYS1=[0,H1;Hr,0]; SYS2=[1,0;0,-1];
CLSYS = feedback(SYS1,SYS2);
% It is possible to assign names to the signals:
set(CLSYS,InputName,{uc,l},OutputName,{y,u})
CLSYS
Transfer function from input "uc" to output...
0.07996 z^2 + 0.1635 z - 0.1018
y: ----------------------------------z^3 - 1.637 z^2 + 0.8801 z - 0.1018
u:
u:
>>
>>
>>
>>
>>
Sampling time: 2
% It is often better to do the feedback in state space:
CLSYS = feedback(ss(SYS1),SYS2);
set(CLSYS,InputName,{uc,l},OutputName,{y,u});tf(CLSYS)
% Show step responses from set point and load disturbance to output and control signal:
step(CLSYS)
Step Response
From: uc
From: l
1.2
1
To: y
0.8
0.6
0.4
Amplitude
0.2
0
1.5
To: u
1
0.5
0
0.5
1
0
10
20
30
40
50
600
10
20
30
40
50
60
Time (sec.)
Step response.
Impulse response.
Response of state-space system with given initial state.
Response to arbitrary inputs.
Response analysis GUI.
Generate input signal for LSIM.
Generate unit-step input.
Frequency response.
bode
- Bode plot of the frequency response.
nyquist
- Nyquist plot.
ltiview
- Response analysis GUI.
System interconnections.
+ and - Add and subtract systems (parallel connection).
*
- Multiplication of systems (series connection).
/ and \
- Division of systems (right and left, respectively).
inv
- Inverse of a system.
[ ]
- Horizontal/vertical concatenation of systems.
feedback
- Feedback connection of two systems.
Classical design tools.
rlocus
- Root locus.
rlocfind
- Interactive root locus gain determination.
rltool
- Root locus design GUI
place
- Pole placement (state feedback or estimator).
estim
- Form estimator given estimator gain.
reg
- Form regulator given state-feedback and estimator gains.
LQG design tools. Notation differs from CCS.
lqr,dlqr
- Linear-quadratic (LQ) state-feedback regulator.
lqry
- LQ regulator with output weighting.
lqrd
- Discrete LQ regulator for continuous plant.
kalman
- Kalman estimator.
kalmd
- Discrete Kalman estimator for continuous plant.
lqgreg
- Form LQG regulator given LQ gain and Kalman estimator.
Matrix equation solvers.
dlyap
- Solve discrete Lyapunov equations.
dare
- Solve discrete algebraic Riccati equations.