Professional Documents
Culture Documents
2.3.08.6
2012
1. .......................................................................................... 3
2. MATLAB ........................................................................... 3
3. HELP ................................................................................. 3
4. Workspace ..................................................................... 6
5. MATLAB....................................................................... 7
6. ............................................................................ 10
7. ........................................... 11
8. .................................................................. 13
9. Workspace ....................................................................... 18
10. ................................................................. 19
11. ........................................................................... 20
12. ............................................................................... 22
13. .m ............................................................................. 24
14. Matlab ............................... 26
15. SIMULINK ...................................................................................... 36
........................................................................................ 57
1.
2.
MATLAB
MATLAB/ SIMULINK PC
Lab Login
( Username: temporal Password: !@#$% (
12345) ). T
Start Menu Windows MATH.
3.
HELP
HELP
Command Prompt click Help menu
Product Help. :
Toolboxes
,
.
Product Help.
(sin):
help Command Prompt:
click ..:
matlab\matfun :
4.
Workspace
MATLAB. quit:
exit:
.
click Save in:
File name.
5.
MATLAB
,
, ";",
:
Enter:
sqrt(2) (sqrt(2) = 2 )
( 7 2) 4 + 3 .
5
, (1x1)
(1 x n m x 1), :
1,1 1,2
2,1 2,2
m,1 m,2
1,n
2,n
m,n
(2,3) A, :
V = 1 6 7 9E2 22 (-)
W = 1 2 3 4e3 0 (-) ";"
.
.
. , V(4)=V(1,4) W(4)=W(4,1).
(:). :
1 0.5
:
2 3 :
MATLAB:
zeros
ones
1
rand
eye
:
(m x n) . size
1x2 m n
. :
/
([ ]). :
max
min
mean
std
sum
prod
HELP.
6.
/ MATLAB
:
+
*
/
\
10
det
inv
eig
TLAB. /
.
:
Z = X\Y Z = inv(X)*Y
Z = X/Y Z = X*inv(Y).
, A^2 A*A A
. 2^A
. (- )
() det, inv, eig (
HELP
).
7.
- - (.)
:
+
.*
./
.\
.^
.
:
:
11
(;)
/ Command Prompt. .
(.. Help atan2):
12
sin
cos
tan
asin
acos
atan
atan2 Four quadrant arctangent
sinh
cosh
tanh
asinh
acosh
atanh
8.
abs
angle
sqrt
real
imag
conj
round .
fix
floor
-
ceil
+
sign
rem
exp
log
log10 10
MATLAB
. ,
/ .
MATLAB :
plot
loglog
semilogx
semilogy
polar
mesh
contour
bar
stairs
x, y
y, x
3-D
plot
loglog, semilogx, semilogy, polar .
,
b
a.
13
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
10
:
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
10
plot
.
MATLAB
, ,
.
:
14
.
o
x
+
*
:
-.
--
y
g
c
r
m
b
w
k
: plot(vector1,vector2,line-type)
:
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
:
title
xlabel
ylabel
text
gtext
grid
x
y
, :
15
10
:
Graph of sin(a) in stars and cos(a) in circles
1
0.8
0.6
0.4
y-axis
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
4
5
6
x-axis in radians
10
.
'-' subplot.
: subplot(mnr). , m
n .
r .
:
16
:
sin(a)
cos(a)
0.5
0.5
-0.5
-0.5
-1
-1
10
0.5
0.5
-0.5
-0.5
10
log10(a)
-1
-1
10
10
: axis([x-min x-max y-min y-max]). , xmin x-max y-min y-max
.
, File Print
OK.
17
9.
Workspace
MATLAB
:
who
whos
what
clc
clear
clear
format
...
hold
delete
<Ctrl>-C
<Esc>
<Home>
<End>
Workspace
who
.M
Matlab, Z z (-) .
18
10.
MATLAB .
MATLAB +1.
y=x3+5x-1
y=[1 0 5 -1]. x y
0 x2 .
MATLAB
:
roots
poly
polyval
conv
deconv
y
r. poly(r) y .
x=-2 polyval.
.. w=2x2-x-1,
w=[2 -1 -1] :
19
w y z=2x5-x4+9x3-7x2-4x+1 z
w y .
11.
MATLAB
. MATLAB
- -TRUE
1 -FALSE
0 .
&
|
~
& | .
~ .
:
20
<
<=
>
>=
==
~
=
any all.
any(A,i), 1
- i. A
21
. all
- 1.
12.
MATLAB
.
.
FOR, WHILE, IF, IF-ELSE :
FOR
for v = expression
statements
end
for:
for i.
S(i) (i) .
i 1
. i
3 .
WHILE
while expression
statements
end
while
.
while:
22
IF
if expression
statements
end
if
. if:
IFELSE
if expression
statements
else
statements
end
if-else .
. .
.
if-else:
23
if else
.
g .
13. .m
MATLAB .m.
.m click File New Script:
.m.
24
.m function
:
function [output1, ...] = (1, 2, etc.)
function (1, 2, etc.) .
"1" .. .
" "
.
:
.m witch.m :
:
25
-1.5
-1
-0.5
0.5
1.5
(%)
compiler . help witch,
:
14. Matlab
(.) (.). MATLAB tf
ss zpk ( 14.1) .
, MATLAB
. , , .
, . .
. 14.2.
14.1
sys=tf(num,den)
sys=ss(A,B,C,D)
sys=zpk(Z,P,K)
--
14.2
[num, den]=ss2tf(A,B,C,D)
26
[A,B,C,D]=tf2ss(num,den)
[Z,P,K]=ss2zp(A,B,C,D)
--
[Z,P,K]=tf2zp(num,den)
--
[num, den]=zp2tf(Z,P,K)
--
[A,B,C,D]=zp2ss(Z,P,K)
--
14.1. . . . .
, MATLAB
step impulse .
lsim. ,
initial ( .).
14.3.
14.3
step(sys)
impulse(sys)
lsim(sys,u,t)
initial(sys,x0,t)
( .)
27
. ,
step(*sys).
: lsim,
:
[u,t]=gensig(type,tau),
type (sin,square, pulse) tau
.
14.2: 1
.
14.2 .
14.2. .
.
MATLAB 14.4 :
14.4
pole(sys)
zero(sys)
pzmap(sys)
minreal(sys)
14.3:
:
28
3 2
1
A=
, B =
,C = 1 1 , D = 0
1 0
0
14.3. 3.
,
. MATLAB
, ,
( ) .
14.5.
14.5
sys=series(sys1,sys2)
sys=parallel(sys1,sys2)
sys=feedback(sys1,sys2,-1)
sys=feedback(sys1,sys2,+1)
: sys=feedback(sys1,sys2,-1)
sys=feedback(sys1,sys2).
14.4:
14.4.
29
14.4. PI .
14.5, .
14.4.
14.5. . 14.4.
, Matlab
14.6.
14.6
bode(sys)
Bode
[Gm,Pm,Wcg,Wcp] = margin(sys)
30
H=freqresp(sys,w)
nyquist (sys)
nyquist
nichols (sys)
nichols
14.6, sys ,
14.1, w rad/s. Gm Pm
Wcg Wcp .
14.5: Bode Nyquist,
-1 -5, 2 K = 3.
14.6, .
14.6 Bode
Nyquist.
14.7. Bode 5.
31
14.8. Nyquist 5.
, (..). Matlab
, , 14.7.
14.7
rlocus(sys)
[K, poles]=rlocfind(sys,P)
P .
: rlocfind
P.
...
14.6: .. :
G(s)=
2
s + 6 s 2 + 5s
3
6.
14.9 .
32
14.9. .. .
.
14.11. 14.6.
14.12. , -6.
,
(.) (.). MATLAB
tf ss zpk ( 14.8) .
14.8
sys=tf(num,den,Ts)
sys=ss(A,B,C,D,Ts)
sys=zpk(Z,P,K,Ts)
--
Ts . Ts = -1.
14.9.
14.9
dstep(num,den)
dimpulse(num,den)
33
dlsim(num,den,u,t)
dinitial(A,B,C,D,x0,t)
( .)
14.7: :
G (z)=
1
z 0.5
14.13, :
14.13. .
, ,
(). , Matlab
14.10.
14.10
.
sysd = c2d(sys,Ts,'method')
[Ad,Bd,Cd,Dd] = c2dm(A,B,C,D,Ts,'method')
(. .)
[numd,dend] = c2dm(num,den,Ts,'method')
(. .)
G (s)=
1
s ( s + 0.5 )
PD :
34
Gc ( s ) = 0.5 + 2 s
Tustin,
= 0.1s .
14.14, Matlab:
14.14. .
14.14
:
14.15.
14.8.
35
14.16. 14.8.
15. SIMULINK
SIMULINK MATLAB
(blocks).
SIMULINK .
.
SIMULINK, .
15.1:
. M=2400kg.
B=320kg/s
F=1130N. v(t)
v(0)=0 m/s.
, M
F -Bv(t).
Newton. :
v +
B
F
v=
M
M
(15.1)
. (15.1) ,
:
v(t)=
F
(1 e ( B/M )t )
B
(15.2)
( )
SIMULINK.
simulink Command Window
>>simulink
36
.
SIMULINK,
(.. Continuous, Discrete ..), 15.1:
15.1. Simulink.
FileNewModel untitled
.
, (blocks)
.
untitled .
. 15.2
blocks Continuous
untitled.
37
15.2. .
15.1
.
15.1
Continuous
Transfer Function
State Space
Integrator
Derivative
Sources
Step
38
Ramp
Clock
Sinks
Scope
To Workspace
Math operations
Gain
Sum
,
.
(15.1)
Laplace. :
G(s)=
v(s)
1
=
F(s) Ms + B
(15.3)
F t=0 s,
:
F(s)=
F
s
(15.4)
untitled
:
) Sources Step Clock.
Step () .
Clock .
39
15.6. untitled.
40
15.8. .
, To Workspace ,
To Workspace1 Clock.
41
15.9. To Workspace1
Clock.
. Step
Step time: 0 Final value: 1130 OK.
15.10. Step.
Transfer Fcn Denominator:
[2400 320] Apply OK.
42
15.12. To Workspace.
43
, . , ,
To Workspace Velocity. , To
Workspace1 Time. 15.13:
15.13. .
, (..
, , ..).
Simulation Configuration Parameters 15.14.
15.14. .
44
15.15. Scope.
15.16. plot.
File Save As...
(.. submarine) untitled.
:
. ,
Stop Time: Max
Step Size: - .
=M/B=7.5 s.
15.2: 1
v(0)=2 m/s.
. , ,
45
. , Simulink,
.
E. (1) :
v =
B
F
v+
M
M
(15.5)
. (15.5) Simulink :
) Continuous o Integrator.
.
v v .
15.17. Integrator.
) Math operations Gain Sum.
Gain .
. .
Sum .
15.19. .
46
. Gain
Gain: 1/M Multiplication: Element-wise
(K.*u). Gain1 Gain: B/M.
Apply OK.
: B M,
.
15.20. Gain.
Sum List of signs:
+- Apply OK.
15.21. Sum.
Integrator.
, Initial condition: 2
Apply OK.
47
22. Integrator.
15.1, To Workspace
t v
. Scope.
Scope :
15.23. Scope.
Parameters 15.23. :
48
15.24. Scope.
Data History Save data to workspace
Variable name: velocity Format: Array.
velocity
Scope ( ).
Limit data points to last:,
,
15.25.
15.25. Scope.
15.26.
Gain1 Gain1
FormatFlip Block.
( Sum),
. (15.5).
49
15.26. .
15.1
:
15.27. Scope.
Scope,
velocity.
t v.
Command Window:
>> t=velocity(:,1);
>> v=velocity(:,2);
>> plot(t,v)
:
50
15.28. plot.
Word,
15.28 JPEG, Bitmap,
Eps .. 15.28. word
.
15.28. Eps.
15.3: 15.1
B v 2 v(0)=2 m/s.
, :
v +
B 2 F
v =
M
M
(15.6)
. (15.6) . ,
Simulink.
:
51
15.30. Mux.
)
15.2.
Step,
Scope
Integrator
, 15.31.
15.31. .
.
Step, Integrator Scope 15.2.
MATLAB Fcn MATLAB Fcn:
submarine_motion(u(1:2)). submarine_motion function
( 15.33).
52
. 13. u(1:2)
MATLAB Fcn (
F v ). , Output
Dimensions: 1 MATLAB Fcn
( v ). Apply
OK.
53
15.34. .
15.1
:
15.35. Scope.
(
) .
, .
54
. 15.4 PI
Simulink.
15.4: , Simulink,
. (15.3), PI :
kP =160, kI = 240
v=1
m/s .
15.36 .
15.36. PI .
Step ,
15.10 Gain Gain1 kP
k I 15.20.
Scope
15.37, Scope1
15.38.
15.37. .
55
15.38. PI .
56
word
Figure 1 15.28:
File Export Setup Size, Rendering,
Fonts Lines Export (Eps,JPEG ..)
Save OK.
Word :
15.28.
57