Matlab 2
Matlab 2
MATLAB
1970 .
.
Rubbish out .
Rubbish in
: MATLAB "lab
) "Matrix (
R
" "c
MATLAB ...
: .
.
" "MATLAB
. -
.
.
) (
. - ) ( .
.
:
(1 (IDE) Integrated Development Environment :
. :
... .
DOS .
.
.
Default :
Command, Command History, Workspace, Current Directory
.
(2 .
(3 .
(4 .
(5 ) Application Program Interface (API
Fortran C ) -( c .
R
PDF "
(6
) "Mathworks ( .
R
: matlab
: help
.
>>help help
>>doc help
:HELP
>>doc sin
>>help sin
:
* .
308
* 10 10
P
308
P
* .
* C java basic .
* >>
* :COMMAND WINDOW
* : CURRENT DIRECTORY )(
* : COMMAND HISTORY
* :WORKSPACE WINDO
:Editor (M-file) . .
File/new/M-file/Editor unit
:demo
) (on-line
.
>>demo
: COMMAND WINDOW
(1 >> ENTER .
(2 )
( .
(3 ""...
eye :
(4 ";"
(5 " " %
(6 :
(7 : clc
(8 : clear all work space
(9 : who
(10 : whos
:
:
):(infinity
i ) j (:
: (pi)
: (Not-a-number) Nan
:
(1
: .
(2
: " ;"
(3
A : B s
(4
n a ) : b n 100
) (
R
]X1=[A : s : B
(
)X= linspace(a , b , n
:
;]A = [ 2 7 9 ; 9 -3 .2
;]B= [8 17 100
]C=[A ; B
]2 4 3 0 1
; Linspace(10,60,6) ; 67
K :
)A(K
:A
)A(:
M N :
)A(M:N
K P :
)B(K,P
N :
)B(: , N
N M :
N M :
M N P : Q
2 :4
)B(: , N:M
)B(N:M , :
)B(N:M , P :Q
)B([2 4] , :
] [ :
: TRANSPOSE
'A
det(a) :
inv(a) :
) :( ) (
2 :
A .*B
2 :
A ./ B
A .^X
:
:
A*B
A/B
A^X
): Isequal (a , b
:
)' : disp ('message .
. m-file .
: a b n a b n
10
(1 :
)w=rot90(a
)w=rot(a,2
2 90 :
(2 : .
)flipud(a
(3 :
)fliplr(a
(4 .
)sort(a
sort (5 : .
))flipud(sort(a
.1 .
)min(a
.2 :
min .3 .
))min(min(a
:s
: t
)[s,t]=min(a
: min .
: max min max
.4 :
)prod(a
.5 :
)'prod(a
.6 :
)sum(a
.7 :
.8 :
)mean(a
))mean(mean(a
11
.9 a a
U
.10
)Diag(a
))diag(fliplr(a
12
: trace() .11
.12 a wp r = .
) r = reshape(, ,
.13
)triu(a
.14
)tril(a
.15
: k
)rand(k
13
.16 10
rand(a,b) *10
.17 ) fix(x x .
.18 )(
)fix(x
)pascal(k
.19 ) (
)magic(k
Log 10 x
P
)Log10(x
)Sin(x
14
ex
)Exp(x
)Cos(x
ex x
)Expm(x
)Tan(x
)[v,d]=eig(x
)Cot(x
)Abs(x
)Asin(x
)Sign(x
)Acos(x
Sin x/x
)Sinc(x
)Atan(x
)Rem(x,y
)Sinh(x
)Mod(x,y
)Cosh(x
)Floor(x
)Sqrt(x
)Ceil(x
)Round(x
Ln x
)Log(x
Log 2 x
)Log2(x
15
m-file
MATLAB .
MATLAB " " ".m .
(MATLAB Editor) MATLAB " ".m
. MATLAB Notepad
" ascii " ".m .
m-file .
MATLAB . MATLAB
.
MATLAB pvt.m :
% A sample scritp file: pvt.m
)'disp(' Calculating the volume of an ideal gas.
)R = 8314; % Gas constant (J/kmol.K
;)' = )t =input(' Vector of temperature (K
;p = input(' Pressure (bar) = ')*1e5
v = R*t/p; % Ideal gas law
% Plotting the results
)plot(t,v
)')xlabel('T (K
)')ylabel('V (m^3/kmol
)'title('Ideal gas volume vs temperature
% .
MATLAB
. .
16
:
.
"" .
if . C
if .
17
] [code .
. 2
Code else .
elseif . if end
.
) .
-1 . if .
. "" "" .
== .
.
if
. . if
.
. 100
. .
18
.
.
.
.
.
. .
.
.
.
.
: switch . . . case . . . (otherwise . . .) end
" switch-case if
.
:
. .
. For .
.
For . n
a b c for end .
19
.
For .
. while
20
y k .
for k 5 .
break for .
21
m-file
a : 0 1 A 1 10 :
A a for A
a 15
a yes no
) : 2 (
22
:
a(i , j ) 10
a(i , j ) -10
2 a(i, j ) 5
- 4 < a(i , j ) < -1
:
7
-7
6
-5
0
23
24
A 1
. - :
- :
25
26
27
28
29
30
31
32
33
34
35
36
37
. :
38
39
40
41
42
43
44
45
46
47
p2 :
48
49
50