matlab、octave对矩阵的操作
1.创建全0矩阵
octave:1> A = zeros(5,6)
A =
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
2.创建全1矩阵
octave:2> A = ones(5,6)
A =
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
3.创建单位矩阵
octave:3> A = eye(5,6)
A =
Diagonal Matrix
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
octave:4> A = eye(6)
A =
Diagonal Matrix
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
4.创建对角线为某数的矩阵
octave:6> v = [3,5,7,2,4]
v =
3 5 7 2 4
octave:7> A = diag(v)
A =
Diagonal Matrix
3 0 0 0 0
0 5 0 0 0
0 0 7 0 0
0 0 0 2 0
0 0 0 0 4
5.生成随机矩阵
octave:14> A = randi(4,4)
A =
2 1 1 1
2 2 2 3
4 2 4 4
3 3 4 1
A = randn(4,5)
A =
0.054718 -0.144613 0.831624 0.848256 0.485120
-0.731943 0.855049 0.400058 0.024901 0.526598
1.020019 -0.999717 -0.397538 0.106885 -0.512197
-0.986166 0.677387 -0.057066 0.847221 -0.476596
横向合并矩阵
M = [A eye(4)]
或者
M = horzcat(M,eye(4))
纵向合并矩阵
M = vertcat(M,eye(4))
得到矩阵的4-8列
N = M(:,[4,5,6,7,8])
或者
N =M(:,[4:8])
得到某个矩阵的条件数
cond(A)
单位矩阵条件数为1,条件数越大,矩阵越接近为奇异矩阵(就是不可逆矩阵)
获取矩阵的逆
inv(A)
获取一个n乘n的希尔伯特矩阵
hilb(n)