## 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```

```>> 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```

0条评论