数学模型与数学建模-2
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
2.1MATLAB
MATLAB Matrix Laboratory , MathWorks 20 80 , , MATLAB Simulink .MATLAB
1) , ;
2) , ;
3) , ;
4) ( ), .
2.1.1MATLAB
MATLAB , , . , MATLAB , 2.1.1 .
MATLAB “>>” , MATLAB . , Enter ,MATLAB .
·8· 2
̽ ԯ
2.1.1MATLAB
1.help
, help . polyfit .
help polyfit
POLYFIT Fit polynomial to data..P=POLYFIT(X,Y,N)finds the coeffici-ents of a polynomial P(X)of degree N that fits the data Y best in a least-squares sense.P is a row vector of length N+1containing the polynomial coefficients in descending powers,P(1)*X^N+P(2)*X^(N-1) +···+P(N)*X+P(N+1).
, MATLAB Help . Help Product Help , ( 2.1.2)
2.1.2Help
2.1MATLAB ·9·
Seach , .
2.clear
clear . “a=1”, >>a=1. 1 a. a , clear .
>>clear a???Undefined function or variable a .
3.format
MATLAB format . format short , 5 ; format rational ; format long g 15 ;
>>format short>>pi ans=3.1416;>>format rational
>>pi ans=355/113;
>>format long g>>pi ans=3.14159265358979
2.1.2MATLAB
1.
2.1.1 MATLAB .
MATLAB 1 , .MATLAB , B b .
2.1.1MATLAB
pi
i,j
inf . n/0 inf, n 0
ans , .
,MATLAB
ans
NaN , . 0/0 inf/inf
2.
MATLAB , . . MATLAB , , , .
A=[1−256−49] A=[1,−2,5,6,−4,9] 6 A.
·10· 2
3 5 C=[279−186;112382017;4−2660924];
,MATLAB , 2.1.2 .
2.1.2MATLAB
ones(i,j) i j 1
zeros(i,j) i j 0
eye(i,j) i j 1, 0
randn(i,j) i j , diag
magic(n) n , , MATLAB , . A ,A(i,j) A i j .A(:,j) A j ,A(i,:) A i .A(i,k1:k2) A i k1 k2 .A(k1:k2,j) A j k1 k2 .
>>A=magic(4)
A=[162313;511108;97612;414151];
>>A(3,2)ans=7;>>A(2,:)ans=[511108]
>>A(2,2:4)ans=[11108]
. [] . D=[A B] A B, A B ; D=[A;B] A B, A
B .
2.1.3MATLAB
MATLAB , MATLAB , 2.1.3 .
2.1.3MATLAB
’A’
+A+B
−A−B
+s+B s B
−s−B s B
*A*B
.* A.*B
.*s.*A s A
2.1MATLAB ·11·
inv inv(A)
\A\B A B inv(A)*B, AX=B /B/A A B B*inv(A), XA=B ∧A∧n A n
./ A./B A B
.\ A.\B B B
./s./B s B
.A∧n A n
>>A=magic(3);B=[1:3;4:6;7:9];>>A=[816;357;492];
>>B=[123;456;789];
>>A*B=[546984;7287102;546984];
>>A\B=[0.01670.08330.1500;0.76670.83330.9000;0.01670.0833
0.1500];
>>B/A=[-0.03330.4667-0.0333;0.16670.66670.1667;0.36670.8667
0.3667];
>>A.*B=[8218;122542;287218];
>>A.\B=[0.12502.00000.5000;1.33331.00000.8571;1.75000.8889
4.5000];
>>B./A=[0.12502.00000.5000;1.33331.00000.8571;1.75000.8889
4.5000];
,MATLAB , 2.1.4 .
2.1.4MATLAB
log(A)A
sqrt(A) A
cond(A) ( , )
det(A) A
rank(A) A
norm(A) A
eig(A) A
trace(A) A
expm(A) A
>>A=magic(5);d=det(A),t=trace(A),rk=rank(A),c=cond(A),