MATLAB考试复习题及例题

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

1 1 1 1 2 3 1 3 6

>> A\\B ans =

0.0667 0.0500 0.0972 0.0667 0.3000 0.6389 0.0667 0.0500 -0.0694 >> C=inv(A) C =

0.1472 -0.1444 0.0639 -0.0611 0.0222 0.1056 -0.0194 0.1889 -0.1028 >> C*B ans =

0.0667 0.0500 0.0972 0.0667 0.3000 0.6389 0.0667 0.0500 -0.0694

右除 A/B =A*inv(B)

>> A/B ans =

27 -31 12 1 2 0 -13 29 -12 >> D=inv(B) D =

3 -3 1 -3 5 -2 1 -2 1 >> A*D ans =

27 -31 12 1 2 0 -13 29 -12 4、矩阵的函数

a.矩阵的基本变换函数

>> A=[3,3,5;2,4,6;7,8,9] %创建方阵 A A =

3 3 5 2 4 6 7 8 9

>> inv(A) %矩阵的逆(A必须为非奇异方阵) ans =

0.5000 -0.5417 0.0833 -1.0000 0.3333 0.3333 0.5000 0.1250 -0.2500 >> A‘ %矩阵的转置 ans =

3 2 7 3 4 8 5 6 9

>> det(A) %求方阵 A 的行列式值 ans = -24

>> eig(A) %求特征值 ans =

16.7503 0.8793 -1.6295

>> logm(A) %求矩阵 A 的对数 ans =

0.5432 + 0.8066i 0.7475 + 0.5526i 0.6902 - 0.6914i 0.8584 + 1.4131i 0.7845 + 0.9681i 0.6967 - 1.2112i 0.7502 - 1.5947i 1.1089 - 1.0926i 1.8504 + 1.3668i >> sqrtm(A) %求矩阵 A 的平方根 ans =

1.2466 + 0.3278i 0.5192 + 0.2246i 1.0906 - 0.2809i 0.2001 + 0.5742i 1.4228 + 0.3934i 1.3620 - 0.4921i 1.6144 - 0.6480i 1.7430 - 0.4439i 2.3610 + 0.5554i 2.3 矩阵、数组和符号运算

>> X=[3,-1,2;1,2,-1;-2,1,4] %输入矩阵 X X =

3 -1 2 1 2 -1 -2 1 4

>> [L,U]=lu(X) %对矩阵 X 进行 LU 分解 L =

1.0000 0 0 0.3333 1.0000 0 -0.6667 0.1429 1.0000

U =

3.0000 -1.0000 2.0000 0 2.3333 -1.6667 0 0 5.5714

>> [Q,R]=qr(X) %对矩阵 X 进行 QR 分解 Q =

-0.8018 0.1543 0.5774 -0.2673 -0.9567 -0.1155 0.5345 -0.2469 0.8083 R =

-3.7417 0.8018 0.8018 0 -2.3146 0.2777 0 0 4.5033 2.3 矩阵、数组和符号运算 > > E=[1,2,3;4,5,6;7,8,9] E =

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

1 4 7 2 5 8 3 6 9 >> E.\\F ans =

1.0000 2.0000 2.3333 0.5000 1.0000 1.3333 0.4286 0.7500 1.0000 >> 4.\\F ans =

0.2500 1.0000 1.7500 0.5000 1.2500 2.0000 0.7500 1.5000 2.2500 >> F./E ans =

1.0000 2.0000 2.3333 0.5000 1.0000 1.3333 0.4286 0.7500 1.0000

>> E*F ans =

14 32 50

32 77 122 50 122 194 >> E.*F ans =

1 8 21 8 25 48 21 48 81 b.向量的数组运算: 加/减法: >> x=[1,2,3] >> y=[4,5,6] >> c=x-y >> a=1+x 乘/除法: >> b=2*x >> b=2.*x >> z3=x.\\9 >> z4=x./9 >> z=x.*y >> z1=x./y >> z2=x.\\y 乘方: >> z7=2.^x >> z5=x.^3 >> z6=x.^y

点积、叉积: >> c1=dot(a,b) >> c1= sum(a.*b) >> c2=cross(a,b)

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

3 3 5 2 4 6 7 8 9 >> log(A) ans =

1.0986 1.0986 0.6931 1.3863 1.9459 2.0794 >> sqrt(A) ans =

1.7321 1.7321 1.4142 2.0000 1.6094 1.7918 2.1972 2.2361 2.4495

联系客服:779662525#qq.com(#替换为@)