1.1 矩阵的表示
1.2 矩阵运算
1.2.14 特殊运算
1.矩阵对角线元素的抽取
函数 diag
格式 X = diag(v,k) %以向量v的元素作为矩阵X的第k条对角线元素,当k=0时,v为X的主对角线;当k>0时,v为上方第k条对角线;当k<0时,v为下方第k条对角线。
X = diag(v) %以v为主对角线元素,其余元素为0构成X。
v = diag(X,k) %抽取X的第k条对角线元素构成向量v。k=0:抽取主对角线元素;k>0:抽取上方第k条对角线元素;k<0抽取下方第k条对角线元素。
v = diag(X) %抽取主对角线元素构成向量v。
2.上三角阵和下三角阵的抽取
函数 tril %取下三角部分
格式 L = tril(X) %抽取X的主对角线的下三角部分构成矩阵L
L = tril(X,k) %抽取X的第k条对角线的下三角部分;k=0为主对角线;k>0为主对角线以上;k<0为主对角线以下。
函数 triu %取上三角部分
格式 U = triu(X) %抽取X的主对角线的上三角部分构成矩阵U
U = triu(X,k) %抽取X的第k条对角线的上三角部分;k=0为主对角线;k>0为主对角线以上;k<0为主对角线以下。
3.矩阵的变维
矩阵的变维有两种方法,即用“:”和函数“reshape”,前者主要针对2个已知维数矩阵之间的变维操作;而后者是对于一个矩阵的操作。
(1)“:”变维
(2)Reshape函数变维
格式 B = reshape(A,m,n) %返回以矩阵A的元素构成的m×n矩阵B
B = reshape(A,m,n,p,…) %将矩阵A变维为m×n×p×…
B = reshape(A,[m n p…]) %同上
B = reshape(A,siz) %由siz决定变维的大小,元素个数与A中元素个数
相同。
(5)复制和平铺矩阵
函数 repmat
格式 B = repmat(A,m,n) %将矩阵A复制m×n块,即B由m×n块A平铺而成。
B = repmat(A,[m n]) %与上面一致
B = repmat(A,[m n p…]) %B由m×n×p×…个A块平铺而成
repmat(A,m,n) %当A是一个数a时,该命令产生一个全由a组成的m×n矩阵。
1.3 矩阵分解
1.3.1 Cholesky分解
函数 chol
格式 R = chol(X) %如果X为n阶对称正定矩阵,则存在一个实的非奇异上三角阵R,满足R'*R = X;若X非正定,则产生错误信息。
[R,p] = chol(X) %不产生任何错误信息,若X为正定阵,则p=0,R与上相同;若X非正定,则p为正整数,R是有序的上三角阵。
1.3.2 LU分解
矩阵的三角分解又称LU分解,它的目的是将一个矩阵分解成一个下三角矩阵L和一个上三角矩阵U的乘积,即A=LU。
函数 lu
格式 [L,U] = lu(X) %U为上三角阵,L为下三角阵或其变换形式,满足LU=X。
[L,U,P] = lu(X) %U为上三角阵,L为下三角阵,P为单位矩阵的行变换矩阵,满足LU=PX。
1.3.3 QR分解
将矩阵A分解成一个正交矩阵与一个上三角矩阵的乘积。
函数 qr
格式 [Q,R] = qr(A) %求得正交矩阵Q和上三角阵R,Q和R满足A=QR。
[Q,R,E] = qr(A) %求得正交矩阵Q和上三角阵R,E为单位矩阵的变换形式,R的对角线元素按大小降序排列,满足AE=QR。
[Q,R] = qr(A,0) %产生矩阵A的“经济大小”分解
[Q,R,E] = qr(A,0) %E的作用是使得R的对角线元素降序,且Q*R=A(:, E)。
R = qr(A) %稀疏矩阵A的分解,只产生一个上三角阵R,满足R'*R = A'*A,这种方法计算A'*A时减少了内在数字信息的损耗。
[C,R] = qr(A,b) %用于稀疏最小二乘问题:minimize||Ax-b||的两步解:[C,R] = qr(A,b),x = R\c。
R = qr(A,0) %针对稀疏矩阵A的经济型分解
[C,R] = qr(A,b,0) %针对稀疏最小二乘问题的经济型分解
函数 qrdelete
格式 [Q,R] = qrdelete(Q,R,j) %返回将矩阵A的第j列移去后的新矩阵的qr分解
函数 qrinsert
格式 [Q,R] = qrinsert(Q,R,j,x) %在矩阵A中第j列插入向量x后的新矩阵进行qr分解。若j大于A的列数,表示在A的最后插入列x。
1.3.6 特征值分解