Matlab——矩阵运算 矩阵基本变换操作

矩阵运算

+ 加 - 减 .* 乘 ./ 左除 .\ 右除 .^ 次方 .' 转置

除了加减符号,其余的运算符必须加“.”

>> a = 1:5

a =

     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:9

b =

     1     3     5     7     9

>> a+b

ans =

     2     5     8    11    14
>> a.*b

ans =

     1     6    15    28    45
>> a.'   %转置矩阵

ans =

     1
     2
     3
     4
     5

 

 

矩阵基本变换操作

转置

>> 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.0015
    0.0176   -0.1047    0.0345
    0.0901   -0.0135   -0.0045

伪逆

>> pinv(a)

ans =

   -0.0116    0.0372   -0.0015
    0.0176   -0.1047    0.0345
    0.0901   -0.0135   -0.0045

左右反转

>> fliplr(a)

ans =

    12     2    10
     4     2    34
     6    34    98

特征值

>> [u,v]=eig(a)

u =

   -0.2960   -0.3635    0.3600
   -0.2925    0.4128   -0.7886
   -0.9093    0.8352   -0.4985


v =

   48.8395         0         0
         0  -19.8451         0
         0         0  -10.9943

上下反转

>> flipud(a)

ans =

    98    34     6
    34     2     4
    10     2    12

旋转90度

>> rot90(a)

ans =

    12     4     6
     2     2    34
    10    34    98

上三角

>> triu(a)

ans =

    10     2    12
     0     2     4
     0     0     6

下三角

>> tril(a)

ans =

    10     0     0
    34     2     0
    98    34     6
>> [l,u] = lu(a)

l =

    0.1020    0.1500    1.0000
    0.3469    1.0000         0
    1.0000         0         0


u =

   98.0000   34.0000    6.0000
         0   -9.7959    1.9184
         0         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.0494


r =

 -104.2113  -32.8179   -8.0989
         0    9.3265   -3.1941
         0         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.2277


s =

  109.5895         0         0
         0   12.0373         0
         0         0    8.0778


v =

   -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

 

猜你喜欢

转载自www.cnblogs.com/expedition/p/10884677.html
0条评论
添加一条新回复