Anda di halaman 1dari 122

.. , . .

MATLAB

.. , . .

MATLAB

-
2005 .

518
32
.., ..
MATLAB. . . ., 2005
,
MATLAB.
(CONTROL, SYMBOLIC, SIGNAL, OPTIMIZATION).
, , .
SIMULINK
. .
, 220100, 552800,
.

:
,
, ..

-


2005
.., .. 2005


.....................................................................................................................................5
1. ...................................................................................5
1.1. ........................................................................................................................................5
1.2. ...............................................................................................................................7
1.2.1. .........................................................................................7
1.2.2. ..........................................................................................................8
1.3. ...................................................................................................................9
1.4. .................................................................................................................11
1.5. ..................................................................................................................13
1.6. ...................................................................................................16
1.7. MATLAB ......................................................................................19

2. MATLAB .............................................................................23
2.1. .......................................................................................23
2.2. ............................................................................................25
2.3. ........................................................................................................28
2.4. ...........................................................................................................30

3. SIMULINK .................................................................................................34
3.1. SIMULINK ......................................................................................34
3.2. ....................................................35
3.3. ...............................................................................36
3.4. SIMULINK .....................................................................................38

4 ...................................................................................41
4.1 MATLAB ............................................................................................41
4.1.1 ..................................................................................41
4.1.2 ...........................................................................................................42
4.1.3 .........................................................................................................46
4.2 ..................................47
4.2.1 .....................................................................................47
4.2.2 ...........................................................................................................49
4.3 ...................................................................................................................53
4.3.1 ....................................................................................53
4.3.2 .....................................................................................................55
4.4 ..................................................................................................58
4.4.1 ..................................................................................................58
4.4.2 ................................................................................59
4.4.3 .....................................................................................60

5 .................................................................65
5.1 .................................................................................65
5.1.1 .................................................................65
5.1.2 ..................................................65
5.1.3 ...................................................................................67
5.2 MIMO- .........................................................................................................68
5.2.1 MIMO- ................................................................................................68
4

5.2.2 ....................................................................................................70
5.3 ..................................................................................................................73
5.3.1 .......................................................................................73
5.3.2 ...............................................................................75
5.3.3 ......................................................................77
5.4 ................................................................................78
5.4.1 .......................................................................................................78
5.4.2 ....................................................................................................81
5.5 SIMULINK ..................................................................................................83
5.5.1 DEE ...............................................................83
5.5.2 Simulink- .................................................................................................84
5.5.3 SIMULINK .........................................................................86
5.5.4 Simulink- MATLAB .................................................................88

6 MATLAB ........................................................................................93
6.1 .............................................................................................................................93
6.2 ..........................................................95
6.3 ..................................................................................................................96
6.4 .....................................................................................................99
6.5 MATLAB.............................................................................99
6.6 m- .............................................................................................................100
6.7 MATLAB .....................................101
6.8 . ...102

...................................................................................................................................115
............................................................................................................115
......................................................................................................119


[6], 10 .
MATLAB ,
, .
SIMULINK ,
.
MATLAB ([1-6, 1012, 14]), (
), . ,
-
.
MATLAB SIMULINK
. 1-3,
MATLAB SIMULINK,
. 4-6
,
, , . MATLAB
, , CONTROL, SYMBOLIC OPTIMIZATION.

1.
1.1.
MATLAB ,
. MATrix LABoratory
( ). MATLAB
. MATLAB
,
.
,
.
MATLAB

, .
,
, ,
. , MATLAB

(, , ),
, .
MATLAB .
, ,
, .
MATLAB.
, ,
MATLAB
(
),
6

. , SYMBOLIC ,
CONTROL .
!

Matlab

Control
systems

Identification

Optimization

Aerospace

Curve fiting

Partial
differential
equation

Simulink

System
identification

Robust control

Communications
CDMA
reference

Signal
processing

Fixed point
Virtual reality

Neural network
Image
processing
Fuzzy
logic

DSP

Financial

Symbolic
math

Dials and
gauges

Data acquisition

Sym mechanics

MATLAB,
SIMULINK,
.
MATLAB . 1.1.
MATLAB, (, ,
) m-,
MATLAB. ,
m-, SIMULINK
( ).

1.2.
1.2.1.
MATLAB, , , ,
(Command Window)
(Workspace). ,
View.
. ,
sin300,
1
sin(pi/6)
Enter. ans=0.5.
0.5

y=sint 0 t 10 ,
0
(
t=0:.1:10;),

y=sin(t);
plot(t, y). -0.5
,
-10
2
4
6
8
10
. Enter
>>t=0:.1:10; y=sin(t); plot(t,y), grid
.
.1.2

( grid).
t, y ( 101 )
MATLAB .
MATLAB,
.m ( m- -). ,
, vova.m. , (
) : >> vova
MATLAB , ,
C:\MATLAB \work\, .
sin. MATLAB
50 .
. 1.
1
X^2
EXP
SIN
ASIN
SINH
XY
X*Y
SQRT
LOG
COS
ACOS
COSH
X/Y
ABC
LOG10
TAN
ATAN
ASINH
8

.
,
( ).
(, sqrt(4) 2).

( ), exp(1) =2,71828
, ,
,
sh, ch, arcsh. , sin, cos
, (degree), sind, cosd
( MATLAB 7). , sin(pi/6) sind(30)
ans=0.5000. ( , ).
, sind([0, 30, 90]) ans=0 0.5000 1.0000.
help.
, MATLAB 7
>> help sind,

:
SIND Sine of argument in degrees. SIND(X) is the sine of the elements of X, expressed in degrees.
For integers n, sind(n*180) is exactly zero, whereas sin(n*pi) reflects the accuracy of the floating point value of pi.
See also asind, sin.

1.2.2.

. MATLAB
. ,
= [1 -2 3 8 5 6], (-) .
-
x = x0:h:xn. h 1. ,
x=0:10 0 10, x=0:0.1:10 10
0.1.
,
. , :
>> a=[1 2 3; 4 5 6; 7 8 9
a=
1 2 3
4 5 6
7 8 9

>> a=[1 ,2, 3; 4, 5, 6; 7, 8, 9]


a=
1 2 3
4 5 6
7 8 9

:
>> a(1,1)
ans = 1

>> a(3,3)
ans = 9

>> b=[1 2 3 4 5]; b(4)


ans = 4

:
>> a(:,1)
ans = 1
4
7

>> a(2,:)
ans =
4 5

>> b(1:3)
ans =
1 2

>> b(3:end)
ans =
3 4 5

MATLAB , (.2).
2
linspace
zeros
eye
logspace
ones
diag
linspace .
, =linspace(xmin,xmax) 100 min
xmax. , , N 0 10,
x = linspace(0,10,N). logspae,
.
zeros, ones, eye diag.
zeros ones, , . , a
A=zeros (3) B=ones (3)
A= 0 0 0
000
000

B= 111
111
111,

C = zeros(1,4) D = ones(1,4) - C = 0 0 0 0 D = 1 1 1 1.
eye ( I,
eye) .
>> E=eye(3)
E= 1 0 0
0 1 0
0 0 1

>> G=eye(2,7)
G=
1 0 0 0
0 1 0 0

0
0

0
0

0
0

eye(size(A)) , .
diag . ,
, , .
, diag
.
, diag ,
[1 1 1], diag .

1.3.
MATLAB plot
. .
plot(x,y), x y ,
y = f(x).
, .
. ,
plot plot(y), x
y.
, grid.
/ , grid on
grid off , .
.
plot ( ) plot(1, 1, 2, 2, ..., n, n), 1, 1;
10

.. . , ,
.
. x(t ) e 0, 2t s i tn,
y(t ) e 0, 2t cos t , t 0 10 0,1.
:
2, 2

>>t=0:.1:10; x=exp(.2*t).*sin(t); y=exp(.2*t).*cos(t); plot(t, x, t, y), grid.

. 1.3. * ()
x, y, (
sin t, cos t, e-0,2t, 101 ).
plot(x,y), grid, ,
. 1.4.
1

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

-0.2

-0.2

-0.4

-0.4

-0.6
0

. 1.3

10

-0.6
-0.5

0.5

.1.4

, , ,
, title, xlabel, ylabel, text. ,
, xlabel('x'), ylabel('y').
plot ,
, . , plot(X,Y,'x')
, x (), plot(X1,Y1,':',X2,Y2,'+')
+ p.
. , plot (X,Y,'r') plot (X,Y,'+g')
+ .
, , help plot.
plot . MATLAB
.
plot3. , , ,
x=sint; y=cost; z=t. 0 t 10
0,02:
>>t = 0:pi/50:10*pi;

plot3(sin(t),cos(t),t);

. 1.5.

11

,
sphere, ellipsoid, cylinder . .
1.6.

40

30

0.5

20

10

-0.5

0
1

-1
1
1

1
0

0
-1 -1

-1 -1

. 1.5

. 1.6

MATLAB . 1.7 4.1.

1.4.
MATLAB .
, , .
. 3
3
AB
A'
trace
inv
A*B
det
rank
pinv
+ , ,
= + . : =*. ,
. A * B B * A .
,
. ,

a11 a12 b11 b12 a11b11 a12b21 a11b12 a12b22


a

.
21 a22 b21 b22 a21b11 a22b21 a22b12 a22b22
MATLAB . :
>>A=[1 2; 3 4]
1 2
3 4

>>B=[5 6; 7 8]
5 6
7 8

>>C=A*B
19 22
43 50

>>CT=B'*A'
19 43
22 50

12


(
). , - -.
MATLAB .
, A B,
.
trace(A) , .. .
, . rank
.
()
.
, det.
a b
, A
2x2 det A ad bc .
c d
:

a1
det b1
c1

a2
b2
c2

a3
b3 a1b2 c3 a2b3c1 a3b1c2 a3b2 c1 a1b3c2 a2b1c3 .
c3

inv(A).
.

1
A1
A* ,
det A
* , Aij .
2 .
1. aij Aij,
.. , .
i+j , .
2. .
,
1

a b
1 d b

.
c d
ad bc c a

. . 4 .
4
>> A=[1 2 3; 0 1 4; 0 0 1]
1 2 3
0 1 4
0 0 1

1
2
3

>> A'
0 0
1 0
4 1

>> det(A)
1

>> inv(A)
1 -2 5
0 1 -4
0 0 1

>> inv(A')
1
0 0
-2 1 0
5 -4 1

, , ,
MATLAB. ,
.
13

.
, X , AX B ,
A - B . X A1 B .
MATLAB
>>X=inv(A)*B >>X=(A^-1)*B.
, A .
AX B ,
pinv, .
(slash backslash).
.
x yz 2
2x 2 y z 2
x 2 y 2 z 5.

1 1 1
A 2 2 1,
1 2 2
MATLAB >>X=inv(A)*B, :
>>A=[1 1 1; 2 2 1; 1 2 2]
A=1 1 1
2 2 1
1 2 2

>>B=[2; 2; 5]
B=2
2
5

2
B 2.
5

>>X=inv(A)*B
X=-1
1
2

, x=-1, y=1, z=2.

1.5.
MATLAB ,
, , ,
, .
. , x 3 2 x 5
1 0 2 5 .
MATLAB . 5.
5
roots
conv
polyval
poly
deconv
residue
.
roots . ,
x 2 5x 6 0 r=roots([1 5 6]),
r=[-2; -3].
poly .
p=poly([-2 -3]) p=[1 5 6]. poly
, .

14

(x -1)8
0.025
0.02


roots

.
(
).
( x 1)8
1.
poly
roots.

0.015
0.01
0.005
0
-0.005
-0.01
-0.015
-0.02
-0.025
-1.04

-1.02

-1

-0.98

-0.96

. 1.7

>>p=poly(-ones(1, 8)), r=roots(p),


p = 1 8 28 56 70 56 28 8 1
r = -1.0203; -1.01420.0144i; -0.99980.0201i; -0.98580.0140i; -0.9801

, 2%.
, MATLAB 32- , .
. 1.7.
roots/poly, ,
.. . 1.7
( x 1)8 , , .
%
n=8; r=-ones(1,n); clg, hold on
for i=1:5,
p=poly(r),
r=roots(p),
plot(r,'*','LineWidth',2)
end
plot(-1,0,'o','LineWidth',2),grid on; hold off

, (
SYMBOLIC).
>> r=-ones(1,8); p=poly(r)
%
p = 1 8 28 56 70 56 28 8 1
>> P=poly2sym(p),
%
P =x^8+8*x^7+28*x^6+56*x^5+70*x^4+56*x^3+28*x^2+8*x+1
>>R=solve(P);
% P( x) 0.
R'=[ -1, -1, -1, -1, -1, -1, -1, -1]
%

, solve . ,
, .
,
. polyval ( polynomial
value). , y x 2 5x 6 5 x 5
:
>> x= -5:0.1:5; p=[1 5 6]; y=polyval(p, x); plot(x, y), grid.

, 1= -3, 2= -2 (
).
15

conv ( convolution.
:
P1 x 2 3x 2; P2 4 x 2 5x 1; P P1 P2 4 x 4 17 x 3 24 x 2 13x 2.
MATLAB:
>> 1=[1 3 2]; 2=[4 5 1]; = conv(P1,P2).
: = 4 17 24 13 2.

deconv.
.
.
4 x 4 17 x 3 24 x 2 14 x 4
x2
4 x 2 5x 1 2
.
2
x 3x 2
x 3x 2

MATLAB:
>> num=[4 17 24 14 4]; den=[1 3 2]; [q,r]=deconv(num,den),


q=

1, r =

2.

q , r .
-
. , ,
.
, ..
.
MATLAB residue.
.
k
k
x5
1 2 .
x 3x 2 x r1 x r2
2

r1, r2 : r1= -2, r2= -1.


k1, k2
:
x 5 k1 ( x 1) k2 ( x 2).
k1 k2 1, k1 2k2 5. , k1 3, k2 4.
residue.
num den ,
R, K, (
).
>>num=[1 5]; den=[1 3 2]; [K, R]=residue(num, den),
K=[-3 4], R=[-2 -1], . ,

x5
4
3

.
x 3x 2 x 1 x 2
2

16

, ,
(
).
help residue.
[num, den]=residue(R, K, P)
, R, K ,
.
-
.

1.6.

,
,
, ,
.
,
. ,

det A E n an1n1 a1 a0 ,
, n .
, .
n=2:
a12
a
det 11
a11 a22 a12a21 2 a11 a22 a11a22 a12a21 .

a22
a21

, , ,
.
2 tr A det A 0.
1, 2 .
MATLAB


poly(A).

. roots. ,
1 2
,
:
0 3
>>A=[1 2; 0 3]; p=poly(A); L=roots(p).

1 3.
eig (
eigen ). , L=eig(A), 1; 3. ,
, .
17

. H
,
, .

AH = H

(A-E)H = 0,

(*)

, .
(*) H, ,
: det A E 0.
. 1 , , n , .. ,
(*), ,
i Hi.
1. 1 , , n , n
H1, , Hn.
2. (A iE)Hi = 0 ,
, ..
.
. , H1 , k H1,
k , . MATLAB
k ,
( ).
3. , ,
.
.
MATLAB,
eig [H,L]=eig(A). H
, L
.
1 2
. A
. ,
3 2

2
1
det A E
1 2 6 2 3 4.

2
3
1 1, 2 4.

AH 1 1 H 1 ,

h1
1 2 h1
3 2 h h .

2
2

h1 2h2 h1
2h 2h2 0,
1

3h1 2h2 h2
3h1 3h2 0.
18


h1 h2 0.
, , h1 1, h2 1, ..
1
H 1 .
1

:
h1 2h2 4h1
3h1 2h2 0,

3h1 2h2 4h2


3h1 2h2 0.
2
h1 2, h2 3, .. H 2 . ,
3
2 / 3
1
H 2
H 2
.

1
3 / 2
MATLAB :
>> A=[1 2;3 2]; [H,D]=eig(A)

:
A
1

2
3

H
-0.7071 -0.5547
0.7071 -0.8321

D
-1
0

0
4

, MATLAB .
.

3 2 1
B 2 1 1.
1 1 1
poly eig, :
>>B=[3 2 1; 2 1 1; 1 1 1]
B=3 2 1
2 1 1
1 1 1

>>v=poly(B)
v=1 -5

>>eig(B)
1

ans= -0.3489

0.6041

4.7448

, ,
B.

1.7. MATLAB
SYMBOLIC MATLAB.
,
, ,
, .
sym syms, ,
sym(2) syms x y z. ,
.
19

. 6.
6
det
rank
inv
expand
simple
solve
diag
poly
eig
factor
collect
numden
,
, . ,

>>syms a b c d; A=[a b;c d], D=det(A)

Enter,
a, b
A
, D a * d b * c.
c, d

P=poly(A) :
P x 2 (a d ) x ad bc,

inv eig ,
.
. ,
, .
:
>> A=sym(A); [H,D]= eig(A), B=sym(B), V=poly(B)
A=sym(A)
[1 2]
[3 2]

H
[ -1, 1]
[ 1, 3/2]

D
[ -1, 0]
[ 0, 4]

B=sym(B)
B= [ 3, 2, 1]
[ 2, 1, 1]
[ 1, 1, 1]

V=poly(B)
V =x^3-5*x^2+x+1

, MATLAB
. ,
, eig(sym(B)) ,
MATLAB.
. 6 ,
. , expand , factor,
, ( ), collect
. , expand (a+b)^2 a^2+2*a*b+b^2,
factor(a^2-b^2)
(a+b)*(a-b), ,
: sym a b.
simple simplify , ,
>>sym(x), y=simple(sin(x)^ 2+cos(x)^ 2)

y=1.
solve, ,
, .
, , x 2 2bx c 0.
>>syms x b c; solve(x^2+2*b*x+c=0, x)
: ans= -b+(b^2-c) ^(1/2), -b-(^2-c) ^(1/2),

x1, 2 b b 2 ac .
20

numden -
.
1
2
3p 5
3p 5

2
.
p 1 p 3 p 1 p 3 p 4 p 3


>>syms p; [num,den]=numden(1/(p+1)+2/(p+3)),
: num=3*p+5, den=(p+1)*(p+3).

expand:
den=p^2+4*p+3, .

sym2poly poly2sym, double vpa,
. , P=sym2poly(den) P=[1 4 3], A=sym([1 2; 2
3]), L=eig(A), L1=double(L) , L
L1:
>>den=expand(den),

A=[1, 2]
[2, 3]

L=2+5 (1/2)
2-5 (1/2)

L1=4.2361
-0.2361


laplace ilaplace
.
Symbolic ,
ezplot funtool. easy plot,
, . . 1.8
y sin x cos 2 x .
sin (x)

sin(x)+cos(2 x)

0.5
0.5

0
0

-0.5

-1
-0.5

-1.5

-1

-2
-6

-4

-2

0
x

>>ezplot('sin')

-6

-4

-2

0
x

>>ezplot('sin(x)+cos(2*x)')

. 1.8
ezplot , ,
. , ,
x 2 y 2 1 ezplot('x^2-y^2-1'). ,
, , ezplot('-x^3+2*x+1',[-2,3])
x 3 2 x 1 [-2, 3].
,

x f (t ), y g (t ),
ezplot('f(t), 'g(t), [t0, t1]). , ,
(x, y) , :
21

x = 2t 4t3, y = t2 3t4.
:
>>ezplot('2*t-4*t^3','t^2-3*t^4',[-1,1]),

, .1.9
x = 2 t-4 t3, y =t2-3 t4
0

-0.5

-1

-1.5
-1.5

-1

-0.5

0
x

0.5

1.5

. 1.9
.
SYMBOLIC
funtool. f(x) g(x)
, , , , .


1. . plot,
:
) x 2 cos t cos 2t, y 2 sin t sin 2t
( , , );
) x 3 cos t cos 3t , y 3 sin t sin 3t
( , , ,
);
) x 2 cos t cos 2t , y 2 sin t sin 2t
( , ,
, );
) x 3 cos t cos 3t , y 3 sin t sin 3t
( , ,
, ).
a a 3
2. . A 1
.
0 a2
MATLAB-, a1 , a2 , a3
.
22

3. . ,

1
0
2
0
4 1
1 24

0
1 .
)
) 2 1 2 ;
) 0
;

3 18
1 1 1
1 1 1
:
)
2+19+90
)
3+62+11+6
)
3+2++1
[1, 2] =[-9 -10]
[1, 2, 3 ] = [-1 -2 -3]
[1, 2, 3 ] = [-1 i - i]
1
1
1 1 1
1
3 8

H 1 0 1.
H 1 i i .
H
.

1 3
1 1 0
1 1 1
4. . : - (,
), () (, ).
- , .
, , , , .
.
, .
, . . , ,
.
, T=P/H3 , P
, . T, () . ,
T <11.5, -, 11.5< T <13, , T >13,
. 1 .
MATLAB- ,
(P, H) ,
( ).
5. . y (n ) y (n) 1 2 3 ... n .
MATLAB- , y (9)
y (n ) .
. y (9) ,
>>y=sqrt(1+sqrt(2+sqrt(3+sqrt(4+sqrt(5+sqrt(6+sqrt(7+sqrt(8+sqrt(9))))))))),
y =1.7579.


for.

n - sqrt1234,

function y=sqrt1234(n)
%
y(n)=sqrt(n);
for i=n-1:-1:1,
y(i)=sqrt(i+y(i+1));
end
y=y(1);

sqrt1234(9), ans =1.7579.


y (n ) - sqr.
23

%Program sqr
% sqr.m sqrt1234(n)
for j=1:10,
y(j)=sqrt1234(j);
end,
plot(y,'*'), grid

6. . 1010.
, ,
( , ).
, ,
?
MATLAB ,
.
. 1010
>> a0=ones(10);
a0=
1
1
1
1
1
1
1
1
1
1

1
1
1
1
1
1
1
1
1
1

1
1
1
1
1
1
1
1
1
1

1
1
1
1
1
1
1
1
1
1

1
1
1
1
1
1
1
1
1
1

1
1
1
1
1
1
1
1
1
1

1
1
1
1
1
1
1
1
1
1

1
1
1
1
1
1
1
1
1
1

1
1
1
1
1
1
1
1
1
1

1
1
1
1
1
1
1
1
1
1

a(k,l) a0
>>a0(k,:)=~a0(k,:);a0(:,l)=~a0(:,l);a0(k,l)=~a0(k,l);a=a0;

.
: ; "" ( ).

24

2. MATLAB
2.1.
MATLAB,
. S u y (. 2.1).
y(t ) ,
.
SISO Single
Input Single Output. (. 2.2) MIMO
Multiple Input Multiple Output.
u
y
, , u 1 , y 1 .
u 2
y2

S
. 2.1

u1
u2

y1

y2

. 2.2

.
(LTI Linear Time Invariant
systems).
CONTROL,
MATLAB. 60 ,
, , .

(. 2.1).
.
,
y(p)
y ( p)
(p) : Q( p)
. ,
u ( p)
1
k

,
,
Tp 1
p
k
2
.
p 2
n-
:
b p m bm1 p m1 b0
Q( p ) m n
, m n.
an p an1 p n1 a0

25

z1, , zm B(p) (zeros), p1, .., pn


A(p) (poles).

( p z1 ) ( p z m )
Q( p ) k
,
( p p1 ) ( p p n )
k bm / an .
MATLAB
B(p)
A(p)
-
: num=[bm, , b0] den=[an, , a0], - z
: z=[z1, , zm], p=[p1, , pn]. ,

Q( p )

2 p2 6 p 4
p3 3 p 2 5 p 2

num=[2 -6 4], den=[1 3 5 2].


, , tf
( Transfer Function).
, , sys=tf(2,[3 1]) sys
2

. ,
3p 1
, , num den. , sys.num{1},
ans = 0 2, sys.den{1}, ans = 3 1.
.
A, B, C, D :
X AX BU ,

Y CX DU ,

U , Y , X [ x1 xn ]T ,

A, B, C, D . , B -,
-, D ( ).
MATLAB , ,
ss ( State Space ).
, B, C, D .
.

x1 2 x1 x2 ,
x 2 3x1 5 x2 4u,
y x1 7 x2 .
:
2 1
A
,
3 5

0
B ,
4

C 1 7,

D 0.

MATLAB, :
>>A=[-2, 1; 3, -5]; B=[0; 4]; C=[1, 7]; D=0; sys=ss(A, B, C, D).

26

a, b, c, d ss- , num den


tf-, , sys.c, ans=1 7.
MATLAB
Q(p) (tf-) X AX BU , Y CX DU
(ss-).
Q( p) C ( pE A) 1 B D .

MATLAB ss- tf- , tf


ss-. ss
tf-. ,
28s 60
sys1=tf(sys). : transfer function 2
, ,
s 7s 7
tf- sys1 .
sys2=ss(sys1), ss-,
A, B, C, D :
7 3.5
a
,
0
2

8
b ,
0

c 3.5 3.75,

d 0.

, sys sys2 ,
( tf(sys2)).
.
MATLAB - zpk-.

. Zpk- Q( p) k

( p z1 ) ... ( p zm )
,
( p p1 ) ... ( p pn )

k bm an (gain). zpk,
ss- tf- zpk-.
, sys3=zpk(sys2),

28( s 2,143)
.
( s 5,791)( s 1,209)

zpk- , tf-,
, sys3.z ans=[-2.1429], .. .
.
, sys=sys1*sys2 sys1 sys2,
sys=sys1+sys2 .
, / (, ?).

2.2.
.
( , , ),
, .
27


.
q(t) -, ..
, t=0.
( ) h(t)
( ,
d
-). q(t ) h(t ).
dt
- 1 1/p .
,
, .

. ,
1
Q( p) , q(t)=1;
p
b

,
Q( p )
,
q(t ) be at .
pa
k
Q( p) 2

p k2
q(t ) sin kt.

MATLAB ilaplace SYMBOLIC,
(inverse Laplace). ,
syms k p; q=ilaplace(k/(p2+k2),
q=sin(k*t). laplace .
, sin 10t, :
>>sym p, t; y=laplace(sin(10*t), t,p).

10
.
p 100

.
(ss-)
X AX bu,
y cX ,

: y=10/(p^2+100), .. y ( p)

q h

X AX ,
q cX , X (0) b;
X AX b, h cX , X (0) 0.
,


b
Q( p)

pa
x ax bu, y x.

28

x ax 0,

x(0) b,

q(t ) be at .

x ax b,
x(0) 0.
, x Ce at
x a / b :
a
h(t ) Ce at a / b 1 e at .
b
h(0)=0.
MATLAB
dsolve SYMBOLIC. h(t)
, :
>>syms a b; h=dsolve(Dx+a*x=b, x(0)=0).
h=b/a-exp(-a*t)*b/a,

.
CONTROL
. impulse step,
impulse function ( ) step function ( ).

tf- ss-,
t, .
impulse.
impulse(sys), . impulse(sys,10),
0 t 10 ( MATLAB
).
,
( ).
[y,t,X]=impulse(sys,t), , sys ss-. t ,
(, t=0:.1:10), y ,
. ,
101 .
1(t), 2(t). 101
(t).
plot(t,y), plot(t,X),
plot(t,X(:,1)).
(t),
1(t), 2(t), 1(t). plot(X(:,1), X(:,2))
x2 f ( x1 ). .
step , ..
. , impulse:
>>step(sys), step(sys,T), y=step(sys,t), [y,t,X]=step(sys,t).

, , T
( ), t ( ).
initial ( initial condition ).
, ,
0 ( =0).
initial(sys,X0)
,
[y,t,X]=initial(sys,X0,t).
29

, lsim (
linear simulation ).
(t), .
lsim(sys,u,t) . ,
t,
sys. , :
>>t=0:1:10; u=sin(t); sys=tf(1,[1 1]; lsim(sys,u,t),

1

p 1
u=sint 0 t 10 .
:

>>y=lsim(sys,u,t), [y,t,X]=lsim(sys,u,t), [y,t,X}=lsim(sys,u,t,X0).

sys ss-.
plot, plot(t,u,t,y).
MATLAB
. :

( expm);
(
trapz);
( dsolve
SYMBOLIC);
( laplace ilaplace
SYMBOLIC);
SIMULINK.
.

2.3.
CONTROL .
- (),
- () - (),
.
Q(p) p i , i 1, ,
.
, , Q(i )
.
Q(i) a() ib() ,
Im

(a, b) (. 2.3).
Q(i)
b

b
A
A a 2 b 2 , tg .
a

,

Re
.
a
30

. 2.3

- (
).

( ) -
, ( ) - .
.
() 20 log 10 A( )
.
, ,
.
MATLAB. ,
tf- W, :
>>sys=tf([1 1], [1 1 1]); W=0: .1: 10;

(frequency response) Q(i )


freqresp.
Q( p )

p 1
,
p p 1
2

Q(i )

i 1
.
i 1 2

H=freqresp(sys,W) , 101
Q(i ).
plot(H(:)) , ..
(. 2.4).
0
-0.2
-0.4
-0.6
-0.8
-1
-1.2
-1.4

0.2

0.4

0.6

0.8

1.2

1.4

. 2.4

31

1.5

0
-0.2
-0.4

-0.6
-0.8
0.5

-1
-1.2

-1.4
0

10

-1.6

. 2.5

10

. 2.6

,
abs angle:
>>A=abs(H(:)); f=angle(H(:));

plot(W,A), plot((W,f).

. 2.5, 2.6, , ,
-/2.
nyquist

bode.

nyquist(sys)
, .. (
, ). bode(sys)
.
,
CONTROL,
ltiview.

2.4.

, , ,
. CONTROL,
(. 1).
1
pole
zero (tzero)

eig
pzmap

ctrb
obsv

gram
minreal

dcgain
roots

,
.. .
. ,
, .
( ).

x 2 y 4 x a,
y 2 x y b.
32

, a b
.
4 2
a
. X AX B , A
, B

2 1
b
, .. :
>> A=[-4 2;2 -1]; eig(A)
ans = -5 0

, , ,
.

dsolve:
>> syms a b;s=dsolve('Dx=2*y-4*x+a,Dy=2*x-y+b')
s = x: [1x1 sym]
y: [1x1 sym]
>> x=s.x
x =2/5*exp(-5*t)*C1-1/10*b+1/5*a+2/5*t*b+1/5*t*a+1/2*C2
>> y= s.y
y =-1/5*exp(-5*t)*C1+4/5*t*b+2/5*t*a+C2

x (a 2b)t 2c1e 5t a c2
y 2(a 2b)t c1e 5t 2c2

, a=-2b, x 2c1e 5t a c2 , y c1e 5t 2c2 .


, z i
pi , . z
p Q(p) = num/den, z =
roots(num); p = roots(den). sys tf- ss-,
p=pole(sys), z=zero(sys).
p=eig(sys), p=eig(sys.a), ..
. tzero ( transfer zeros )
z=tzero(A,B,C,D).
pzmap .
[p, z]=pzmap(sys), p z , pzmap(sys)
(
, ).

R D, A, B , C
:
C
CA
n 1
.
R [B, AB, ..., A B], D
...
n1
CA
.
33

. ,
, : rankR = n.
.
, : rankD = n.
.
, R D : rankR = n, rankD = n.

ctrb obsv ( controlability observability). : R=ctrb(sys), D=obsv(sys).
, ,
, R=ctrb(A, B), D=obsv(A, C) R=ctrb(sys.a, sys.b), D=obsv(sys.a,
sys.c). rank.

.
gram, . 4.4, 4.5.
,
. SISO-
.
minreal ( minimal realization).
: sys1=minreal(sys)
sys1=minreal(sys, eps).
,
.
( ).
p 1
Q( p ) 2
. z1= 1 1= 1, 2= 2.
p 3p 2
, 1= z1. tf-
:
>>s=tf([1 1],[1 3 2])
s+1
------------s2 + 3 s + 2

>>zero(s)
-1

>>pole(s)
-2
-1

>>eig(s)
-2
-1

>> [p, z]=pzmap(s)


p=2 z= 1
1

,
pzmap(s) ( . 2.7, , ).

34

Pole-Zero Map
1

, ,

( ) (-1, 0)
.
ss-
,
ctrb, obsv rank:

Imaginary Axis

0.5

-0.5

-1
-2

-1.5

-1

-0.5

Real Axis

. 2.7

a = -3 -2
1 0

>>s1 = ss(s)
b= 2
0

>>R=ctrb(s1)
R=
2 -6
0 2

c = 0.5 0.5

>>D=obsv(s1)
D = 0,5 0,5
-1 -1

>>rank(R)

>>rankD

R D, , s1 , ,
, .
: q=minreal(s),
1
. ,
q
s2
Q( p) +1.
,
:
>>K=dcgain(s)
K=0.5

>>K=dcgain(q)
k=0.5

.
impulse(s, q), step(s, q),
.
ctrb obsv ,
, A, b, c .
( ).

.
X = AX + bu,

y = cX,

a1
A 0
0

1
a2
1

0
a 2

0 , b a3 , c 1 1 1 ,
1
a1

XR3 , u, y .
.
.
>> syms a1 a2 a3 real
>> A=[-a1 1 0;0 -a2 0;0 1 -a1], b=[a2;a3;1]; =[1 1 1];

35

R=[b, Ab, A2b], D=[cT, (cA)T, (cA2)T]T:


>> R=ctrb(A, b)
-a1*a2+a3,
-a1*(-a1*a2+a3)-a2*a3]
-a2*a3,
a2^2*a3 ]
a3-a1,
-a2*a3-a1*(a3-a1)]

[ a2,
[a3,
[1,

>> D=obsv(A, c),


[ 1,
1,
[ -a1,
2-a2,
[a1^2, -2*a1-(2-a2)*a2,

1]
-a1]
a1^2]

:
det(R) =0,
det(D) =0. ,
, .
( ).
.


1. ,
, ,
MATLAB.
)

m ,
k ,
,
F v

F, x v x .
) ( ).
) ( ).
uR

R
i(t)

iL

uc
iC

uL

iR
I

i,
iL

u;
uc uR.

L, m ; R,
/10; , k .
. :

ma v kx F , v x,
a x ;

36

i L iC i R i (t ),

u L u c u R u,

i u / z( p),

z R R,

zC

1
,
Cp

z L Lp.

2. dsolve,

x x x x 0,
) x 0 x0 1,

x 0 2,

) x 0 60,

x 0 x0 0.

: ) x e t sin t , ) x 30(e t sin t cos t ) 30e t 42,4 sin(t 45o ) .


3. :
) x 2 x x 4, x( 0 ) 1, x( 0 ) 2, x( 0 ) 2;
) x n 2 x a sin( nt ), x( 0 ) x( 0 ) 0.
: ) x(t ) 4t 3 2e t ,

) x(t )

a
sin nt cos nt cos( nt ).
2n 2

pa
u e t . .
MATLAB, a=1; b=2; T=3.
.
) MATLAB ( CONTROL):

4.

a = 1; b = 2; T = 3;
t = linspace(0, T); u = exp(-b*t);
sys = tf(1, [1 a]);
y = lsim(sys, u, t);
ym = max(y); plot(t, y).

Q( p)

%
%
%
%
%

1
e at e t .
a
1
;
y(t ) te at .
a ( ) : y ( p)
2
( p a)
tM=1/a, y(tM)=1/ae.
5. y(4) y = e-t, :
y0 3, y 0 5.25, y0 7.5, y0 5.75. MATLAB.
.
,
, u = e-t .
y (5 0,25t )e t 2 cos t .
: :
, C1et. ,
e-t
. ,
.
.
) .

) ( SYMBOLIC);

y (t )

37

sys=tf(1,[1 0 0 0 -1]); s=ss(sys);


T=10;t=0:.1:T;
u=exp(-t);
X0=[-5.75;7.5;-5.25;3];
y=lsim(s,u,t,X0);
z=(5-t/4).*exp(-t)-2*cos(t);
plot(t,y,t,z)

-1

-2

10

< 8 ., .
) . u = e-t
, b 0.
. R [b, Ab, ..., A4 b] 4, ..
. , (
25 .).
) ,
4- . MATLAB
minreal. ,

5,75 p 4 1,75 p 3 2,25 p 2 2,25 p 4


Q( p)
( p 1)( p 4 1)
1.

3. SIMULINK
3.1. SIMULINK

MATLAB SIMULINK.
, .
,
.
, , (
), .
SIMULINK , simulink

. .
File/New/Model.
. (,
Continuous) .
38

. ,
.
,
. 1.
1

Cut, Paste, Clear

, ,

Format/Flip name

Integrator1
1
s

1
s

Integrator

Format/Hide name

1
s

1
s

Integrator

Format/Flip block

1
s

1
s

Format/Rotate block

1
s

1
s

.3.1 . : Sine wave


( ) Sources ( ), Scope ()
Sinks ( ) Integrator () Continuous
( ). ,
. , ,
DEL. .
1
s
Sine Wave

Integrator

Scope

.3.1

Simulation/Start.

Scope, .
c .

3.2.
(, ,
) .
( ) Sources (). .3.2.

39

untitled.mat
Step

Band-Limited
White Noise

Ramp

1
Sine Wave

Pulse
Generator

Constant

From File

simin
From
Workspace

. 3.2
. 2.
2

Step

Sine wave


y A sin(t ) b

Ramp


y k (t t 0 ), t t 0
y 0
0, t t 0

Pulse generator
Band-limited
noise

white

Constant
From File

From Workspace


MATLAB

Step time
Initial value
Final value

Amplitude
Bias
Frequency
Phase
Slope
Start time

A
b
/

Initial output

y 0

Amplitude
Period
Pulse width
Phase delay
Noise power
Sample time
Seed

Constant value
File name
Sample time
Data
Sample time

k
t 0

SIMULINK
Signalbuilder, - .
,
Sinks. Scope, Graph (), Display, To
File To Workspace. . 3.3.
0
Display

Scope

simout

untitled.mat

To Workspace

To File

XY Graph

. 3.3
Scope . XY Graph
, , .
Display . To File
.
40

.
load.
MATLAB
To Workspace. ( simout).
(array), (structure),
(structure with time). MATLAB
simout timeout.

MATLAB.
simout.time simout.signal.

3.3.
. 3.4
Continuous.
1
s

x' = Ax+Bu
y = Cx+Du

(s-1)

s+1

s(s+1)

Integrator

State-Space

Transfer Fcn

Zero-Pole

du/dt
Derivative

. 3.4
. 3
1

Derivative

Integrator

State-space


()

Transfer Fcn.

External reset:
none
rising
falling
either
level
Initial condition
Limit output:
upper
saturation limit
lower
saturation limit
A, B, C, D
Initial conditions
Numerator
Denominator

Zero-pole

Zeros
Poles
Gain

:






:



. 3.5 ( Discrete).
, . Unit delay
41

Discrete Filter ,
1 / z .
1

(z-1)

z+0.5

z(z-0.5)

Discrete
Transfer Fcn

Discrete
Zero-Pole

y(n)=Cx(n)+Du(n)
x(n+1)=Ax(n)+Bu(n)

1+0.5z-1
Discrete Filter

Discrete State-Space

z-1

Discrete-Time
Integrator

Unit Delay

. 3.5
. 3.6 .
(Math Operations).
e

u
sin

Math
Function

Sign

Sum
Sum1

|u|

Trigonometric
Function

Gain

. 3.6
. 4.
4

Math function

Sign

Sum

Trigonometric
function

Gain

Abs

Function: exp, log,


10^u, log10, sqrt, .
Output signal type
Auto
Real
Complex
Icon shape:
Rectangular
Round
List of signs
Function: sin, cos, tan,
asin, acos, sinh, cosh,
.
Output signal type
Auto
Real
Complex
Gain
Multiplication:
Element-wise (K.*u)
Matrix (K*u)
Matrix (u*K)

:









:

(K*u)
(u*K)

3.4. SIMULINK

42

SIMULINK
, , ,
.

y sin y 0,

y (0) 0, y(0) 1/ 2.

,
300 .
.3.7, a. ,
siny .
.
, :
, .. y y .
y(t ) y (t ) .
MATLAB.
.3.7, .
XY Graph. Scope .
(Mux)
(Signal Routing).
MATLAB To Workspace c
structure with time. y(t ) y (t )
MATLAB, :
>> plot(simout.time,simout.signals.values)

, ,
Scope , plot.
y''

a)

y'
1
s

1
s

Integrator

Integrator1

Scope

y''

y'
1
s

1
s

Integrator

Integrator1
Mux

Scope
simout

-1
Gain

sin
Trigonometric
Function

-1
Gain

To Workspace

sin
Trigonometric
Function

XY Graph

. 3.7
Simulation/Simulation parameters
. Solver () Workspace I/O
( ). Solver Simulation
Time ( ) (Start time)
(Stop time). (Solver)
(Fixed-step)
(Variable step). ,
. Workspace I/O
43

,
.
, ,
u e t :
y sin y u, y(0) 1, y (0) 1.

u(t).
SIMULINK, MATLAB
SIMULINK. . ,
3.7, (In Sources) (Out
Sinks). 3.8, .
Stop time=20. Workspace I/O Input
[t, u], Initial State xInitial, Time tout, Output yout,
-.
MATLAB u e t
y(0) 1, y (0) 1 :
%
%
% u

>> xInitial=[1; 1];


>> t=linspace(0,20)';
>> u=exp(-t);

SIMULINK.
tout yout. plot(tout,yout,t,u,'r:'),
y(t ), y (t ), u(t ) ( 3.8, ).
y'

y''
1
In1

1
s

1
s

Integrator

Integrator1

2.5
2

Out1

1.5

1
0.5

-0.5

sin
-1

Trigonometric
Function

-1.5

-2
-2.5
0

10

12

14

16

18

20

. 3.8


1.
X AX ,

X (0) 1 1 .
T

44

1 1 1 1
1 1 1 1

) A
1 1 1 1

1 1 1 1
MATLAB SIMULINK .
dsolve.
.
) x1 x2 x3 e 14t

1 2 3
) A 2 4 6,

3 6 9

>> A=-[1 2 3;2 4 6;3 6 9]; s=ss(A,eye(3),eye(3),0);initial(s,[1;1;1])

) x1 x2 x3 x4 e t
>> s=ss(-ones(4),eye(4),eye(4),0);initial(s,[1;1;1;1])

2. y a1e a2t sin a3 t. 1, 2, 3 ,


, . , ,
.
3. SIMULINK c
:
) y (1 0,5 cos t ) y 4 y 0 ;
) t 2 y ty (t 2 n 2 ) y 0 ;
) (1 t 2 ) y 2ty n(n 1) y 0 ;
) (1 t 2 ) y ty n 2 y 0 ;
) ty (1 t ) y ny 0 .
4.
g
y sin y 0,
l
y , g , l .
). SIMULINK ,
,
b (.3.9 ).
,
.
y(t ), y (t ), y f ( y ).
).
( b)

y
b

.3.9

45


MATLAB SIMULINK,
.
MATLAB .

MATLAB
plot . 1.3.
MATLAB .
,
.


MATLAB ,
:
grid

axis

hold

figure

shg

clf

subplot

. grid ()
grid on grid off .
axis.
axis square, axis normal, axis auto axis equal.
, axis('square'), axis(normal), axis(auto) axis('equal'),
. axis('square') .
plot(x,x) 45 ,
. , plot(sin(t),cos(t)) ,
. axis('normal') .
, , axis([10 10 -1 2]).
10 x 10, 1 y 2, plot (X,Y,'LineWidth',2) .
. ,
plot.
, plot ,
, plot (1, 1, 2, 2, 3, 3), y1 = f1 (x1), y2 = f2 (x2), y3 = f3
(x3).

. , Y ,
plot(, Y) , Y
( Y).
46

. , , ,
:
>>t=0:0.1:10; x=[sin(t);cos(t); exp(-t)]; plot(t,x)

. 4.1.
hold,
. plot ,
. ,
hold .
hold on hold off.
:
>> hold on, plot(t,sin(t)), plot(t,cos(t)), plot(t,exp(t)), hold off

( ), .
4.1 .
1

0.5

-1

10

10

0
1

-0.5

-1

-1

10

. 4.1
figure .
, .
figure ,
. figure(5) , 5,
plot .
.
Alt-Tab ,
shg ( show graphic).
clf ( clear figure).
, clc ( clear command),
, .. clear.
clear(x), clear x y z
x, y, z.

. subplot.
subplot(mnp) mn (m n )
. ,
>>subplot(211), plot(t,sin(t)), subplot(212), plot(t,cos(t))

47

, ,
(. 4.1, ). subplot(111) subplot
, .
plot,
, .


MATLAB ,
. . 4.1.
4.1
loglog
polar
stairs
area
pcolor
line
pie
plotyy
semilogx comet
bar
fill
colormap ribbon
pie3
strips
semilogy stem
barh
patch
rectangle scatter
errorbar imagesc
.
loglog, semilogx, semilogy, polar plot.
" ",
.e. , .
loglog , . Semilogx
, , X , Y
. Semilogy , , Y
, X .
. " " 14 ,
100, 200, 300, 500, 1000, 2000, 4000, 8000, 16000, 32000, 64000, 125000, 500000,
1000000 1.
, plot, subplot, semilogy, title, xlabel, ylabel, bar.
.
>> y=[100 200 300 500 1000 2000 4000 8000 16000 32000 64000 125000 500000 1000000];
>> subplot(121); plot(y),grid, title('Rate of game'), xlabel('Tours');ylabel('Rubles');
>> subplot(122); semilogy(y), grid, title('Rate of game'), xlabel('Tours');ylabel('Rubles');

.4.2. ,
.
10

x 10

Rate of game
10

Rate of game "MILLIONER"

Rubles

Rubles

8
6
4

10

2
0

10

15

Tours

10

10

15

Tours

.4.2

2005
48

polar.
, plot, ,
. polar(, r)
r = f(),
- r , .
, r = bea .
b=1, a= 0,2 . 4.3.
90
120

1
1

60

0.8

0.8

0.6
150

30

0.4

0.6

0.2

0.4
180

0.2
210

330

0
0

240

10

15

20

300
270
t=0:10:180; x=sind(t); stairs(x)

t = 0:.1:10; r = exp(-.2*t); polar(t,r,'*')

. 4.4

. 4.3

comet ,
, . ,
stem, , ,
.
stairs (), .
4.4 .
, bar.
, (.
4.5). barh .
5

0.5

0
-0.5

-1
1
0

x=5:-1:0; bar(x)

2 4.5 3
.

20

40

60

80

100

t=0:.1:10; x=sin(t); area(x)

. 4.6
49

area, fill patch .


. 4.6, .
colormap.
white, gray, black, cool, hot, 'default'.
rgb-,
, , . , [0 0 0] , [1 1 1] , [.5 .5 .5]
, [1 0 0] , [127/255 1 212/255] .
'r','g','b','c','m','y', 'w', 'k'. colormap
, errorbar, imagesc, pcolor.
rectangle
, line , .
ribbon . ,
x=0:.2:10; y=sin(x); ribbon(y) (. 4.7).
1
0.8
0.6

0.4

0.5

0.2
0

0
-0.2

-0.5

-0.4
-0.6

-1
150

-0.8

1.4

100

1.2

-1

10

50
0.8
0

0.6

. 4.7

. 4.8

scatter ( scatter ).
, x=0:.2:10; y=sin(x); scatter(,y, 10*(.^2+1)) ,
(. 4.8). ,
.
pie pie3, , .
4.9 . 4.10.

50

7%
13%

33%

33%

7%
13%
20%

27%

20%

27%

pie3(1:5)

pie(1:5)

. 4.10

. 4.9

errorbar . .
4.11 :
t=1:.05:20;y=exp(.2*t).*sin(t);x=exp(.2*t).*cos(t); errorbar(x,y,(t.^1.5)*.1)

plotyy .
plotyy(X1,Y1,X2,Y2) Y1 X1 y- Y2
X2 y- . . 4.12
t=0:.1:10; y=sin(t); plotyy(t,y,t,t.^2), grid

60

100

50

50
40
30
20
10
0
-10
-20
-30
-40
-40

-1
0
-20

. 4.11

20

40

0
10

60

. 4.12

strips ( strip ) .
.
Imagesc ( ). .
4.7
( +1 , -1 ).
hintonw, spy, printmat, plotmatrix.

51

2
0

10

12
2

10

imagesc(hadamard(12))

. 4.13

12

bar3(diag(7:-1:1))

. 4.14


. MATLAB ,
,
. .4.2.
4.2
bar3
plot3
mesh
surf
sphere
cylinder
bar3h
contour
meshgrid
fill3
ellipsoid
logo
bar3 ,
. .
4.14 . bar3h
.
plot3.
.1.3.
contour, mesh,
meshgrid surf. contour(Z) ,
Z, , .
.
contourf contour3.
mesh(Z) Z.

.

52

0.5
0.4
0.3
0.2
0.1
0
40
30

20
15

20

10

10
0

5
0

. 4.15
meshgrid mesh
. meshgrid
(x, y). . 4.15 ,
2
2
z xe x y 0 x 1,9; 2 y 1,9 ,

:
[X,Y] = meshgrid(0:.1:1.9, -2:.1:1.9); Z =X.*exp(-X.^2-Y.^2); mesh(Z)

surf fill3 .
.
. 1.3 cylinder, sphere, ellipsoid, logo,
membrane, peaks .
SYMBOLIC, ezplot, ezcontour, ezmesh, ezmeshc, ezplot3, ezpolar, ezsurf, ezsurfc.
MATLAB
. , ,
, ..
. MATLAB,
. 4.16. logo.
L- ,
membrane.
membrane 2, 3, 4 .. . 4.17
.
.

53

. 4.16

. 4.17

, MATLAB,
(bmp, metafile) , , WORD. ,
MATLAB
. IMAGE PROCESSING.


MATLAB ,
,
, ,
. .

f(x)=0.
y=f(x)
( MATLAB plot, fplot, ezplot).
f(x, )=0,
g(x, y)=0, (, )
. ,
.
roots .
, ,
, , ,
fzero. ,
f ( x) 0 , x0 .
. f ( x) x 2 3x 2 -1 -2. MATLAB
: roots fzero.
ff m-
( MATLAB) inline.
fzero, ,
.
>> =[1 3 2];
>> roots(p)
ans = -2
-1

>>f(x)= inline('x^2+3*x+2';
>> fzero f(x), -3))

function y=ff(x)
y=x^2+3*x+2;

54

ans = -2.0000
>> fzero(f(x),0)
ans = -1

>> fzero(@ff,0)
ans = -1

fzero , ,
. ,
optimget optimset.
optimset( '), , opts=optimset('fzero').
opts=optimset( ,_).
, :
>> o=optimset('fzero');
>> optimget(o,'TolX')
ans = 2.2204e-016
>> fzero(@ff,0)
ans = -1
>> o=optimset(o,'TolX',1e-1);
>> fzero(@ff,0,o)
ans = -1.0240

% fzero
%
% 2.22-16
% 0.1
% 0.1

1= 1 1= 1,024.
(
) solve SYMBOLIC.
.
. x e x 0.
y x e x
. , .
solve. solve(x+exp(-x)),
ans=lambert(-1).

, (
, xe x ). ,
double(ans) ( ans=-0.3181+1.3372i), x=lambertw().
= 1 x= 0,318+1,337i, = 1,4 x= 0,0828+1,517i (
x 1,4e x 0 ).

x2+a2=452,
x2+b2=352,

45

35

a
b

y x
,
10 b
.
x y x

10
a

10
-y

x
55

. 4.18

F(X)=0, F -, ,
fsolve. ,
m-, ,
. .
. - 45
35 (. 4.18). 10 .
.
. a b,
x, y.
4 4 , . 4.18. MATLAB
.
1 (). solve:
>>syms a b x y;s=solve('x^2 + a^2-45^2, x^2 + b^2-35^2, y/10-.x/b, (x-y)/10-x/a')
s = a: [12x1 sym] b: [12x1 sym] x: [12x1 sym] y: [12x1 sym]
s 12 .
, >> s.x, s.y, ,

, .
, :
>>[double(s.x) double(s.y) double(s.a) double(s.b)]

12 ,
:
>>ans=31.8175

21.8189 31.8222 14.5825

2 (). fsolve.
ladder,
.
function fn=ladder(p)
x=p(1); y=p(2); a=p(3); b=p(4);
f(1)=x^2 + a^2 - 45^2; f(2)=x^2 + b^2 - 35^2;
f(3)=y/10 - x/b; f(4)=(x-y)/10 - x/a;
fn=f(:);

, [10; 10; 20; 20]


>>x=fsolve('ladders',[10; 10; 20; 20])

: x=31.8175; y=21.8189; a=31.8222;


, .

b=14.5825.


.
( " ")
.
,
y f ( x1 ,, xn ).
f / x1 =0 , ..., f / xn =0,
grad = 0.
.
56

,

y f ( x1 ,, xn )
g ( x1 ,, xn ) 0. L = f + g
.

( ), , ,
. MATLAB
fminsearch, fminunc, fmincon, fminbnd.
linprog.
fminsearch.
f (x) f (x) ,
MATLAB .
. f ( x) x 2 3x 2 1
, .
polyder, fzero.
fminsearch(@ff,0)
ans = -1.5000

polyder(p)
ans = 2

fzero(inline('2*x+3'),0)
ans = -1.5000

ff(ans)
ans = -0.25

f(x) .

fminunc ( unconstrained ).
, .
. y x12 x22 , , ,
x1 x2 0 . m-
, fff:
function y=fff(x)
y=x(1)^2+x(2)^2;

>> x=fminunc(@fff,[3 3])


Warning: Gradient must be provided for trust-region method;
using line-search method instead.
x = 1.0e-008 * [-0.9290 -0.9290]

. MATLAB
. , -,
fff , y,
( ), , -,
optimset.
function [y,dy]=fff1(x)
y=x(1)^2+x(2)^2; %
dy=[2*x(1),2*x(2)]; %

>> fminunc(@fff1,[3 3],optimset('Gradobj','on'))


Optimization terminated successfully:
First-order optimality less than OPTIONS.TolFun, and no
negative/zero curvature detected
ans = 0 0

.
.
y = 2x12 + 8x22 + x32 + 4x1x2 + 2x1x3 4x3.
y / x i ,
57

4x1 + 4x2 + 2x3 = 0;

16x2 + 4x1 = 0;

2x3 + 2x1 4 = 0.

x1 = 4, x2 = 1, x3 = 6.
, .
. fminunc.
.
.
:
z = 100(y x2)2 + (1 x)2.

x = y = 1 (
). .

z'x = 400x(y x) 2(1 x) = 0;


z'y = 200(y x) = 0,
, x = y = 1.
,
.
, bandem
Optimization. ,
.
fminunc, .
= 1,9; =2.
>> f='100*(x(2)-x(1)^2)^2+(1-x(1))^2';
%
>> GRAD='[100*(4*x(1)^3-4*x(1)*x(2))+2*x(1)-2; 100*(2*x(2)-2*x(1)^2)]';
%
>>OPTIONS = optimset(OPTIONS,'gradobj','on');
%
>> [x,fval] = fminunc({f,GRAD},[-1.9, 2],OPTIONS)
x = 1.0000 1.0000 fval = 1.2371e-015
%

, .
. ,
. :
z =(a + 10b)2 +5(c d)4 +(b 2c)4 + 10(a d)4.
a = b = c = d = 0.
( ),
( ) .

,
.
. MATLAB.
fminbnd
fmincon. fminbnd ( bound )
x1 x x2 . , x=fminbnd(inline('x^2+3*x+2'),0,1) x = 0.

fmincon. :
x=fmincon(fun,x0,,,eq,eq,Lb,Ub,nonlcon,options,p1,p2,...). , ,
fun, x0. options,
58

. p1, p2, ...


. - ,
[ ].
. A B
AX B , Aeq Beq Aeq X Beq . Ub Lb
Lb X Ub . G( X ) 0
nonlcon ( nonlinear constraints).
.
f(X)=XTAX =1. ,
1 0,5
. A
,
0,5 2

f x 2 xy 2y 2 x 2 y 2 1.
, eig fmincon.
1. ,
:
>>=[1 1/2;1/2 2]; [v,d]=eig(), [V,D]=eig(sym()),

:
v=
-0.9239
0.3827

0.3827
0.9239

d=
0.7929
0
0 2.2071

V=
[
1,
1]
[ 1+2^(1/2), 1-2^(1/2)]

D=
[ 3/2+1/2*2^(1/2),
0]
[
0, 3/2-1/2*2^(1/2)]

3 2
2,2
2
0,79. =0,924, =0,383;
=-0,924, =0,383.

(. 4.19).

, f f

x2 + y2 - 1 = 0
2
1.5
1
0.5
y
0
-0.5
-1
-1.5
-2
-2

-1

0
x

. 4.19

59

2. fmincon f x 2 xy 2y 2
g x 2 y 2 1 0. inline,
m- nlcon.m:
function [h,g] = nlcon(x)
h = [];
g = x(1)^2+x(2)^2-1;

:
>> f=inline('x(1)^2+x(1)*x(2)+2*x(2)^2'); x=fmincon(@(x) f(x),[1;1],[],[],[],[],[],[],[[],@(x)nlcon(x)])
x = -0.9239 0.3827

. ,
f:
f1=inline('-(x(1)^2+x(1)*x(2)+2*x(2)^2)'); x=fmincon(@(x) f1(x),[1;1],[],[],[],[],[],[],[[],@(x)nlcon(x)])
x = 0.3827 0.9239

, .
fmincon
, SIMULINK, . 5.5.4.
, :
>> x=fminunc(@fff,[3 3]);
>> [x,fval]=fminunc(@fff,[3 3]);
>> [x,fval,flag]=fminunc(@fff,[3 3]);
>> [x,fval,flag]
ans = -0.0000 -0.0000 0.0000 1.0000

, ,
, . ,
, ,
.
,
, .
J c1 x1 cn xn
ai1 x1 ain xn bi ,

i 1, 2, , m.


cT X extr , AX b.
b c -, mn.
,
, x1 3x2 0
x1 3x2 0;
x1 3x2 0.
,
-.
MATLAB linprog.
: linprog(, A. b).
T*x A*x<=b ( ).
.

60

. .
, 6000 12000 . : 440
, 65 .. 320 - .
:

2
0.5
2

4
0.25
2.5

440
65
320
,
.
. .
, .
:
8x 12 y max .
2 x 4 y 440
0.5x 0.25 y 65
2 x 2.5 y 320 .
:

4
2
440

A 0.5 0.25, b 65 .
2
320
2.5
MATLAB .
1 (). (x, y)
, . x
, y .
.4.20. , ,
. 8x 12 y const.
,
(80, 60).
LAB :
8
x
c X max, c , X ,
12
y
T

x=0:0.2:300; y1=-2*x+220; y2=(-1/2)*x+130; y3=(-5/4)*x+160;


plot(x,y1,x,y2,x,y3); grid; hold on
for c=0:60:1460
y=-3/2*x+c/8;
plot(x,y,'black');grid on;
end

61

. 4.20. .
2 (). linprog.
>>X=linprog(-[8; 12],[2 4;0.5 0.25;2 2.5;],[440;65;320])
Optimization terminated successfully.
X= 60.0000
80.0000

, ,
, -1. ,
, 60 80
.

1 MATLAB
, , , , .
svd, cond norm, ,
( ).
S=svd(A) , ..
.
, , .
. ,
62


, , svd eig.
. :
>>A =[2
= 2 4
6 2

4; 6

2];

>>S=svd(A)
S=7.2361
2.7639

>>S= svd(sym(A))
S=5+5^(1/2)
5-5^(1/2)

,

. , A 2 5 5 7,2361,
5 5 3 5

2,618 (
2
5 5
, ).
.
norm .
MATLAB:
norm () norm(, 2) X 2 ( x12 ... xn2 )1 2 (
);
norm(, 1) - X 1 x1 ... xn ( ,
);
norm(x, inf) () X max ( xi ) (

).
:
norm(A)

norm(A, 2) (
) A 2 max 1i 2 ( AT A), max(svd(A));
i

norm(A, 1) () (
) A 1 max ( aij ... amj ) ;
i

norm(A, inf) () (
) A max ( ai1 ... ain ) ;
i

norm(A, 'fro') ( ,
2
2
2 12
a12
... anm
) tr 1 2 ( AT A).
) A F (a11
, ,
. , (condition number)
cond( A) A1 A . Ee cond(A).
=1 . ,

AX=b.
,
cond.
,
y f (t ), ,
0 t T .
.
63

,
() ( ,
):
1/ 2

y max y (t ) .
y 1 y (t ) dt , y 2 y 2 (t )dt ,
0tT
0
0

MATLAB ,
trapz
max:
y(t):
N=trapz(t, abs(y));
y(t): N= sqrt(trapz(t, y.*y));
y(t): N=max(abs(y)).
t y .
, ,
lsim .
. Q(p)=1/(p+)2,
.
q(t) N2 ( )

T

q te ; N q 2 dt
at

1
4 3

N MATLAB, =1.
) . impulse trapz:
%
% Nq - [ 0, T ], T = max(t);
%

>>sys=tf(1,[1 2 1]); [q,t]=impulse(sys);


>>Nq=trapz(t, (q.*q) ); nq = sqrt(Nq)
nq = 0.5000

) .
:
>>syms p; q=ilaplace(1/(p+1)^2)
q =t*exp(-t)
>>Mq=int(q^2,0, inf); mq=sqrt(Mq)
mq =1/2

%
% Mq
%

.
. Q(p)=1/(p+).
q(t) (0, )
T

q e ; N q 2 dt
t

1
(1 e 2T ).
2

MATLAB N T 1, 2, .

MATLAB
polyvalm, sqrtm, expm, logm. polyvalm
F ( A) an An a1 A a0 E .
, .
sqrtm (A) A. A
, .
64

expm (A) e A
, logm (A) ln A .
. , e a
a 2 a3
an
e a 1 a

.
2! 3!
n!



A2
An
(*)
eA E A

.
2!
n!
, ,
, .

(,
, expm()=exp()).
.
det e A etrA ,
.
. :

1 0
1 2
0 1
A1
, A2
, A3

.
0 2
0 1
1 0

(*), :
e 0
e 2e
e A1
, e A2
2
,
0 e
0 e

cos1 sin1
e A3
.
sin1 cos1

1 , e A1 3,
det e A etrA . .
MATLAB expm:
>>A1=[1 0;0 2];
>>e1=expm(A1)
2.7183 0
0
7.3891

>>A2=[1 2;0 1];


>>e2=expm(A2)
2.7183 5.4366
0
2.7183

>>A3=[0 1;-1 0];


>>e3=expm(A3)
0.5403 0.8415
-0.8415 0.5403

e 2,7183, e 2 7,3891, 2e 5,4366 ,


sin 57,30 cos 57,30.
3 i.
i ,

A

cos sin
e A ea
.
sin cos

65

1 0.5
cos 0.5 sin 0.5
. A
e A

/e .
0.5 1
sin 0.5 cos 0.5
expm :
>>exp(-1)*[cos(-1/2), sin(-1/2);
-sin(-1/2),cos(-1/2)]
ans =
0.3228 -0.1764
0.1764 0.3228

>> A=[-1 -.5;.5 -1];


>>expm(A)
ans =
0.3228 -0.1764
0.1764 0.3228

>>A=[-1 -.5;.5 -1];


>>expm(sym(A))
ans =
[exp(-1)*cos(1/2),-exp(-1)*sin(1/2)]
[exp(-1)*sin(1/2),exp(-1)*cos(1/2)]

SYMBOLIC
.
2

2
3

. etA , A 1

2
2 .

MATLAB.
>> A=[-2 1 -2;1 -2 2;3 -3 5]; eig(a)'
ans = -1 3 -1
>> syms t, F=expm(t*A); 4*F
4F = [ -exp(3*t)+5*exp(-t), -exp(-t)+exp(3*t), 2*exp(-t)-2*exp(3*t)]
[ -exp(-t)+exp(3*t), -exp(3*t)+5*exp(-t), -2*exp(-t)+2*exp(3*t) ]
[ -3*exp(-t)+3*exp(3*t), 3*exp(-t)-3*exp(3*t), 6*exp(3*t)-2*exp(-t)]

, :
e 3t 5e t
1
F e 3t e t
4
3e 3t 3e t

e 3t e t
e 3t 5e t
3e 3t 3e t

2e 3t 2e t

2e 3t 2e t .
6e 3t 2e t

A eig
jordan:
>> [V,D]=eig(sym(A)), [v,d]=jordan(sym(A))
V
[ -1, 1, -2]
[ 1, 1, 0]
[ 3, 0, 1]

D
[ 3, 0, 0]
[ 0, -1, 0]
[ 0, 0, -1]

v
[ -3/4, -1/4, -2]
[ -1/4, 1/4, 0]
[ 1/4, 3/4, 1]

d
[ -1, 0, 0]
[ 0, 3, 0]
[ 0, 0, -1]

-1, , ..
.

.

X AX ,

X (0) X 0 ,

y CX ,

, , .

66

MATLAB initial
CONTROL. .

X (t ) Ce At X 0 .
,
.
, initial
.
.

y 0,2 y 4 y 0.

y(t)

y0 0,25; 0,5; 0,75; 1; y 0 0.
. , x1 y; x2 y :

x1 x2 ,
x 2 4 x1 0,2 x2 .

, 0 :
1
0
A
,
4 0,2

C 1 0,

0,25 0,5 0,75 1


X0
.
0
0 0
0

expmpend.m y Ce At X 0 :
% Program expmpend
A=[0 1; -4 -0.2]; c=[1 0];
X0=[1/4 1/2 3/4 1; 0 0 0 0];
h=0.1; t=0:h:10; N=length(t);
Eh=expm(A*h);
F=zeros(N,2); F(1,:)=c;
for i=2:N
F(i,:)=F(i-1,:)*Eh;
end
Y=F*X0;
plot(t,Y), grid

% ,
%
%

F Ce At N2

%
%

. 4.21.

67

y1, y2, y3, y4


1
0.8
0.6
0.4
Y

0.2
0
-0.2
-0.4
-0.6
-0.8
0

10

. 4.21
, ,
ezplot.
A=[0 1; -4 -0.2]; c=[1 0];
% ,
X0=[1/4 1/2 3/4 1; 0 0 0 0];
%
syms T
E=expm(A*T);Y=c*E*X0;
ezplot(Y(1),[0 10]),hold on,ezplot(Y(2),[0 10]),grid,ezplot(Y(3),[0 10]),
ezplot(Y(4),[0 10]),hold off, title('y_1, y_2, y_3, y_4')

, ezplot
, hold.


, .
B TAT 1 , ,
, . A ,
, , .
.
A X = Y.
A ,
, (, ,
).
X AX .
X = T Y, Y T 1 ATY ,
.
68

MATLAB, , balance.
,
. ,
, (
).
.
:
>>A=[1 100 0.1; 1 0 0; 0 100 1], [T, B]=balance(A)

:
A
1 100 0.1
1
0 0
0 100 1

T
2 0
0
0 0.25 0
0 0
32

1
8
0

B
12.5
1.6
0
0
0.7813 1

.
,
( ).
,
.
, ,
.
(companion form), ( ),
, , .
MATLAB : compan, jordan, schur,
hess. .

pE A p n an1 p n1 ... a1 p a0 .
A n,

1
0
0
0
0
0

E
0
1
0
0 0

.
B

a
0
0
0

0
1


a0 a1 a2 an2 an1
a = (a0, ..., an-1).

.
, ,
.

69

a ,

a ,

. ,
.
,
- .
.
, =poly(A)
. compan
.

B=compan(),
,
( ),
, ,
.
. : P x 3 2 x 2 3x 4.
: =[1 2 3 4]; B=compan().

2 3 4
B 1
0
0 .
0
1
0
( poly(B)),
, .
,
2 1 0
3 0 1,

4 0 0

1
0
0
0
0
1 ,

4 3 2

0 0 4
1 0 3.

0 1 2

.
,
: p=poly(A);
B=compan(p).
.
- , .
MATLAB
.
1. =eye(2) ,
.
2. =compan(poly(A)) . ,
? MATLAB,
B T 1 AT .
70


, .

, . ,
,
.
.
X AX . d1 , , d n
, V,
,
X VY

y1 d1 y1 , y 2 d 2 y2 , , y n d n yn .
, y1 c1e d1t , y2 c2 e d2t , , yn cn e dnt , ci
.

Y DY ,

d1 0
0 d
2
D

0 0

0
0 0
.

0 dn

A D D V 1 AV , V ,
.
D
. MATLAB V D
[V, D]=eig(A).

3 6 6
. A 2 6 2 .
12 6 15
d1 3, d 2 6, d 3 9. :

1 2 1
V 0 1 2.
1 2 4
MATLAB
>>A =[-3 -6 6;-2 6 2;-12 -6 15]; [V,D]=eig(A)

-0.7071
-0.0000
-0.7071

V=
0.2182 0.6667
0.4364 -0.3333
0.8729 0.6667

D=
3.0000
0
0
0
9.0000
0
0
0
6.0000

D . , MATLAB
,
. V
71

D. ,
V ,
.
eig , MATLAB
,
>> A =sym([-3 -6 6;-2 6 2;-12 -6 15]); [V,D]=eig(A)
V=
[ -2, 1, 1/2]
[ 1, 0, 1]
[ -2, 1, 2]

D=
[ 6, 0, 0]
[ 0, 3, 0]
[ 0, 0, 9]

MATLAB
.
,
.
0 1 1
B 2 1 1
.
:
2 1 3
d1 2, d 2 1 i, d 3 1 i, :

1
h1 0,
2

i
h2 1,
i

1
h3 i .
1

B :
>>B =[0 1 1;-2 1 1;-2 1 3]; [,L]=eig(B)
H=
-0.4472
0.0000
-0.8944

0.0000 - 0.5774i 0.0000 + 0.5774i


0.5774
0.5774
0.0000 - 0.5774i 0.0000 + 0.5774i

L=
2.0000
0
0

0
0
1.0000 + 1.0000i
0
0 1.0000 - 1.0000i


>>B =sym([0 1 1;-2 1 1;-2 1 3]); [H,L]=eig(B)
H=
[ 1, 1, 1]
[ i, -i, 0]
[ 1, 1, 2]

L=
[ 1+i, 0, ]
[ 0, 1-i, 0]
[ 0, 0, 2]

H L .
L ,

i
.

MATLAB cdf2rdf ( complex
diagonal form to real diagonal form).
72

, eig,
.
.
>> [H1,L1]=cdf2rdf(H,L)
H1 =
-0.4472
0.0000
-0.8944

L1 =
2.0000
0
0 1.0000
0 -1.0000

0.0000 -0.5774
0.5774
0
0.0000 -0.5774

0
1.0000
1.0000

L1 .
1
.
rsf2csf. .
A ,

1 1
0 ,
1

2
0

1
2
0

0
1
2

..

eig ,
.
2 0 0
. C 0 2 1. 2,
0 0 2

2 , 2 .
, 2 ,
1
0

. V1 0, V2 1.
0
0
eig.
3

>>=[2 0 0;0 2 1;0 0 2], [H,L]=eig()


H=
1.0000
0
0

0
0
1.0000 -1.0000
0
0.0000

L=
2
0
0

0
2
0

0
0
2

MATLAB ,
L C.
MATLAB , ,
( ).
,
( , .. ),
. eig ,
, .
73

>> C=[2 0 0;0 2 1;0 0 2]; [H1,L1,p]= eig(sym(C))


C=
2
0
0

0
2
0

H1 =
[ 1, 0]
[ 0, 1]
[ 0, 0]

0
1
2

L1 =
[ 2, 0, 0]
[ 0, 2, 0]
[ 0, 0, 2]

p=
1 2

MATLAB , .
L1 - .
, jordan.
[V,J]=Jordan(A), V J:
V/A*V=J.
:
>> C=[2 0 0;0 2 1;0 0 2]; [V,J] = jordan(C),
C=
2
0
0

0
2
0

0
1
2

V=
0
1
0

J=
1
0
1

-2
1
0

2
0
0

1
2
0

0
0
2

V
( [9].
, jordan .
. , ,
0,01 :
>> C1=[2 0 0;0 2 1;0 0 2.01]; [V1,J1] = jordan(sym(C1)),
C1 =
2
0
0

0
2
0

0
1
2.01

V1 =
[
1,
[ -100,
[
0,

J1 =
0, -201/100]
100,
1 ]
1,
0]

[ 2,
0,
[ 0, 201/100,
[ 0,
0,

0]
0]
2]

J1 1
, J .
J () F
, .

V,
1, ..., n :

AJ V 1 AF V ,

10 0n

V .
1n1 nn1

MATLAB vander.
, V
.
: -, , -,
( ).
74

,
.


1. 2005 .
. 4.2.1,
: 500, 1000, 2000, 3000, 5000, 10000, 15000, 25000, 50000, 100000, 200000, 400000,
800000, 150000,
3000000 .
, 5000, 100000
.
2. x 2 xy y 2 25.
MATLAB.
. :
- ( x y );
- 45
,

x a cos t, y b sin t , a, b (

1 , 2 A=[1 .5;.5 1]/25 a 1/ 1 , b 1/ 2 ;


- chol = RTR A
R;
- A
;
- contour z x 2 xy y 2 ;
- : ezplot('x*x+x*y+y*y-25')
3. 8 ,
. MATLAB
.
. x, y,
xy(x-y)max x+y=8.
3
3
: x 4(1
), y 4(1
).
3
3
4. =[a b; c 0], a, b, c , , .
, , 1,
2, 3, .
. i A AX / X .
5. e At :
1
0
A1
,
2 3

2 1 0
A2 0 2 0,

0 0 2

2 1 0
A3 0 2 1.

0 0 2

75

0
0

2t

A1t

2e t e 2t

t
2 t
2e 2e

e t e 2t
.
e t 2e 2 t

A2t

2t

te
e 2t
0

0 .
e 2t

e A3t

2t
e

0
0

te 2 t
e 2t
0

t 2 2t
e
2

te 2 t .
e 2t

6. :
A1=[1 2 3;2 4 6;3 6 9]; A2=diag(1:4]); A3=ones(3); A4=ones(4); A5=triu(ones(4));

76


MATLAB
2, 3. ,
,
.

. 2.1. , S Q(p)
.

X AX bu,

y cX ,

X=TZ,
~
~
A T 1 AT , b T 1b, c~ Tc.
MATLAB ss2ss ( state space to state space).
sys1=ss2ss(sys,T), sys , ).
, ,
, .
,
.
,
. ,
. ,
.
ss- X=TZ
~ ~
, A, b , c~
.

.
, .
,
.
, , .
,
MATLAB , .

CONTROL canon, ()
.
, ('modal' 'companion').
( ) (
).
77


.
,
. ,
.
.
,
, . ,
, .
, ,
,
.
MATLAB .
canon
.
. :

4 1 2
2

X 2 1 2 X 1 u, y [1 0 1] X .
1 1 1
0
ss- canon modal:
>> a=[-4 1 2;-2 -1 2;-1 1 -1]; b=[2;1;0]; c=[1 0 1]; sys=ss(a,b,c,0);
>> sysM=canon(sys,'modal'); sysM.a, sysM.b, sysM.c
sysM.a
-1.0000
0
0
0
-3.0000
0
0
0
-2.0000

sysM.b
-1.7321
2.8284
1.4142

1.1547

sysM.c
0.7071

1.4142

, .
:
>> [sysC,T]=canon(sys,'compan'); sysC.a, sysC.b, sysC.c, T, ctrb(sys)

0
1
0

sys.a
0
-6
0
-11
1
-6

sys.b
1
0
0

sys.c
-8 24

0.5
-0.75
-0.25

T
0
-3.5
1.5 -3.25
0.5 -0.75

1
0
0

ctrb(sys)
0
0
1
0
0
1

, .
.
, canon
, :
>> sys=ss([2 0 0;0 2 1;0 0 2],[1;1;1],[1 1 1],0)
a=

b=
2 0 0
0 2 1
0 0 2

1 1
2 1
3 1

c=
1 1 1 1

78

>>sysm=canon(sys,'modal')
a=
2 0 0
0 2 0
0 0 2

b=

c=
1 1 -1

1
2.252e+015
2.252e+015

, ( !),
B .

,
balreal.
. 25 .
(balanced representation) .

.
, , b, c,
.
Wc W X AX bu; y cX
,

Wc e At bbT e A t dt ,
T

Wo e A t c T ce At dt.
T


. gram.
, c ( controlability observability).
Wc W
WcAT+AWc=-bbT,

WA+ATW=-cTc.

MATLAB lyap.

X A X b u, y c X
,

Wc Wo diag 1 ,..., n .
,
Wc, W, , .
1 ,..., n
, .
A,b,c
.

T
T
b Ic , A IA I , I diag[i1 ,..., in ], I
1 .

.

Wc, W ,

79

T-1Wc(T-1)T,
TTWT. balreal.
: sysB=balreal(sys), [sysB, G, T]= balreal(sys).
sysB G
.
. sys .
>> [sysB,G,T]=balreal(sys); sysB.a, sysB.b, sysB.c, G, T
sysB.a

sysB.b

sysB.c

-0.0356 -1.5276 -0.0329


1.5276 -3.5063 -0.4072
0.0329 -0.4072 -2.4581

0.1804
-1.4233
-0.0831

-0.1804 -1.4233 -0.0831

0.4569
0.2889
0.0014

T
0.5121 -0.8439 -1.5360
-0.7893 0.1554 -0.5514
0.3732 -0.8295 0.7452

, -.
G .
, ,
.
. -
, zpk(sys):
ans

2( s 2.414)( s 0.4142)
.
( s 1)( s 2)( s 3)

sysB
3.
bv sysB
Wc=gram(sysB, 'c'), Wo= gram(sysB, 'o'):
Wc =
0.4569 -0.0000 -0.0000
-0.0000 0.2889 -0.0000
-0.0000 -0.0000 0.0014

Wo =
0.4569
0.0000
0.0000

0.0000
0.2889
0.0000

0.0000
0.0000
0.0014

, G.
MIMO-
MIMO-

, ..
SISO-. , .. MIMO (Multy Input Multy Output Models). -
ss, tf zpk. r , ss- r ,
m , m .
MIMO- ,
, .
, rss
( random space state system).
, :
>> s=rss(5,2,3); impulse(s), figure, bode(s), figure, nyquist(s).

80

18 : 6 (
), 6 6 .
r m r m
ui y j , i 1,, r , j 1,, m . i j
Qij ( p) .
Q( p) m r . , tf(s).
tfdata: [n,d]=tfdata(s).
:
n=
[1x6 double] [1x6 double] [1x6 double]
[1x6 double] [1x6 double] [1x6 double]

d=
[1x6 double]
[1x6 double]

[1x6 double]
[1x6 double]

[1x6 double]
[1x6 double]

n d
Qij(p). ,
Qij. ,
:
>>tf(n{2,3},d{2,3}).

MIMO- lsim, U
, , u i , .
Y , , .
. ,
1

Q( s) s 1 1

( s 1) 2

3
s 3 .
s 1

s 2
2

MATLAB, :
>> N={1,3; 1, [1, -1]};
>> D={[1 1],[1 0 3]; poly([-1,-1]), [1, 2]};
>> sys=tf(N,D)

%
%
% MIMO-
Q(s)

:
Transfer function from input 1 to output...
1
1
#1: ----#2: ------------s+1
s^2 + 2 s + 1

Transfer function from input 2 to output...


3
s-1
#1: ------#2: ----s^2 + 3
s+2

.
, .
>> t=linspace(0,10); u1=sin(t); u2=cos(t); U=[u1;u2], Y=lsim(sys,[U],t); plot(t,Y) ,grid.

(.5.1):

81

2
1

0
-1
-2
-3

10

.5.1
MIMO- freqresp
m r W , m - , r , W . bode nyquist
, impulse step T m r ,
T .

,
MIMO- - ctrb, obsv, gram.

balreal, minreal, sminreal, modred.
.
. ,
. 5.2.
:
1) = 1+ 2+ 3;
2) 1, 2, 3.

1
p 1

1
p2

1
p3

1
p2

1
p3

1
p4

1
p3

1
p4

1
p5

y1

y2

y3

. 5.2

82

.
Q1 ( p), Q2 ( p), Q3 ( p) :
Q1 ( p)

1
1
, Q2 ( p)
,
( p 1)( p 2)( p 3)
( p 2)( p 3)( p 4)

Q3 ( p)

1
,
( p 3)( p 4)( p 5)

q(p) Q(p):
Q1 ( p )
q( p ) Q1 ( p ) Q2 ( p ) Q3 ( p ),
Q ( p ) Q2 ( p ).

Q3 ( p )
, 9.
, . , ,
1
q(p)
:
p3
1
1
1
1
1
1 1

.
q( p)

p 1 p 2 p 2 p 4 p 4 p 5 p 3
, 7
, .. 7 ( , ).
1
,

p2
1

.
p4
, .

.
: , ,
, . n0,
n1, n2, n3 .

R [ B, AB, , An1 B],

D [C T , (CA)T , , (CAn1 )T ]T ,

H = DR .
rankR n0 n1 , rankD n0 n2 , rankH n0 . n = n0 + n1 + n2 + n3
:
n0 rankH, n1 rankR rankH, n2 rankD rankH, n3 n rankH rankR rankD. (*)

MATLAB. ,
,
:
>>s1=ss(-1, 1, 1, 0); s2=ss(-2, 1, 1, 0); s3=ss(-3, 1, 1, 0);
>>s4=ss(-4, 1, 1, 0); s5=ss(-5, 1, 1, 0);
>> sys=s1*s2*s3+ s2*s3*s4 +s3*s4*s5;
% ( 1)
>> SYS=[s1*s2*s3; s2*s3*s4; s3*s4*s5]
% ( 2)
83


( ),
( )
.
-1
0
0
0
0
0
0
0
0

1
-2
0
0
0
0
0
0
0

sys.a, SYS.a
0 0 0 0 0
1 0 0 0 0
-3 0 0 0 0
0 -2 1 0 0
0 0 -3 1 0
0 0 0 -4 0
0 0 0 0 -3
0 0 0 0 0
0 0 0 0 0

0
0
0
0
0
0
1
-4
0

0
0
0
0
0
0
0
1
-5

sys.b, SYS.b
0
0
1
0
0
1
0
0
1

SYS.c
1 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0 0

sys.c
1 0 0 1 0 0 1 0 0

, SYS sys ,
( ).
1. sys .
:
>>R=ctrb(sys); D=obsv(sys); H=D*R;
>>r1=rank(R), r2=rank(D), r3= rank(H),
r1=5, r2=5, r3=4

(*) :
n0 r3 4; n1 r1 r3 1; n2 r2 r3 1;
n3 9 4 5 5 3.
,
n1= 1,
n2=1,
n3=3. n0 = 4.
:
>> wc=gram(sys,'c'), wo=gram(sys,'o'), r1=rank(wc), r2=rank(wo), r3= rank(wc*wo),
r1=5, r2=5, r3=4

minreal:
>>msys = minreal(sys);

zpk(msys),

:
5 states removed
Zero/pole/gain:

3 (s+3)
---------------------------(s+5) (s+4) (s+2) (s+1)

,
- :
>> zpk(sys)

3 (s+2) (s+3)^4 (s+4)


----------------------------------(s+3)^3 (s+4)^2 (s+5) (s+2)^2 (s+1)

3 (s+3)
-----------------------------(s+4) (s+5) (s+2) (s+1)

2. 1, 2, 3.
:
>> Wc=gram(SYS,'c'), Wo=gram(SYS,'o'),
>>r1=rank(Wc), r2=rank(Wo), r3= rank(Wc*Wo),
84

r1=5, r2=9, r3=5

(*) :
n0 r3 5; n1 r1 r3 0; n2 r2 r3 4;
n3 9 5 5 9 0.
,
:
. .
minreal:
>>mSYS=minreal(SYS)
4states removed.

MATLAB , mSYS
.
, -
, . , zpk-
:
zpk(SYS), zpk(mSYS)
Zero/pole/gain from input to output 1

1
#1: ----------------(s+1) (s+2) (s+3)

Zero/pole/gain from input to output 2

Zero/pole/gain from input to output 3

1
#2: ----------------(s+2) (s+3) (s+4)

1
#3: ----------------(s+3) (s+4) (s+5)

minreal [msys,U] = minreal(sys)


U,
, U*A*U',U*B,C*U'.



MATLAB .
,
.
n-
ynk an1 ynk 1 a1 yk 1 a0 yk bn1unk 1 b1uk 1 b0uk .

k , uk , k , ai, bi
.
, , . MATLAB
filter,
, .
b , :
y=filter(b,a,u).
.

SIGNAL, .
, ,
:
X k 1 AX k Bu k ,

yk CX k Duk .
85

X k R n ; uk , yk , A, B, C, D
.

z-,
.
x(t) y(t)
z- z-
Q(z) = Y(z)/U(z).

bn1 z n1 b1 z b0
Q( z ) n
.
z an1 z n1 a1 z a0
, ,

Q( z ) C ( zE A) 1 B D.
.
[4]. . 4.3
.
4.3

X AX Bu

y CX Du


b z m bm1 z m1 b1 z b0
Q( z ) m n
,

an z an1 z n1 a1 z a0

1 / z

Y ( z)
U ( z)

Q( z )

F ( p) f (t )e pt dt
0

X (t ) e At X 0


X k 1 AX k Bu k ,
yk CX k Duk
bm p m bm1 p m1 b1 p b0
,
an p n an1 p n1 a1 p a0
1 / p
Y ( p)
Q( p )
C ( pE A) 1 B D
U ( p)
z -

f ( n)
F ( z) n
n 0 z
Q( p )

X k Ak X 0

z i
e it , i zin ,

;
;
(k 0j k 1j n k mj n m1 ) z nj ,
t
(k 0j k 1j t k mjt m1 ) e j , z j m .
i m .

CONTROL
. ,
86

, ts
(sampling time).
. ,
1 1 / 2
1
X k 1
X k u k , yk 0 1X ,

1/ 2 1
0

, 0,7.
ss- :
>> a=[-1 -1/2 ;1/2 -1]; b=[1;0]; c=[0 1]; d=0; ts=0.7; s1=ss(a,b,c,d, ts).

:
a=
-1 -0.5
0.5 -1

b=
1
0

c=
0 1

d=
0

: Sampling time: 0.7 Discrete-time model.


tf zpk- , :
>> num=1; den=[1 1]; s2=tf(num,den, ts);

s2

1
z 1

>> z=[ ]; p=[-1 -2]; k=3; s3=zpk(z,p,k, ts)

s3

3
z z2
2

, .
ts:
>> s3.ts
ans = 0.7000


(step, impulse, initial,
lsim), .
lsim ,
, .
>> u=1./1:10;
% 1 1/3 .. 1/10.
>> % :
>> y=lsim(s1,u); y
ans =
0
0 0.5000
0 0.8750 0.2500 0.9063 0.8750 0.6172
>> % :
>> t=0:0.1:0.9; y1=lsim(s1,u,t)
??? Error using ==> rfinputs
Time sample spacing must match sample time of discrete-time models.
>> % :
>> t=0:0.7:(0.7*9); y1=lsim(s1,u,t);

1.6719

,
lsim CONTROL filter MATLAB.
, :
>> [n,d]=tfdata(s1);
87

>> yy=filter(n{1},d{1},u)
yy =
0
0 0.5000

0.8750

0.2500

0.9063

0.8750

0.6172

1.6719

, .
-

.
impulse. ( )
step. freqs freqz.
, -
Q( z) 1 /( z 2) :
>> [h,w]=freqz(1,[1 2], 200); plot(w,abs(h)), grid on


. Control Toolbox
2d ( continuous to discrete) d2c (discrete to continuous).
. 2d
. ,
.
impinvar bilinear (Signal Processing Toolbox).

SYMBOLIC. ztrans iztrans
z. ,
>>syms t, ztrans(t^2)

: ans =z*(z+1)/(z1)^3,
>>syms a t, ztrans(sin(a*t)),
: ans =z*sin(a)/(z^2-2*z*cos(a)+1).

z-:
t2

z ( z 1)
,
( z 1) 3

sin at

z sin a
.
z 2 z cos a 1
2

.
1. . , .
b , k.
n ?
. yn,
:
yn+1=yn(1+k)+b; y0=B.
z- y n Y( z ); y n1 z (Y( z) B),
:
z
z (Y( z ) B) (k 1)Y( z ) b
.
z 1
Y(z):
Bz B b
Y( z ) z
.
( z k 1)( z 1)
z- iztrans:
>> syms z b B k , Y=z*(B*z-B+b)/(z-k -1)/( z-1); y=iztrans(Y)
y =(-b+(k+1)^n*B*k+(k+1)^n*b)/k
88

b
b
, n y n (B )(k 1) n .
k
k
CONTROL SYMBOLIC
. .
2.

y k 1 xk
xk 1 5xk 6 yk 7uk .

( ) u
.
.
y
0 1
0
X , A
, B , C [0 1].

x
6 5
7
1 ().
Q C ( zE A) 1 B, z.
SYMBOLIC. :
>>syms z;
>>=[0 1;-6 5];=[0; 7];=[0 1];
>>Q=*inv(z*eye(2)-))*;
>>q=iztrans(Q); Q,q
Q=7*z/(z^2-5*z+6),q=-7*2^n+7*3^n

%
%
%
%

2 (). CONTROL:
>> A=[0 1;-6 5];B=[0; 7];C=[0 1];
>>sd=ss(A,B,C,0,1);
% Discrete-time model
>> s=tf(sd)
7z
Transfer function:
------------z^2 - 5 z + 6

Sampling time: 1,

:
>> syms z; q=iztrans(7*z/(z^2-5*z+6))
q = -7*2^n+7*3^n

: Q( z )

7z
, qn 7(3n 2 n ).
z 5z 6
2

MATLAB
, ,
.
. SIGNAL ,
.
buttap, cheb1ap, cheb2ap, ellipap,
- ,
.

89

-
. ,
, , ..
:
buttap ;
cheb1ap (
);
cheb2ap (
);
ellipap .
:
1
Q( p)
, An ( p) n- . Q( j )Q* ( j )
An ( p )
1
1

, Tn n.
2 2
2n
1 Tn ( )
1
s. MATLAB -
[z, p, k] = cheb1ap(n, Rp), n , Rp
( ).
.
:
>> [z,p,k]=cheb1ap(8,1);

- :
>>w=0:0.01:4;
>>h=freqs(k*poly(z), poly(p),w);
>>plot(w,abs(h));
>>sys=zpk(z,p,k); nyquist(sys)

. 5.3
Nyquist Diagram
1

0.8

0.8

0.6
0.4

Imaginary Axis

0.6
0.4
0.2
0

0.2
0
-0.2
-0.4
-0.6

0.5

1.5
w

2.5

-0.8
-1
-1

-0.8

-0.6

-0.4

-0.2

0.2

0.4

0.6

0.8

Real Axis

. 5.3
90


2 z 1
p
.
T z 1
MATLAB bilinear. :
[bz, az]= bilinear(b, a, F),

-,

F .

, .
:
butter .
cheby1 .
cheby2 .
ellip
.
( )
( ).
,
, 's'. ,
butter(n, w0, type, ' s') n
0.

SIMULINK. ,
,
, .


. MATLAB
, SIMULINK.

.
lsim ( initial).

dsolve SYMBOLIC.
.

y a 2 y 0.
:
>>y=dsolve('D2y+a^2*y=0'),
MATLAB : y=C1*sin(a*t)+C2*cos(a*t).
,
y C1 sin at C2 cos at.
y0 2, y 0 a, . :
>>y=dsolve('D2y+a^2*y=0, y(0)=2, Dy(0)=a').
: y = sin(a*t)+2*cos(a*t).
dsolve .
.
91

u 2v,

u0 v0 0,
:

v 2w,

w 2u

w0 3.

>> S=dsolve('Du=2*v, Dv=2*w, Dw=-2*u','u(0)=0, v(0)=0, w(0)=3').

MATLAB :
S=

u: [1x1 sym]

v: [1x1 sym]

w: [1x1 sym]

S :
>>u = S.u, v = S.v, w = S.w

MATLAB :
u=exp(-2*t)+3^(1/2)*exp(t)*sin(3^(1/2)*t)-exp(t)*cos(3^(1/2)*t)
v =-exp(-2*t)+3^(1/2)*exp(t)*sin(3^(1/2)*t)+exp(t)*cos(3^(1/2)*t)
w =exp(-2*t)+2*exp(t)*cos(3^(1/2)*t).

pretty.
MAPLE, :
u e

( 2 t )

v e

3 e t sin( 3 t ) e t cos ( 3 t )

( 2 t )

3 e t sin( 3 t ) e t cos ( 3 t )

w e

u(0) 1, v(0) 1, w(1) e 2 :

( 2 t )

2 e t cos ( 3 t ) .

>> S=dsolve('Du=2*v, Dv=2*w, Dw=-2*u', 'u(0)=1, v(0)=-1, w(1)=exp(-2)');


>>u = S.u, v = S.v, w = S.w
: u =exp(-2*t), v =-exp(-2*t), w =exp(-2*t).


ode23 ode45.
Ordinary Differential Equation, . ode45 , .
ode23 [t, X] = ode23('fun', [T0 T1], 0).
,
X F ( X , t ), X (T0 ) X 0

T0 t T1 .
t
X . ,
- F ( X , t ) ,
. m-,
, , 'fun'.
. ode23
y siny 0,8 y 3 ,

y(0) 1,

y (0) 0.

, 1 = y,

x2 y :

92

x1 x2 ,

1
X0 .
0

x2 0,8 x sin x1 ,
3
1

m- fun:
function F = fun (t, X)
F = [X(2); .8*X(1)^3-sin(X(1))];


>>0 = 0, 1 = 20, X0 = [1; 0];


>> [t, X] = ode23('fun', [T0 T1], X0).

t 0 20
, x1(t), x2(t). , .
plot(t, X).
( ), interp1:
>>tt = 0:0.1:20; XX = interp1(t, X, tt, 'spline');

tt.

deval . ode23:
>> SOL = ode23(@fun,[T0 T1], X0)

SOL, :
SOL =

solver: 'ode23'

extdata: [1x1 struct]

x: [1x90 double]

y: [2x90 double]

SOL x y. x , y
X (t ) . SOL.x SOL.y
deval SOL, ,
.
:
>>t=0:.1:20; y = deval(SOL,t); figure(2), plot(t,y,o')

. 5.4.
1

0.5

-0.5

-1

10
t

15

20

. 5.4
ode23
eps ( eps = 0.001). ode45
.
93

,
, .
MATLAB , ,
ode15s, ode23s, ode23t. S (Stiff)
, .
-
M ( X , t ) X F ( X , t ), M , F -.

,
. ,
.
MATLAB
bvp4c ( boundary value problem for continous).

.

sol=bvp4c (F, G, solinit)
Y F ( x, Y ) a, b ,
G(Y (a), Y (b)) 0 . bvp4c
F F ( x, Y ) ,
G G(Y (a ), Y (b)) solinit,
.
. bvp4c
- twobvp.
y y 0 ,
y(0) 0, y(4) 2 .

y1 y, y2 y , Y y1

Y F ( x, Y ) .

y2 .

y1 y 2
y2
, .. Y

.
y 2 y1
y1
twoode, x .
, ,
(boundary conditions).
Y (a) Y (b) ,
G(Y (a), Y (b)) . y(0) y(4) 2 T .
Y (a) Y (b) , ,
twobc. twoode twobc :
function dydx = twoode(x,y)
dydx = [ y(2); -abs(y(1)) ];

function res = twobc(ya,yb)


res = [ ya(1); yb(1) + 2 ];

solinit x y. x ,
y Y (x) . ,
bvpinit.
94

x. , y,
fun, x. :
function y= fun (x)
y=[x^2, x-1];
>> solinit = bvpinit([0 1 2 3 4],@ fun)
solinit = x: [0 1 2 3 4]
y: [2x5 double]
>> solinit.y
ans = 0 1 4 9 16
-1 0 1 2 3

>> solinit = bvpinit([0 1 2 3 4],[1 0])


solinit = x: [0 1 2 3 4]
y: [2x5 double]
>> solinit.y
ans = 1 1 1 1 1
0 0 0 0 0

bvp4c .

>>solinit = bvpinit([0 1 2 3 4],[1 0]); sol = bvp4c(@twoode,@twobc,solinit);

[0, 4].
bvp4c sol, x, y,
yp ( ) solver ( , bvp4c).
plot(sol.x,sol.y), . 5.5 ( ).
[0 1 2 3 4],
[1 0], ..
y , : y( x ) 1 , y ( x) 0 .
, y( x) 1 ,
y ( x) 0 , :
>>solinit = bvpinit([0 1 2 3 4],[1 0]);
>>sol = bvp4c(@twoode,@twobc,solinit);

( . 5.5).
, .
A BVP with two solutions
3
y0(x) = 1

2
y
1
y0(x))= -1
0
-1
-2

0.5

1.5

2
x

2.5

3.5

. 5.5
, bvp4c .
, plot(sol.x).
deval. sol,
, . , xint =
linspace(0,4); yint = deval(sol,xint); 100 ,
95

[0 4].

plot(xint,yint(1,:)).

, y y 0

y y 0 y 0
.

y y 0 y 0

y( x) C1 sin x C2 cos x
y( x) C3e t C4 e t ,
. y(0) 0, y(4) 2
, y (0) .
1. y(0) 0 , y( x) C3e x C4 e x . C3 , C4
y(0) 0 , y(4) 2 : C3e 0 C4 e 0 0, C3e 4 C4 e 4 2 . C3

2e 4
2e 4
.
,
C

4
e8 1
e8 1

sh x
. x 0 . ,
sh 4
. 5.5 .
2. y(0) 0 , y( x) C1 sin x C2 cos x , y(0) 0
C2 0, y( x) C1 sin x . y ( x) C1 cos x .
y ( x) C e x C e x .
x . ~

y ( x) 2

~
y (4 ) 2 y(0) 0 C3

1
, C 4 C3 .
sh (4 )

e x ex
2
~
y ( x)
. ~
.
y(0) y( ) C1
sh (4 )
sh (4 )
, . 5.5 :
sin x
sh(x )
y ( x) 2

0 t ; y( x) 2
0 4.
sh(4 )
sh(4 )

, ,
.

SIMULINK
SIMULINK . 3.
SIMULINK
, MATLAB.
DEE


SIMULINK.

.
DEE (Differential Equation Editor).
SIMULINK ,
96

. , "" ,
, .
dee. ,
Differential Equation Editor, ( )
SIMULINK,
( , .).


y siny 0, y(0) y (0) 0,
:
x1 x2
x 2 sin x1
Name:

pendulum

# of inputs

First order equations, f(x,u):

x0

x(2)
-sin(x(1))

dx/dt=

1
0

Output equations, f(x,u)


x(1)
x(2)

y=


diffeqed.
. 5.6.
Scope Number of axes
. ,
.
,
, , , look under
mask, , . 5.6.

Differential Equation
Editor
DEE

u(1)

u(2)

1/s

Port1

y1

x1

Integ1

SysMux
Mux

Scope

u(2)

f(u)

1/s

Port2

y2

x2

Integ2

. 5.6
97

Simulink-


,
SIMULINK,
Output Point
Input Point
,
Linear Analysis Tools ,
SIMULINK.
. 5.7
LTIview.
,
Input Point, Output Point Control_System_Toolbox (
Model_Inputs_and_Outputs) (. . 5.7).
( ), SIMULINK,
. linmod.
, . 5.8,
test_sys.mdl.
, In Out.
1

In1

x2
s
Integrator

s+1

x1

Out1
Scope

Transfer Fcn

Step

Gain

. 5.8

k=1.
[A,B,C,D]=linmod('test_ sys'), :
A = -1
-1

1
0

B=

0
1

C=

D=

linmod 0 4.
,
.
, ..
, X 0 . Simulink-
trim ( trim ;
). mdl-,
X,
u y. dX
.
[X,u,y,dX]=trim('test_ sys') :
X=

0.5
0.5

u = 0.5

y=

0.5000

dX = 0
0

98

, u= 0,5, =0,5 v=1


, 2=0,5 .
1, 2 .
k, k=2, [X,u,y,dX]=trim('test_cx').
:
X=

0.3333
0.3333

u = 0.3333

y=

0.3333

dX = 1.0e-015 * 0
0.1110

u= 1/3, 1= 2 =1/3.
. k = 1
x1 x1 x2 , x 2 x1 u v, y x1 , v 1.
x 2 0 , x1 u = 1.
x1 u, . trim
x1 = 0,5; u = 0,5 ( [1 1]).
x1 + x2 = 0, y = x1, x2 = y = 0,5.
k = 2 x1 x1 x2 , x 2 2 x1 u 1, y x1 .
x 2 0 , 2x1 u = 1. trim
x1 = 1/3, u = 1/3 (, x1 = 2/5, u = 1/5,
[2 1]).
SIMULINK

, Simulink- ,
, .
, ,
Edit/Create subsystem. , ,
. ,
(Edit/Mask subsystem).
Edit/Look under mask.
Edit/Edit mask . Unmask,
,
SIMULINK.
. ,
. ,
g1 g2. , , -,
2 Gains (. 5.9, ) , -,
,
(. 5.9, ).

99

2 gains

Constant

Scope
Subsystem

. 5.9
Icon Draw commands

plot( (1+sin(0:0.2:6.2))/2,(1+cos(0:0.2:6.2))/2)
text(0.1,0.5,'2 gains')

Units Normalized, ,
1x1.
Parameters g1 g2 (
) Gain 1 Gain 2,
.
. .

y1 ky1 y2 0,
y2 y1 y 2 0.

SIMULINK . 5.10, .
, .
, , . 5.10, .
.
, .

100

a)

y1

1
s

1
s

Integrator

Integrator1

y2

1
s

1
s

Integrator2

Integrator3

-K-

-1

Gain1

Gain2

Scope1

)
y2

y1
In1

Out1

In1

Out1

Scope2
Subsystem1

Subsystem2

. 5.10

y1 (0) 0,

. 5.11
y2 (0) 1 k=1.2.

0.5

-0.5

-1

10

15

20
t

25

30

35

40

. 5.11
Simulink- MATLAB

SIMULINK
.
, .
101

, Simulink-
open. , open('vdp') vdp.mdl (
).
sim, , sim('vdp').
, ( ),
. y=sim('model',timespan,options,ut),
timespan , ut ,
.
. , . 5.12
simple_model. 30.
.

1
In1

1
s

Integrator

Gain

1
Out1

>>open('simple_model');
>>t=0:0.1:30;
>>sim('simple_model',[0 30],[],[t' sin(t')])

>> [t1,y1]=sim('simple_model',[0 30],[],[t' sin(t')]);


Scope

>>plot(t1,y1)

. 5.12
Scope
.
plot , sim .
sim simset.
ode23:
>> [t2,y2]=sim('simple_model',[0 30],simset ('Solver','ode23'),[t' sin(t')]);

, simget,
, o=simget ('simple_model').
,
. get_param set_param.

, get_param(gcb, 'objectparameters').
. gcb . ,
Gain, gcb 'simple_model/Gain'.
get_param , ,
>> p=get_param('simple_model/Gain', 'Gain'), class(p)
p =3

ans =har

, . , , ,
3 4 set_param,
set_param('simple_model/Gain', 'Gain',4), set_param('simple_model/Gain', 'Gain',num2str(4))!
, ,
( , )
MATLAB for.
( ).

102

y 0,3 y sin y 0.

y02 y 02 R 2 ( R
). y0 , y 0 ,

E y 2 dt extremum .
0

. SIMULINK sys.mdl (. 5.13).

sin
Trigonometric
Function

1
s

1
s

y
Scope
1

0.3

Out1
Gain

. 5.13
.
1 ( ).
,
, .

MATLAB

y R sin , y 0 R cos , 0 .
m-
optic.m.
Program optic
open('sys');
E=zeros(1,200); R=1;
for i=1:200
x0=R*cosd(i); y0=R*sind(i);
set_param('sys/x','initial',num2str(x0));
set_param('sys/y','initial',num2str(y0));
sim('sys',[0,40],[],[]);
E(i)=trapz(tout,yout.^2);
disp(i);
end
plot(E,'LineWidth',2);grid
title('ENERGY vs. IC angle'),

%Optimal Initial Condition for sys.mdl


% sys.mdl
%
%
%
%
%
% i
%
%

R=1 . 5.14. ,
2,4.

103

ENERGY vs. IC angle

2.8

ymin

2.6

ymax

0.5

2.4
2.2
y

1.8
1.6

-0.5

1.4
0

50

100

150

200

-1

10

15

20

25

. 5.14
, :
[EM,iM]=max(E);x0M=cosd(iM);y0M=sind(iM); [Em,im]=min(E);x0m=cosd(im);y0m=sind(im);
disp('iM,x0M y0M EM='),[iM,x0M y0M EM], disp('im,x0m y0m Em='),[im,x0m y0m Em],

:
iM,x0M y0M EM = 47 0.6820
im,x0m y0m Em = 136 -0.7193

0.7314
0.6947

2.4118
1.2637

, , =2,412,
=47, .. y0 0,682, y 0 0,731 (
). ,
=1,264,
=136, .. y0 0,719, y 0 0,695 (
).
. 5.14, .
R ,
, .
,
( ). . 5.15
()
() R=2,29,
.

104

ENERGY vs. IC angle

R=2.29

60

50

40

30

20

10

-1

50

R=2,29

100

iM,x0M y0M EM= 41

150

1.7283

200

1.5024 51.8763

-2

10

15

im,x0m y0m Em= 122 -1.2135

20
1.9420

25

6.5953

. 5.15
2 ( fmincon). . 4.2.1
MATLAB .
( ),
( ) (
):
E f ( x0 , y0 ) extr , g ( x0 , y0 ) x02 y02 R 2 0.
fmincon.
, .
m- energy nlcon:
function energy
function E = energy (x)
%open('sys');
x0=x(1); y0=x(2);
set_param('sys_old/x','initial',num2str(x0,15));
set_param('sys_old/y','initial',num2str(y0,15));
[tout,xx,yout]=sim('sys_old',[0,40],[],[]);
E=trapz(tout,yout.^2);

function nlcon
function [h,g] = nlcon(x)
h = [];
R=1;
%R=2.29;
g = x(1)^2+x(2)^2-R^2;

, fmincon:
>> [X,E]=fmincon('energy',[1;1],[],[],[],[],[],[],'nlcon')


( R=1).
, trapz
energy . :
R=1
X = 0.7198
-0.6942

norm(X)
1

E=trapz(tout,yout.^2)
E =1.2637

R=1
X = 0.6844
0.7291

norm(X)
1

E=-trapz(tout,yout.^2)
E = -2.4118

, .
105

R=2.29,
:
R=2.29
X = 1.7201
1.5118

norm(X)
2.2900

E=-trapz(tout,yout.^2)
E = -51.8823

R=2.29
X = 1.2100
-1.9442

norm(X)
2.2900

E=trapz(tout,yout.^2)
E = 6.5955

energy.
(%), sys.mdl
, .
, open('sys') .
num2str(x0,15).
x0, . ,
4, (
, ).
MATLAB
,
,
, .


1. . MATLAB

:
) x a sin x 0 ;
) -- x ( x 2 1) x x 0 ;
) x 2 x x 3 0 .
: 0 . 0

x0

2. . MATLAB
y 3 y 2 y 4u; , h =
0,1. .
.
h 0,1 .
p1 1; p 2 2;
z i e pi h :
z1 e 0,1 ; z 2 e 0,2 .

( z z1 )( z z 2 ) z 2 (e 0,1 e 0,2 ) z e 0,3 z 2 1,724 z 0,741 0.
y n 1,724 y n 1 0,741y n 2 x n 2 .

= 1. y . 2;

y n

1 1,724 0,741

0,017

, 0,034 .
106

, y n 1,724 y n 1 0,741y n 2 0,034 x n 2 .


:
y n 4(0,905) n 2(0,819) n 2 .
y(t ) 4e t 2e 2t 2 ,
MATLAB. c2d, impinvar bilinear:
>> sys=
tf(4,[1 3 2])
4
------------s^2 + 3 s + 2

>> sysd =
c2d(sys,0.1,'imp')
0.3444 z
---------------------z^2 - 1.724 z + 0.7408

>> [bz,az] =
impinvar(4,[1 3 2],10)
bz = 0 0.0344
az =1.0000 -1.7236 0.7408

>> [numd,dend] =
bilinear(4,[1 3 2],10)
numd = 0.0087 0.0173 0.0087
dend = 1.0000 -1.7229 0.7403

, impinvar.
3. . , ,

0
0
0
0
2 1
1
1 2 0

0
0
0
0

0
1

2
1
0
0
X
X u ,
0
1 2 1
0
0
0
0
0
0
0
1 2 1


0
0
0
1 1
0
0

1 0 0 0 0 0
Y
X.
0 0 0 0 0 1

u , xi .
Y .
:
) SIMULINK
;
) ,
.
4. .
:
..
..
kx
ky
x
, y
.
2
2
2 3
(x y )
( x y 2 )3

km3
.
c2
SIMULINK
x0 0; y0 6478,388 , x 0 7,89 /c, y 0 0 . ,
k=3,9870 105

h x 2 y 2 z 2 R3 , R3 =6378,388 .
5. . -1 (1970-71.), 700, 2 1/ 2/,
11 10 . , ,
.
:
y (t ) ay(t T ) a y .

107

a=1
, .5.16.
SIMULINK
y 1 , y(t) y f ( y ) ,
.
,
. (, ).

1
y

1
..

. 5.16.

108

16.06.2005 mtl_M5_checked

MATLAB

MATLAB , , ,
. , . 5.1
. 90%
double, cell . MATLAB
(array). , MATLAB
.
cell

Java class

ARRAY

logical

char

function handle

NUMERIC

structure

user class

single

double

int8, uint8,
int16, uint16,
int32, int32,
int64, uint64

. 6.1
double array , , .
MATLAB ,
1x1:
>> c=3; size (c)
ans =1 1

109

(cell array).
: , , , , ..
{ }:
>> c={1,2 3; 'scrambled eggs',[12, 13, 14], -0.3}
c=
[
1]
[
2]
[
3]
'scrambled eggs' [1x3 double] [-0.3000]

, .
, double,
:
c{1,2}
ans =
2

c{2,1}
ans =
scrambled eggs

c{2,2}=18
c=
[
1]
'scrambled eggs'

[ 2]
[18]

[
3]
[-0.3000]

size length , :
>> size(c)
ans =
2 3
>> length(c)
ans = 3

>> c1={1,2 ,3}


c1 =
[1] [2] [3]
>> size(c1)
ans = 1 3

>> length(c1)
ans =
3

>> c2={3,; 4 ; 7}
c2 =
[3]
[4]
[7]

>> size(c2)
ans =
3 1
>> length(c2)
ans = 3

,
.
double cell array,
, num2cell, mat2cell cell2mat.
num2cell, ,
. 2 (two) to ().
>> a=[1 2; 3 4]
a=
1 2
3 4

>> num2cell(a)
ans =
[1] [2]
[3] [4]

>>n1=num2cell(a,1)
n1 =
[2x1
double]
[2x1 double]

>> n1{1}
ans =
1
3

>>n2=num2cell(a,2)
n2 =
[1x2 double]
[1x2 double]

num2cell .
. ,
, . num2cell(a,1)
, num2cell(a,2) .
cell2mat num2cell,
:
>> cell2mat(num2cell(a))
ans =
1 2
3 4

>> cell2mat(num2cell(a))-a
ans =
0 0
0 0

mat2cell .
,
. , , . ,
110

1 2, 2, 3 1. [1 2] [2 3
1] mat2cell.
mat2cell .
>> b=[ 1 2 3 4 5 6; 7 8 9 10 11 12; 13,14,15, 16, 17, 18 ]
b=
1

10

11

12

13

14

15

16

17

18

>> b1=mat2cell(b,[1 2],[2 3 1])


b1 =
[1x2 double] [1x3 double] [
6]
[2x2 double] [2x3 double] [2x1 double]

>> b1{1,1}
ans =
1 2
>> b1{1,2}
ans =
3 4 5

>> b1{1,3}
ans =
6
>> b1{2,1}
ans =
7 8
13 14

>> size(b)
ans =
3 6
>> b1{2,2}
ans =
9 10 11
15 16 17

>> b1{2,3}
ans =
12
18


, MATLAB .
, .
MATLAB .
, ,
. class isa (is a .).
, , 1 0,
, .
double cell array:
>> a=[1 2 3]
a= 1 2 3
>> b={4,5,6}
b = [4] [5] [6]

>> class(a)
ans = double
>> class(b)
ans = cell

>> isa(a,'double')
ans = 1
>> isa(a,'cell')
ans = 0

>> isa(b,'double')
ans = 0
>> isa(b,'cell')
ans = 1

>> class(class(a))
ans =char

, (struct).
MATLAB struct,
: struct (1, 1, 2, 2, ..).
.
, :
>> d = struct('strings',{{'hello','yes'}},'lengths',[5 3])
d=
strings: {'hello' 'yes'}
lengths: [5 3]

>> d.strings
ans =
'hello' 'yes'

>> d.strings{1}='no'
d=
strings: {'no' 'yes'}
lengths: [5 3]

, ,
, . ,
. struct .
f1 , ,
f1 ,
111

. ,
struct ,
. ,
:
>> d = struct('strings',{'hello','yes'},'lengths',[5 3])
d=
1x2 struct array with fields:
strings
lengths

>> d.strings
ans =
hello
ans =
yes

>> d.lengths
ans = 5 3
ans = 5 3

>> u=struct('f1',{1,2},'f2',{3,4})
u = 1x2 struct array with fields:
f1
f2
>> u=struct('f1',{1,2},'f2',{3,4,5})
??? Error using ==> struct
Array dimensions of input 4 must match those of
input 2 or be scalar.
>> u=struct('f1',{1,2},'f2',{3,4},'f3',{5,6})
u = 1x2 struct array with fields:
f1
f2
f3

>> u(1)
ans =
f1: 1
f2: 3
>> u(1)
ans =
f1: 1
f2: 3
f3: 5

>> u(2)
ans =
f1: 2
f2: 4
>> u(2)
ans =
f1: 2
f2: 4
f3: 6

>> size(d)
ans = 1 2
>> d(1)
ans =
strings: 'hello'
lengths: [5 3]
>> d(2)
ans =
strings: 'yes'
lengths: [5 3]

: isfield, getfield, setfield, rmfield,


fieldnames. isfield (s,fldname) 1 s fldname 0
. getfield (s,fldname) fldname s, ..
s.fldname. setfield (s,fldname,fldvalue) s,
fldname fldvalue. s , ..
s.fldname=fldvalue. rmfield(s,fldname)
fldname s. ,
: s.new_field_name=some_value. fieldnames(s)
, s.
.
>>u=struct('f1',1,'f2',0.1)
u=
f1: 1
f2: 0.1000

>> isfield(u,'f1')
ans = 1
>> isfield(u,'f3')
ans = 0

>> fieldnames(u)
ans =
'f1'
'f2'

>>rmfield(u1,'f2')
ans = f1: -1

>> getfield(u,'f1')
ans = 1
>>setfield(u,'f1',-1)
ans =
f1: -1
f2: 0.1000
>> u1
u1 =
f1: -1
f2: 0.1000

>> u
u=
f1: 1
f2: 0.1000

>>u1=setfield(u,'f1',-1)
u1 =
f1: -1
f2: 0.1000

>>u2=rmfield(u1,'f2')
u2 =
f1: -1

>> fieldnames(u2)
ans = 'f1'
>> u2.f1=19
u2 = f1: 19

struct,
.
MATLAB,
ss, tf, zpk, lti , ,
. MATLAB , ,
, , ,
.

112


MATLAB . ,
, m-
.
who, whos, clear, save, load. who
mat-. whos
who. ,
:
>> a=17;
>>b={'ratata','gagaga'};
>> who
Your variables are:
a b

>> whos
Name
Size
Bytes Class
a
1x1
8 double array
b
1x2
144 cell array
Grand total is 15 elements using 152
bytes

>> v=who
v = 'a'
'b'
>> w=whos
w = 3x1 struct array with
fields:
name
size
bytes
class

>> w(1)
ans =
name: 'a'
size: [1 1]
bytes: 8
class: 'double'
>> w(1).bytes
ans =
8

,
,
.
, clear.
, ,
, , , Java
.
:
>> a=1; b=2; c=3; global d; d=8;
>> who
Your variables are:
a ans b c d v w

>> clear c;
>> who
Your variables are:
a ans b d v w
>> clear globals;

>> who
Your variables are:
a ans b d v w
>> clear
>> who


workspace. GUI,
, openvar. , ,
:
>> m=eye(5); openvar('m').


, save load. :
save _ 1 2 .
load _ 1 2 .
load _

:
>> a=1; b=2; c=3; global d; d=8;
>> save file1 a b d
>> clear

>> who
>> load file1
>> who

Your variables are:


a b d

113

MATLAB- *.mat.
mat- , C FORTRAN API.

MATLAB
v4 v6. mat-,
4- 6- , .
ASCII-, ascii:
>> m=[23 67; 90 890];
>> save file2 m -ascii
>> clear m
>> load file2 m -ascii
>> m
??? Undefined function or variable 'm'.

>> who
>> n=eye(5)
Your variables are:
n=
file2
1 0 0 0 0
>> file2
0 1 0 0 0
file2 =
0 0 1 0 0
23 67
0 0 0 1 0
90 890
0 0 0 0 1
>> load file2 -ascii
??? Error using ==> load
Number of columns on line 3 of ASCII file
C:\MATLAB\work\file2
must be the same as previous lines.

>> m=[23 67; 90 890];


>> save file2 m n -ascii
>> clear

, ASCII-
MATLAB. , . ,
, . ,
ASCII ,
.
MATLAB / ,
/ .
MATLAB ,
. dir, type, pwd, cd, what, matlabroot, path, addpath, rmpath,
genpath, rehash, which.
type m-, , type misha
c misha.m, .
(.m, .mat, .bat, ...) , m-.
pwd cd ,
:
>> pwd
ans = C:\MATLAB\work

>> cd ..
>> pwd
ans = C:\MATLAB

dir (directory) ,
.
name, date, bytes isdir. what ,
, ,
MATLAB. path, m, mat,
mex, mdl, p, classes. path , m m- , mat
mat- .. .mex .p
MATLAB- , . classes
. what dir:
>> d=dir(pwd)
d=
194x1 struct array with fields:
name
date

>> d(1)
ans =
name: '.'
date: '05-Jan-2003 16:19:16'
bytes: 0

>> d(2)
ans =
name: '..'
date: '05-Jan-2003 16:19:16'
bytes: 0

114

bytes
isdir
>> d(3)
ans =
name: '1.TXT'
date: '16-Feb-2005 00:19:52'
bytes: 2104
isdir: 0

isdir: 1

isdir: 1

>> w=what(pwd)
w=
path: 'C:\MATLAB\work'
m: {105x1 cell}
mat: {2x1 cell}
mex: {0x1 cell}
mdl: {18x1 cell}
p: {0x1 cell}
classes: {3x1 cell}

>> w.mat
ans =
'hanke14.mat'
'hanke15.mat'

cd (change directory) ,
.
, D:\MATLAB\BIN D:\MATLAB \CONTROL
cd \MATLAB \ntrol
matlabroot , MATLAB.
path , . addpath rmpath
. addpath
BEGIN END.
genpath ,
. rehash ,
MATLAB, , .
, m- ,
, .
which, m-. ,
>> which tmp08
C:\MATLAB\work\tmp08.m


MATLAB quit
exit. MATLAB .
MATLAB 4
:
;
PERL-;
Java;
COM-.
!. ,
.
&, . ,
:
>>path

>> ! path

>> ! path &

&, MS DOS.
,
system ( ), dos unix. : [status, result]
= DOS('command', '-echo'), status , result .
'-echo' . Windows 98 Windows ME
DOS bat- 0.
MATLAB PERL (. , ,
C:\MATLAB\sys\perlsys\perl), .
115

PERL- MATLAB perl.


result=perl(perlfile,arg1,arg2,...), perlfile , arg1, arg2 ..
.

MATLAB
MATLAB ,
.
MATLAB if switch. if
:
if

elseif

else

end

, a is even a.
>> if rem(a,2) == 0
disp('a is even')
end

, : a is even
for while. for
. ,

>> for i=1:5


x(i)=0
end

0 x.
, x(1:5)=0.
while
. , while:
n, n! 100- .
>> n = 1; f=1;
while log10(f) < 100
f=f*n; n = n+1;
end
disp(n-1)
70

break,
continue. input, ,
.
's'.

m-
116

- . 1.2.
MATLAB MATLAB. , ,
.
,
.
function hello_world;
disp('Get lost!!!');

, , ,
, , function, ..
hello_world.m
.
function d=sum3(a,b,c)
d=a+b+c;

, ,
ans:
>> a=sum3(1,2,3)
a= 6
>> sum3(1,2,3)
ans = 6

,
, :
function [s,d]=sum_and_difference(a,b);
% function [s,d]=sum_and_difference(a,b);
% This function returns sum and difference of two values.
s=a+b;
d=a-b;

:
>> [x1,x2]=sum_and_difference(3,5)
x1 = 8
x2 = -2

, ,
help :
>> help sum_and_difference
function [s,d]=sum_and_difference(a,b);
This function returns sum and difference of two values.

MATLAB
MATLAB .
:
varargin ,
varargout ,
117

nargin ,
nargout .
,
. ,
varargin{1}, varargin{2} .. sum_and_difference ,
.
function varargout=sum_and_difference2(varargin);
if nargin>=1
a=varargin{1};
else
a=0;
end
if nargin>=2
b=varargin{2};
else
b=0;
end
s=a+b;
d=a-b;
if nargout==2
varargout{1}=s;
varargout{2}=d;
else
varargout{1}=[s, d];
end

:
>> [a,b]=sum_and_difference2(3,7)
a = 10
b = -4
>> a=sum_and_difference2(3,7)
a = 10 -4

>> a=sum_and_difference2(3)
a= 3 3
>> [a,b]=sum_and_difference2(3)
a= 3
b= 3
>> sum_and_difference2
ans = 0 0

MATLAB,
, .

.

.
global:
function a2=test_global
global a;
a2=a^2;

,
:
>> a=5
a= 5

>> a
a= []
118

>> %
>> test_global
ans = [ ]
>> global a;
Warning: The value of local variables may have been changed to
match the globals. Future versions of MATLAB will require that
you declare a variable to be global before you use that variable.

>> a=5
a= 5
>> test_global
ans = 25

, ,
isglobal:
>> a=9;
>> isglobal(a)
ans = 0
>> global a;
Warning: The value of local variables may have been changed to match the
globals. Future versions of MATLAB will require that you declare
a variable to be global before you use that variable.
>> isglobal(a)
ans = 1


assignin evalin.
assignin(ws,'name',v), ws , 'name' ,
v . ws 'base'
'caller' .
assignin, , v 'name'
ws. (
) , evalin(ws,'expression').
'caller' ,
.
'caller'.
assignin_demo1 assignin_demo2:
function m=assignin_demo1
disp('m in assignin_demo1 workspace:')
m=[1 2 ; 3 4]
assignin_demo2;
disp('After calling assignin_demo2 m had changed:')
disp(m)
function assignin_demo2
m=evalin('caller','m');
disp('m in caller(assignin_demo1) workspace:')
disp('Let''s change m and pass it back to assignin_demo1 workspace:')
m=[5 6; 7 8]
assignin('caller','m',m);

assignin_demo1 :
>> k=assignin_demo1
m in assignin_demo1 workspace:
m= 1 2
3 4
m in caller(assignin_demo1) workspace:
119

Let's change m and pass it back to assignin_demo1 workspace:


m= 5 6
7 8
After calling assignin_demo2 m had changed:
5 6
7 8
k=
5 6
7 8

'base'
k=assignin_demo3:
function k=assignin_demo3
k=evalin('base','a+8');

:
>> a=19;
>> k=assignin_demo3
k = 27

MATLAB-
persistent.


1. m-, ,
.
. dir; , ;
sort, [a,b]=sort({'asasa','aaaaa','akkkk'}),
.
2. function myfunc(p1,p1,varargin).
) myfunc(17,64,[24 -5 0],{78,90,[8 9]})
nargin? ) varargin{2}? varargin{3}?
: ) nargin=4, ) varargin{2}={78,90,[8 9]}, varargin{3}
3. global a.
: function f=mufunc a=1:10; f=sum(a);
a?
: ,
( global ).
3. mufunc1?
function f=mufunc1
a=a+1:10;
f=fum(a);

: (. ).
4.
s=(1:3)'; k=0;
for i=s
k=k+i;
end
k

.
: s ,
k=
120

1
2
3

i=[1 2 3]'
5. ) , , k=6? )
, s={1,2,3}?
: s=1:3, s=(1:3)'.
) .
6. , myfunc, dir1 dir2.
, ? 3 .
:
1: display(1) display(2), ,
, (1 2).
2: , .
3: which.
7. , for, while
.
. sum/cumsum. :
, iztrans, initial
8. , myfunc1
error('Something wrong');
myfunc2, ,
myfunc1 .
?
. try/catch.
9. , a.
a.m?
: .
10.
k=7
if k=8
disp('k=8!')
end

: if k= =8 ( =, = =).

121


MATLAB ,
, ,
, .
, , 1000 , 30
, SIMULINK .
, EXCEL,
WORD, MAPLE.
.
-
, , [1-5, 10, 11, 13].
,
, MATLAB.

MATLAB
MATLAB.


1.
. . MatLab 5.3/6.. -.: -, 2003.
2.
., . MATLAB. -.: ,
2001.
3.
.. MATLAB 6/6.1/6.5 + SIMULINK 4/5 . -.:
-, 2003.
4.
., . SIMULINK 4. . -M.: ,
. 2003.
5.
., ., . MATLAB 6.x:
. -.: -, 2004.
6.
.., .. MATLAB. . . ., , 1994.
7.
.. . -.: , 1970.
8.
. . . . . ., ,
1992.
9.
. . . . .
-., , 2004.
10.
.., .. Matlab .-: -, 2005.
11.
. . MATLAB 6: . .:
-, 2003.
12.
. . -C.: , 2002.
13.
. . : . 2- . -.:
"", 2002.
14.
., ., . MATLAB . -., .
2001.

122

Anda mungkin juga menyukai