..
:
蒒
( 200101)
2013.
- .
: ..., ..
..
: 200101: .: , 2013. . 67.
.16. . 28. .: 6 .
4- 200100 .
" " , , Matlab Simulink, .
.., 2013
, 2013
充3
充.5
1 Matlab.5
1.1 Command Window6
1.2 - Workspace..8
1.3 m-ⅅ.9
2 Matlab..11
2.1 酅.11
2.2 () ode23, ode45.13
2.3 trapz15
2.4 quad, quad 8.16
2.5 .17
2.5.1 icubic...18
2.5.2 spline.19
2.5.3 interp 1..20
2.5.4 interpft.21
3 充23
3.1 .23
3.2 limit.23
3.3 solve24
3.4 diff.25
|
|
3.5 dsolve..26
3.6 int.26
4 셅.27
4.1 셅...27
5 Matlab.41
6 Simulink.44
7 Simulink...51
7.1 51
7.2 Simulink...52
8 ...54
8.1 1..55
8.2 2..55
8.3 3..55
9 55
...65
..66
Matlab - . , , , . Matlab - :
- ;
- ;
- ;
- , ;
- ;
- , .
1 Matlab
Matlab 4- , : Workspace, Command Window, Command History, Current Director ( 1)
1 Matlab
Workspace ( ) , , .
Command Window , .
Command History , .
Current Directory .
Windows. , , View.
1.1 Command Window
Matlab Command Window ( ), : , , . Matlab, Windows - ( 2). , >>.
2 Matlab
. , , Windows, Matlab , - , Windows.
|
|
Matlab (session). - , . , , . , ( ) ( mat), Save.
, . ( 3).
. , , Windows, Matlab , - , Windows.
3 ,
Matlab clc, , , Matlab. , d, ENTER :
>> d
d =
28. 8496
1.2 - Workspace
, , , Matlab ( Matlab - Workspace). ( 4).
4
. : Desktop/ Workspase.
:
- ;
- ;
- , .. ( delete);
- , , , , .
Open. . Delete , Close .
Array Editor
Workspase , , Array Editor, . 5 , , .
5 Command Window, Workspace, Array Editor
1.3 m-
, m- . Windows ( 6). m- Edit File/ New/ M-file
6 m-
:
- , Save As File ;
- Run.
, / - - Matlab. , .
/ . m- () , . .
|
|
:
- , (). , (, ), . .;
- .
, , who.
, Matlab. , 6,
>> who
Your variables are: >>
Matlab . ,
File/ Save Workspace as...
Windows . , Matlab mat, mat-.
/ m- . :
- - ;
- , - ;
- % - ;
- ( ) - ;
- - .
. . , (, - + cos(x) sin(x) . .), .
2 Matlab
2.1
Matlab / \. :
A⋅ X= B, (1)
A NxN, a B
N, \ A \ B. \ , A B A \ B, :
inv(A) * B (2)
inv(A) , A. / . A / B B * inv(A). , (1)
, , . A⋅ X=B (A m´n, B- n´k, k - ) \. , :
x1+2 x2+3 x3= 3
5 x1+4 x2+3 x3= 9 (3)
3 x1+4 x2+3 x3= 6
|
|
()
A=[1 2 3; 5 4 3; 3 4 3]
B=[3 3; 9 9; 6 7]
X=A\B
X = 1.5000 1.0000
0.0000 1.0000
0.5000 0.0000
2.2 () ode23, ode45
:
[t, X] = ode23(< >, t0, tf, x0)
[t, X] = ode23(< >, t0, tf, x0, tol, trace)
[t, X] = ode45(< >, t0, tf, x0)
[t, X] = ode45(< >, t0, tf, x0, tol, trace)
:
ode23 ode45 . , . 1- :
(4)
x - ;
t - ;
f - - x, t.
[t, X] = ode23(< >, t0, tf, x0, tol, trace) [t, X] = = ode45(< >, t0, tf, x0, tol, trace) , - 2- 3- 4- 5- .
:
:
< > - , m-, ;
t0 - ; tfinal - ;
x0 - ;
tol - ; ode23 tol = 1.e-3, ode45 tol = 1.e-6);
trace - , ; , ;
:
t - ;
X - , .
:
2- , :
(5)
:
(6)
- m- ; vdpol.
function xdot = vdpol(t, x)
xdot = [x(2); x(2).* (1 - x(1).^2) - x(1)];
, vdpol 0 <= t <= 20, ode23:
t0 = 0; tf = 20;
x0 = [0 0.25]'; %
[t, X] = ode23('vdpol', t0, tf, x0);
plot(t, X), grid, hold on
gtext('x1'), gtext('x2')
7
7 -
ode23 ode45 - . , . ode45 , . interp1.
2.3 trapz
:
I = trapz(x, y)
I = trapz(y)
:
I = trapz(x, y) y x, . x y , Y , size(Y, 1) = length(x). . I = trapz(y) , , ; , h , , h.
:
(7)
.
x = 0:pi/100:pi; y = sin(x);
I = trapz(x, y) I = pi/100*trapz(y)
:
I = 1.9998.
2.4 quad, quad8
quad - 2- ( ), quad8 - 8-
- , (7)
:
[I, cnt] = quad(< >, a, b)
[I, cnt] = quad(< >, a, b, tol)
[I, cnt] = quad(< >, a, b, tol, trace)
[I, cnt] = quad8(< >, a, b)
[I, cnt] = quad8(< >, a, b, tol)
[I, cnt] = quad8(< >, a, b, tol, trace)
:
quad quad8 .
[I, cnt] = quad(< >, a, b) [I, cnt] = quad8(< >, a, b) ; , -. cnt , .
|
|
[I, cnt] = quad(< >, a, b, tol) [I, cnt] = quad8(< >, a, b, tol) tol. tol = 1e-3.
[I, cnt] = quad(< >, a, b, tol, trace) [I, cnt] = quad8 (< >, a, b, tol, trace), trace , , .
:
7.
.
[I, cnt] = quad('sin', 0, pi) [I, cnt] = quad('sin', 0, pi, 1e-4, 1)
I = 2.0000 I = 2.0000
cnt = 17 cnt = 33
Matlab :
icubic - ;
spline - ;
interp1 - ;
interp2 - ;
interpft - .
, .
2.5.1 icubic
:
yi = icubic(y, xi)
yi = icubic(x, y, xi)
:
yi = icubic(y, xi) y xi , . Y - , . xi , NaN.
yi = icubic(x, y, xi) xi , x .
:
10 , .
x = 0:10; y = sin(x);
xi = 0:.25:10;
yi = icubic(x, y, xi);
plot(x, y, 'o', xi, yi, g), grid.
8
8 -
2.5.2 spline
:
yi = spline(x, y, xi)
pp = spline(x, y)
v = ppval(pp, xx)
[breaks, coefs, l, k] = unmkpp(pp)
pp = mkpp(breaks, coefs)
:
yi = spline(x, y, xi) y xi , .
pp = spline(x, y) pp- , m- ppval, mkpp, unmkpp. v = ppval(pp, xx) - pp xx.
[breaks, coefs, l, k] = unmkpp(pp) pp:
breaks - ;
coefs - ;
l = length(breaks) - 1;
k = length(coefs)/l.
pp = mkpp(breaks, coefs) - pp .
:
10 , .
x = 0:10; y = sin(x);
xi = 0:.25:10;
yi = spline(x, y, xi);
plot(x, y, 'o', xi, yi, g), grid
9
9 -
2.5.3 interp1
:
yi = interp1(x, y, xi)
yi = interp1(x, y, xi, <>)
:
yi = interp1(x, y, xi) y, x; yi xi. Y - , . .
yi = interp1(x, y, xi, <>) :
linear
cubic
spline
, x ; , , x .
:
10 , .
x = 0:10; y = sin(x);
xi = 0:.25:10;
yi = interp1(x, y, xi);
plot(x, y, 'o', xi, yi, g), hold on
yi = interp1(x, y, xi, spline);
plot(x, y, 'ob', xi, yi, m), grid, hold off
10
10 -
2.5.4 interpft
:
yp = interpft(y, n)
:
yp = interpft(y, n) , , n y. length(x) = m, dx, y dy = dx * m/n, n m.
:
y = sin(x), 11 [0 10].
x = 0:10; y = sin(x);
xp = 0:0.25:10;
yp = interpft(y, 41);
xt = 0:0.01:10; yt = sin(xt);
plot(xt, yt, 'r'), hold on, plot(x, y, 'ob', xp, yp)
11
11 -
y = sin(x) 41 . , [0 1.5] .
3
3.1
Matlab , . sym syms.
syms , , :
syms x y z;
sym - , :
x = sym('x'); y = sym('y'); z = sym('z');
, y, z.
3.2 limit
limit. Matlab 1.
1
MATLAB | |
% | |
% |
: () Matlab inf. Matlab NaN.
: :
syms x
y1=sin(x)/x;
limit(y1)
ans =
1 %