矩阵运算
+ 加 - 减 .* 乘 ./ 左除 .\ 右除 .^ 次方 .' 转置
除了加减符号,其余的运算符必须加“.”
>> a = 1:5a =1 2 3 4 5>> a-2 %减法ans =-1 0 1 2 3
>> 2.*a-1 %乘法 减法ans =1 3 5 7 9
>> b = 1:2:9b =1 3 5 7 9>> a+bans =2 5 8 11 14
>> a.*bans =1 6 15 28 45
>> a.' %转置矩阵 ans =12345
矩阵基本变换操作
转置
>> a = [10,2,12;34,2,4;98,34,6]
a =
10 2 12
34 2 4
98 34 6
>> a.'
ans =
10 34 98
2 2 34
12 4 6
求逆
>> inv(a)ans =-0.0116 0.0372 -0.00150.0176 -0.1047 0.03450.0901 -0.0135 -0.0045
伪逆
>> pinv(a)ans =-0.0116 0.0372 -0.00150.0176 -0.1047 0.03450.0901 -0.0135 -0.0045
左右反转
>> fliplr(a)ans =12 2 104 2 346 34 98
特征值
>> [u,v]=eig(a)u =-0.2960 -0.3635 0.3600-0.2925 0.4128 -0.7886-0.9093 0.8352 -0.4985v =48.8395 0 00 -19.8451 00 0 -10.9943
上下反转
>> flipud(a)ans =98 34 634 2 410 2 12
旋转90度
>> rot90(a)ans =12 4 62 2 3410 34 98
上三角
>> triu(a)ans =10 2 120 2 40 0 6
下三角
>> tril(a)ans =10 0 034 2 098 34 6
>> [l,u] = lu(a)l =0.1020 0.1500 1.00000.3469 1.0000 01.0000 0 0u =98.0000 34.0000 6.00000 -9.7959 1.91840 0 11.1000
正交分解
>> [q,r] = qr(a)q =-0.0960 -0.1232 -0.9877-0.3263 -0.9336 0.1482-0.9404 0.3365 0.0494r =-104.2113 -32.8179 -8.09890 9.3265 -3.19410 0 -10.9638
奇异值分解
>> [u,s,v] = svd(a)u =-0.1003 0.8857 0.4532-0.3031 0.4066 -0.8618-0.9477 -0.2239 0.2277s =109.5895 0 00 12.0373 00 0 8.0778v =-0.9506 0.0619 -0.3041-0.3014 -0.4176 0.8572-0.0739 0.9065 0.4156
矩阵范数
>> norm(a)ans =109.5895>> norm(a,1)ans =142>> norm(a,inf)ans =138